diff --git a/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php b/Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php index 56fe06a2..07343e57 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 = $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..2c0e2e07 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 = $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..23cba5d1 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 = $factory->createForNewestSupportedVersion(); } else { $parser = new Parser($lexer); } diff --git a/Translation/Extractor/File/AuthenticationMessagesExtractor.php b/Translation/Extractor/File/AuthenticationMessagesExtractor.php index 4621fd03..11ce7c48 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 = $node->name->name; } return; diff --git a/Translation/Extractor/File/FormExtractor.php b/Translation/Extractor/File/FormExtractor.php index 93bb2fed..7e553abb 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' === $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\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..c62278ef 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 = $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] = $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 = $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..0581da6b 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 = $node->name->name; } return; diff --git a/Translation/Extractor/FileExtractor.php b/Translation/Extractor/FileExtractor.php index 34c5e2a5..91ab49ed 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 = $factory->createForNewestSupportedVersion(); } else { $this->phpParser = new Parser($lexer); } diff --git a/composer.json b/composer.json index 350dafef..2e7f0de0 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": "^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",