From 61ccb0276675c16a6a774f3dc6a0d863de29824c Mon Sep 17 00:00:00 2001 From: qkdreyer Date: Mon, 8 Jan 2024 14:49:55 +0100 Subject: [PATCH] chore(deps): upgrade nikic/php-parser@^5 --- .../Extractor/File/BasePhpFileExtractorTest.php | 4 ++-- .../Extractor/File/Fixture/MyAuthException.php | 2 +- .../File/TranslationContainerExtractorTest.php | 2 +- .../Extractor/File/ValidationExtractorTest.php | 2 +- .../File/AuthenticationMessagesExtractor.php | 2 +- Translation/Extractor/File/FormExtractor.php | 13 +++++++++---- .../File/TranslationContainerExtractor.php | 6 +++--- Translation/Extractor/File/ValidationExtractor.php | 2 +- Translation/Extractor/FileExtractor.php | 2 +- composer.json | 2 +- 10 files changed, 21 insertions(+), 16 deletions(-) diff --git a/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php b/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php index 56fe06a2..7792a460 100644 --- a/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php +++ b/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php @@ -38,7 +38,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null) { $fileRealPath = __DIR__ . '/Fixture/' . $file; if (! is_file($fileRealPath)) { - throw new RuntimeException(sprintf('The file "%s" does not exist.', $fileRealPath)); + throw new \RuntimeException(sprintf('The file "%s" does not exist.', $fileRealPath)); } if ($extractor === null) { @@ -48,7 +48,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null) $lexer = new Lexer(); if (class_exists(ParserFactory::class)) { $factory = new ParserFactory(); - $parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer); + $parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion(); } else { $parser = new Parser($lexer); } diff --git a/Tests/Translation/Extractor/File/Fixture/MyAuthException.php b/Tests/Translation/Extractor/File/Fixture/MyAuthException.php index 5caaff3c..273d45b4 100644 --- a/Tests/Translation/Extractor/File/Fixture/MyAuthException.php +++ b/Tests/Translation/Extractor/File/Fixture/MyAuthException.php @@ -26,7 +26,7 @@ class MyAuthException extends AuthenticationException { private $foo; - public function getMessageKey() + public function getMessageKey(): string { if (! empty($this->foo)) { /** @Desc("%foo% is invalid.") */ diff --git a/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php b/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php index b2dbc221..7d65e560 100644 --- a/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php +++ b/Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php @@ -62,7 +62,7 @@ private function extract($file, ?TranslationContainerExtractor $extractor = null $lexer = new Lexer(); if (class_exists(ParserFactory::class)) { $factory = new ParserFactory(); - $parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer); + $parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion(); } else { $parser = new Parser($lexer); } diff --git a/Tests/Translation/Extractor/File/ValidationExtractorTest.php b/Tests/Translation/Extractor/File/ValidationExtractorTest.php index 18136c3f..234788c7 100644 --- a/Tests/Translation/Extractor/File/ValidationExtractorTest.php +++ b/Tests/Translation/Extractor/File/ValidationExtractorTest.php @@ -62,7 +62,7 @@ private function extract($file, ?ValidationExtractor $extractor = null) $lexer = new Lexer(); if (class_exists(ParserFactory::class)) { $factory = new ParserFactory(); - $parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer); + $parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion(); } else { $parser = new Parser($lexer); } diff --git a/Translation/Extractor/File/AuthenticationMessagesExtractor.php b/Translation/Extractor/File/AuthenticationMessagesExtractor.php index 4621fd03..1eaff0e5 100644 --- a/Translation/Extractor/File/AuthenticationMessagesExtractor.php +++ b/Translation/Extractor/File/AuthenticationMessagesExtractor.php @@ -116,7 +116,7 @@ public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Namespace_) { if (isset($node->name)) { - $this->namespace = implode('\\', $node->name->parts); + $this->namespace = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name; } return; diff --git a/Translation/Extractor/File/FormExtractor.php b/Translation/Extractor/File/FormExtractor.php index 93bb2fed..b88ac436 100644 --- a/Translation/Extractor/File/FormExtractor.php +++ b/Translation/Extractor/File/FormExtractor.php @@ -28,6 +28,7 @@ use JMS\TranslationBundle\Logger\LoggerAwareInterface; use JMS\TranslationBundle\Model\Message; use JMS\TranslationBundle\Model\MessageCatalogue; +use JMS\TranslationBundle\Model\SourceInterface; use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface; use JMS\TranslationBundle\Translation\FileSourceFactory; use PhpParser\Comment\Doc; @@ -76,7 +77,7 @@ class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeV private $defaultDomain; /** - * @var string + * @var array */ private $defaultDomainMessages; @@ -203,7 +204,7 @@ public function getDomain(Node $node) protected function parseEmptyValueNode(Node $item, $domain) { // Skip empty_value when false - if ($item->value instanceof Node\Expr\ConstFetch && $item->value->name instanceof Node\Name && 'false' === $item->value->name->parts[0]) { + if ($item->value instanceof Node\Expr\ConstFetch && $item->value->name instanceof Node\Name && 'false' === (property_exists($item->value->name, 'parts') ? $item->value->name->parts[0] : $item->value->name->getFirst())) { return true; } @@ -407,6 +408,10 @@ private function parseItem($item, $domain = null) $docComment = $item->value->getDocComment(); } + if (!$docComment) { + $docComment = $item->getDocComment(); + } + $docComment = is_object($docComment) ? $docComment->getText() : null; if ($docComment) { @@ -427,7 +432,7 @@ private function parseItem($item, $domain = null) // check if the value is explicitly set to false => e.g. for FormField that should be rendered without label $ignore = $ignore || !$item->value instanceof Node\Scalar\String_ || $item->value->value === false; - if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber) { + if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber && !$item->value instanceof Node\Scalar\Int_) { if ($ignore) { return; } @@ -459,7 +464,7 @@ private function parseItem($item, $domain = null) /** * @param string $id - * @param string $source + * @param SourceInterface $source * @param string|null $domain * @param string|null $desc * @param string|null $meaning diff --git a/Translation/Extractor/File/TranslationContainerExtractor.php b/Translation/Extractor/File/TranslationContainerExtractor.php index b2044883..5e565656 100644 --- a/Translation/Extractor/File/TranslationContainerExtractor.php +++ b/Translation/Extractor/File/TranslationContainerExtractor.php @@ -74,7 +74,7 @@ public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Namespace_) { if (isset($node->name)) { - $this->namespace = implode('\\', $node->name->parts); + $this->namespace = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name; } $this->useStatements = []; @@ -83,7 +83,7 @@ public function enterNode(Node $node) if ($node instanceof Node\Stmt\UseUse) { $nodeAliasName = is_string($node->alias) ? $node->alias : $node->getAlias()->name; - $this->useStatements[$nodeAliasName] = implode('\\', $node->name->parts); + $this->useStatements[$nodeAliasName] = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name; return; } @@ -94,7 +94,7 @@ public function enterNode(Node $node) $isContainer = false; foreach ($node->implements as $interface) { - $name = implode('\\', $interface->parts); + $name = property_exists($interface, 'parts') ? implode('\\', $interface->parts) : $interface->name; if (isset($this->useStatements[$name])) { $name = $this->useStatements[$name]; } diff --git a/Translation/Extractor/File/ValidationExtractor.php b/Translation/Extractor/File/ValidationExtractor.php index 9b1a1530..4fc01f99 100644 --- a/Translation/Extractor/File/ValidationExtractor.php +++ b/Translation/Extractor/File/ValidationExtractor.php @@ -84,7 +84,7 @@ public function enterNode(Node $node) { if ($node instanceof Node\Stmt\Namespace_) { if (isset($node->name)) { - $this->namespace = implode('\\', $node->name->parts); + $this->namespace = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name; } return; diff --git a/Translation/Extractor/FileExtractor.php b/Translation/Extractor/FileExtractor.php index 34c5e2a5..b7a6c576 100644 --- a/Translation/Extractor/FileExtractor.php +++ b/Translation/Extractor/FileExtractor.php @@ -107,7 +107,7 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v $lexer = new Lexer(); if (class_exists(ParserFactory::class)) { $factory = new ParserFactory(); - $this->phpParser = $factory->create(ParserFactory::PREFER_PHP7, $lexer); + $this->phpParser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion(); } else { $this->phpParser = new Parser($lexer); } diff --git a/composer.json b/composer.json index 350dafef..f65d4aee 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ ], "require": { "php": "^7.4 || ^8.0", - "nikic/php-parser": "^4.9", + "nikic/php-parser": "^4.9 || ^5", "symfony/console": "^4.3 || ^5.4 || ^6.0", "symfony/expression-language": "^4.3 || ^5.4 || ^6.0", "symfony/framework-bundle": "^4.3 || ^5.4 || ^6.0",