Skip to content

Commit ad89a56

Browse files
authored
Merge pull request #584 from qkdreyer/nikic-php-parser-5
chore(deps): upgrade nikic/php-parser@^5
2 parents da38bd0 + 61ccb02 commit ad89a56

10 files changed

+21
-16
lines changed

Tests/Translation/Extractor/File/BasePhpFileExtractorTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
3838
{
3939
$fileRealPath = __DIR__ . '/Fixture/' . $file;
4040
if (! is_file($fileRealPath)) {
41-
throw new RuntimeException(sprintf('The file "%s" does not exist.', $fileRealPath));
41+
throw new \RuntimeException(sprintf('The file "%s" does not exist.', $fileRealPath));
4242
}
4343

4444
if ($extractor === null) {
@@ -48,7 +48,7 @@ final protected function extract($file, ?FileVisitorInterface $extractor = null)
4848
$lexer = new Lexer();
4949
if (class_exists(ParserFactory::class)) {
5050
$factory = new ParserFactory();
51-
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
51+
$parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
5252
} else {
5353
$parser = new Parser($lexer);
5454
}

Tests/Translation/Extractor/File/Fixture/MyAuthException.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class MyAuthException extends AuthenticationException
2626
{
2727
private $foo;
2828

29-
public function getMessageKey()
29+
public function getMessageKey(): string
3030
{
3131
if (! empty($this->foo)) {
3232
/** @Desc("%foo% is invalid.") */

Tests/Translation/Extractor/File/TranslationContainerExtractorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function extract($file, ?TranslationContainerExtractor $extractor = null
6262
$lexer = new Lexer();
6363
if (class_exists(ParserFactory::class)) {
6464
$factory = new ParserFactory();
65-
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
65+
$parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
6666
} else {
6767
$parser = new Parser($lexer);
6868
}

Tests/Translation/Extractor/File/ValidationExtractorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ private function extract($file, ?ValidationExtractor $extractor = null)
6262
$lexer = new Lexer();
6363
if (class_exists(ParserFactory::class)) {
6464
$factory = new ParserFactory();
65-
$parser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
65+
$parser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
6666
} else {
6767
$parser = new Parser($lexer);
6868
}

Translation/Extractor/File/AuthenticationMessagesExtractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ public function enterNode(Node $node)
116116
{
117117
if ($node instanceof Node\Stmt\Namespace_) {
118118
if (isset($node->name)) {
119-
$this->namespace = implode('\\', $node->name->parts);
119+
$this->namespace = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name;
120120
}
121121

122122
return;

Translation/Extractor/File/FormExtractor.php

+9-4
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
use JMS\TranslationBundle\Logger\LoggerAwareInterface;
2929
use JMS\TranslationBundle\Model\Message;
3030
use JMS\TranslationBundle\Model\MessageCatalogue;
31+
use JMS\TranslationBundle\Model\SourceInterface;
3132
use JMS\TranslationBundle\Translation\Extractor\FileVisitorInterface;
3233
use JMS\TranslationBundle\Translation\FileSourceFactory;
3334
use PhpParser\Comment\Doc;
@@ -76,7 +77,7 @@ class FormExtractor implements FileVisitorInterface, LoggerAwareInterface, NodeV
7677
private $defaultDomain;
7778

7879
/**
79-
* @var string
80+
* @var array
8081
*/
8182
private $defaultDomainMessages;
8283

@@ -203,7 +204,7 @@ public function getDomain(Node $node)
203204
protected function parseEmptyValueNode(Node $item, $domain)
204205
{
205206
// Skip empty_value when false
206-
if ($item->value instanceof Node\Expr\ConstFetch && $item->value->name instanceof Node\Name && 'false' === $item->value->name->parts[0]) {
207+
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())) {
207208
return true;
208209
}
209210

@@ -407,6 +408,10 @@ private function parseItem($item, $domain = null)
407408
$docComment = $item->value->getDocComment();
408409
}
409410

411+
if (!$docComment) {
412+
$docComment = $item->getDocComment();
413+
}
414+
410415
$docComment = is_object($docComment) ? $docComment->getText() : null;
411416

412417
if ($docComment) {
@@ -427,7 +432,7 @@ private function parseItem($item, $domain = null)
427432
// check if the value is explicitly set to false => e.g. for FormField that should be rendered without label
428433
$ignore = $ignore || !$item->value instanceof Node\Scalar\String_ || $item->value->value === false;
429434

430-
if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber) {
435+
if (!$item->value instanceof Node\Scalar\String_ && !$item->value instanceof Node\Scalar\LNumber && !$item->value instanceof Node\Scalar\Int_) {
431436
if ($ignore) {
432437
return;
433438
}
@@ -459,7 +464,7 @@ private function parseItem($item, $domain = null)
459464

460465
/**
461466
* @param string $id
462-
* @param string $source
467+
* @param SourceInterface $source
463468
* @param string|null $domain
464469
* @param string|null $desc
465470
* @param string|null $meaning

Translation/Extractor/File/TranslationContainerExtractor.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ public function enterNode(Node $node)
7474
{
7575
if ($node instanceof Node\Stmt\Namespace_) {
7676
if (isset($node->name)) {
77-
$this->namespace = implode('\\', $node->name->parts);
77+
$this->namespace = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name;
7878
}
7979
$this->useStatements = [];
8080

@@ -83,7 +83,7 @@ public function enterNode(Node $node)
8383

8484
if ($node instanceof Node\Stmt\UseUse) {
8585
$nodeAliasName = is_string($node->alias) ? $node->alias : $node->getAlias()->name;
86-
$this->useStatements[$nodeAliasName] = implode('\\', $node->name->parts);
86+
$this->useStatements[$nodeAliasName] = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name;
8787

8888
return;
8989
}
@@ -94,7 +94,7 @@ public function enterNode(Node $node)
9494

9595
$isContainer = false;
9696
foreach ($node->implements as $interface) {
97-
$name = implode('\\', $interface->parts);
97+
$name = property_exists($interface, 'parts') ? implode('\\', $interface->parts) : $interface->name;
9898
if (isset($this->useStatements[$name])) {
9999
$name = $this->useStatements[$name];
100100
}

Translation/Extractor/File/ValidationExtractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public function enterNode(Node $node)
8484
{
8585
if ($node instanceof Node\Stmt\Namespace_) {
8686
if (isset($node->name)) {
87-
$this->namespace = implode('\\', $node->name->parts);
87+
$this->namespace = property_exists($node->name, 'parts') ? implode('\\', $node->name->parts) : $node->name->name;
8888
}
8989

9090
return;

Translation/Extractor/FileExtractor.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,7 @@ public function __construct(Environment $twig, LoggerInterface $logger, array $v
107107
$lexer = new Lexer();
108108
if (class_exists(ParserFactory::class)) {
109109
$factory = new ParserFactory();
110-
$this->phpParser = $factory->create(ParserFactory::PREFER_PHP7, $lexer);
110+
$this->phpParser = \method_exists($factory, 'create') ? $factory->create(ParserFactory::PREFER_PHP7, $lexer) : $factory->createForNewestSupportedVersion();
111111
} else {
112112
$this->phpParser = new Parser($lexer);
113113
}

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
],
2323
"require": {
2424
"php": "^7.4 || ^8.0",
25-
"nikic/php-parser": "^4.9",
25+
"nikic/php-parser": "^4.9 || ^5",
2626
"symfony/console": "^4.3 || ^5.4 || ^6.0",
2727
"symfony/expression-language": "^4.3 || ^5.4 || ^6.0",
2828
"symfony/framework-bundle": "^4.3 || ^5.4 || ^6.0",

0 commit comments

Comments
 (0)