From f211c11a9208f053dfc3655515b47050c38d57ee Mon Sep 17 00:00:00 2001 From: Jaapio Date: Tue, 7 May 2024 16:54:31 +0200 Subject: [PATCH] Bump phpparser top 4.18 min --- composer-require-checker.json | 3 ++- composer.json | 2 +- composer.lock | 22 +++++++++-------- phpstan.neon | 4 ---- psalm.xml | 1 + .../Reflection/Php/Factory/Function_.php | 6 ----- .../Reflection/Php/Factory/Property.php | 6 ++--- .../Php/Factory/PropertyIterator.php | 2 +- .../Reflection/Php/NodesFactory.php | 1 - .../Types/NamespaceNodeToContext.php | 24 ++++++++++++------- .../Reflection/Php/Factory/Class_Test.php | 1 - .../Php/Factory/PropertyIteratorTest.php | 1 - .../Reflection/Php/NodesFactoryTest.php | 1 - 13 files changed, 35 insertions(+), 39 deletions(-) diff --git a/composer-require-checker.json b/composer-require-checker.json index e2718623..a4883184 100644 --- a/composer-require-checker.json +++ b/composer-require-checker.json @@ -2,7 +2,8 @@ "symbol-whitelist" : [ "null", "true", "false", "static", "self", "parent", - "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object" + "array", "string", "int", "float", "bool", "iterable", "callable", "void", "object", + "PhpParser\\Node\\Stmt\\PropertyProperty" ], "php-core-extensions" : [ "Core", diff --git a/composer.json b/composer.json index e7cdb4d2..dec67b54 100644 --- a/composer.json +++ b/composer.json @@ -20,7 +20,7 @@ }, "require": { "php": "8.1.*|8.2.*|8.3.*", - "nikic/php-parser": "~4.14 || ^5.0", + "nikic/php-parser": "~4.18 || ^5.0", "phpdocumentor/reflection-common": "^2.1", "phpdocumentor/reflection-docblock": "^5", "phpdocumentor/type-resolver": "^1.2", diff --git a/composer.lock b/composer.lock index 8e258ff9..fb9b289f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "632acca5e52598434ef0221de06c0ed1", + "content-hash": "279b483d5011c8c542bf1fbea5df1543", "packages": [ { "name": "doctrine/deprecations", @@ -55,25 +55,27 @@ }, { "name": "nikic/php-parser", - "version": "v4.19.1", + "version": "v5.0.2", "source": { "type": "git", "url": "https://github.com/nikic/PHP-Parser.git", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b" + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/4e1b88d21c69391150ace211e9eaf05810858d0b", - "reference": "4e1b88d21c69391150ace211e9eaf05810858d0b", + "url": "https://api.github.com/repos/nikic/PHP-Parser/zipball/139676794dc1e9231bf7bcd123cfc0c99182cb13", + "reference": "139676794dc1e9231bf7bcd123cfc0c99182cb13", "shasum": "" }, "require": { + "ext-ctype": "*", + "ext-json": "*", "ext-tokenizer": "*", - "php": ">=7.1" + "php": ">=7.4" }, "require-dev": { "ircmaxell/php-yacc": "^0.0.7", - "phpunit/phpunit": "^6.5 || ^7.0 || ^8.0 || ^9.0" + "phpunit/phpunit": "^7.0 || ^8.0 || ^9.0" }, "bin": [ "bin/php-parse" @@ -81,7 +83,7 @@ "type": "library", "extra": { "branch-alias": { - "dev-master": "4.9-dev" + "dev-master": "5.0-dev" } }, "autoload": { @@ -105,9 +107,9 @@ ], "support": { "issues": "https://github.com/nikic/PHP-Parser/issues", - "source": "https://github.com/nikic/PHP-Parser/tree/v4.19.1" + "source": "https://github.com/nikic/PHP-Parser/tree/v5.0.2" }, - "time": "2024-03-17T08:10:35+00:00" + "time": "2024-03-05T20:51:40+00:00" }, { "name": "phpdocumentor/reflection-common", diff --git a/phpstan.neon b/phpstan.neon index 3f6932cd..687d5bd5 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -16,10 +16,6 @@ parameters: - '#Parameter \#1 \$fqsen of class phpDocumentor\\Reflection\\Php\\(.*) constructor expects phpDocumentor\\Reflection\\Fqsen, mixed given\.#' - '#Parameter \#1 \$fqsen of method phpDocumentor\\Reflection\\Php\\File::addNamespace\(\) expects phpDocumentor\\Reflection\\Fqsen, mixed given\.#' # - # there is one test case that prevents changing PropertyIterator::getDefault() to just return Expr (this is set in PhpParser) - # src/phpDocumentor/Reflection/Php/Factory/Property.php - - '#Parameter \#1 \$node of method PhpParser\\PrettyPrinterAbstract::prettyPrintExpr\(\) expects PhpParser\\Node\\Expr, PhpParser\\Node\\Expr\|string given\.#' - # # Type hint in php-parser is incorrect. - '#Cannot cast PhpParser\\Node\\Expr\|string to string.#' diff --git a/psalm.xml b/psalm.xml index 8b73b240..bdac9dad 100644 --- a/psalm.xml +++ b/psalm.xml @@ -16,5 +16,6 @@ + diff --git a/src/phpDocumentor/Reflection/Php/Factory/Function_.php b/src/phpDocumentor/Reflection/Php/Factory/Function_.php index 191f1e05..8fc04ddf 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Function_.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Function_.php @@ -21,8 +21,6 @@ use PhpParser\Node\Stmt\Function_ as FunctionNode; use Webmozart\Assert\Assert; -use function is_array; - /** * Strategy to convert Function_ to FunctionDescriptor * @@ -61,10 +59,6 @@ protected function doCreate( $file->addFunction($function); - if (!is_array($object->stmts)) { - return $function; - } - $thisContext = $context->push($function); foreach ($object->stmts as $stmt) { $strategy = $strategies->findMatching($thisContext, $stmt); diff --git a/src/phpDocumentor/Reflection/Php/Factory/Property.php b/src/phpDocumentor/Reflection/Php/Factory/Property.php index 1682f5f9..60b1be68 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/Property.php +++ b/src/phpDocumentor/Reflection/Php/Factory/Property.php @@ -70,9 +70,9 @@ protected function doCreate( $iterator = new PropertyIterator($object); foreach ($iterator as $stmt) { - $default = null; - if ($iterator->getDefault() !== null) { - $default = $this->valueConverter->prettyPrintExpr($iterator->getDefault()); + $default = $iterator->getDefault(); + if ($default !== null) { + $default = $this->valueConverter->prettyPrintExpr($default); } $propertyContainer->addProperty( diff --git a/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php b/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php index 6d04da8b..45b86d82 100644 --- a/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php +++ b/src/phpDocumentor/Reflection/Php/Factory/PropertyIterator.php @@ -130,7 +130,7 @@ public function getName(): string /** * returns the default value of the current property. */ - public function getDefault(): null|Expr + public function getDefault(): Expr|null { return $this->property->props[$this->index]->default; } diff --git a/src/phpDocumentor/Reflection/Php/NodesFactory.php b/src/phpDocumentor/Reflection/Php/NodesFactory.php index 44a0c05b..cb877df6 100644 --- a/src/phpDocumentor/Reflection/Php/NodesFactory.php +++ b/src/phpDocumentor/Reflection/Php/NodesFactory.php @@ -14,7 +14,6 @@ namespace phpDocumentor\Reflection\Php; use phpDocumentor\Reflection\NodeVisitor\ElementNameResolver; -use PhpParser\Lexer\Emulative; use PhpParser\Node; use PhpParser\NodeTraverser; use PhpParser\NodeTraverserInterface; diff --git a/src/phpDocumentor/Reflection/Types/NamespaceNodeToContext.php b/src/phpDocumentor/Reflection/Types/NamespaceNodeToContext.php index f4c78f70..012e1fad 100644 --- a/src/phpDocumentor/Reflection/Types/NamespaceNodeToContext.php +++ b/src/phpDocumentor/Reflection/Types/NamespaceNodeToContext.php @@ -33,15 +33,21 @@ public function __invoke(Namespace_|null $namespace): Context private function aliasesToFullyQualifiedNames(Namespace_ $namespace): array { // flatten(flatten(map(stuff))) - return array_merge([], ...array_merge([], ...array_map(static fn ($use): array => array_map(static function (UseUse $useUse) use ($use): array { - if ($use instanceof GroupUse) { - return [ - (string) $useUse->getAlias() => $use->prefix->toString() . '\\' . $useUse->name->toString(), - ]; - } - - return [(string) $useUse->getAlias() => $useUse->name->toString()]; - }, $use->uses), $this->classAlikeUses($namespace)))); + return array_merge([], ...array_merge([], ...array_map( + static fn ($use): array => array_map( + static function (Node\UseItem|UseUse $useUse) use ($use): array { + if ($use instanceof GroupUse) { + return [ + (string) $useUse->getAlias() => $use->prefix->toString() . '\\' . $useUse->name->toString(), + ]; + } + + return [(string) $useUse->getAlias() => $useUse->name->toString()]; + }, + $use->uses, + ), + $this->classAlikeUses($namespace), + ))); } /** @return Use_[]|GroupUse[] */ diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/Class_Test.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/Class_Test.php index 4121844d..82da37ef 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/Class_Test.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/Class_Test.php @@ -23,7 +23,6 @@ use phpDocumentor\Reflection\Php\ProjectFactoryStrategy; use phpDocumentor\Reflection\Php\StrategyContainer; use PhpParser\Comment\Doc; -use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Stmt\Class_ as ClassNode; use PhpParser\Node\Stmt\ClassMethod; diff --git a/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyIteratorTest.php b/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyIteratorTest.php index 621450be..a97feaa8 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyIteratorTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/Factory/PropertyIteratorTest.php @@ -16,7 +16,6 @@ use Mockery as m; use Mockery\Adapter\Phpunit\MockeryTestCase; use PhpParser\Comment\Doc; -use PhpParser\Node\Identifier; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Property as PropertyNode; use PhpParser\Node\Stmt\PropertyProperty; diff --git a/tests/unit/phpDocumentor/Reflection/Php/NodesFactoryTest.php b/tests/unit/phpDocumentor/Reflection/Php/NodesFactoryTest.php index e9de5d03..1854ff0d 100644 --- a/tests/unit/phpDocumentor/Reflection/Php/NodesFactoryTest.php +++ b/tests/unit/phpDocumentor/Reflection/Php/NodesFactoryTest.php @@ -14,7 +14,6 @@ namespace phpDocumentor\Reflection\Php; use phpDocumentor\Reflection\NodeVisitor\ElementNameResolver; -use PhpParser\Lexer\Emulative; use PhpParser\NodeTraverser; use PhpParser\NodeTraverserInterface; use PhpParser\NodeVisitor\NameResolver;