diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 0bd34026..a47880bb 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: fail-fast: false matrix: php-version: [ - '8.0', + '8.1', '8.2', '8.3' ] @@ -57,14 +57,14 @@ jobs: - name: Run tests run: | - if [[ ${{ matrix.php-version }} == '8.0' ]]; then + if [[ ${{ matrix.php-version }} == '8.1' ]]; then XDEBUG_MODE=coverage vendor/bin/phpunit --coverage-clover coverage.xml else composer test fi - name: Code Coverage Report - if: success() && matrix.php-version == '8.0' + if: success() && matrix.php-version == '8.1' uses: codecov/codecov-action@v1 - name: Composer require spryker-sdk/composer-prefer-lowest package diff --git a/README.md b/README.md index 703cc350..37a35247 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Build Status](https://github.com/spryker-sdk/integrator/workflows/CI/badge.svg?branch=master)](https://github.com/spryker-sdk/integrator/actions?query=workflow%3ACI+branch%3Amaster) [![codecov](https://codecov.io/gh/spryker-sdk/integrator/branch/master/graph/badge.svg?token=l6Xj26Cqei)](https://codecov.io/gh/spryker-sdk/integrator) [![Latest Stable Version](https://poser.pugx.org/spryker-sdk/integrator/v/stable.svg)](https://packagist.org/packages/spryker-sdk/integrator) -[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.0-8892BF.svg)](https://php.net/) +[![Minimum PHP Version](https://img.shields.io/badge/php-%3E%3D%208.1-8892BF.svg)](https://php.net/) [![PHPStan](https://img.shields.io/badge/PHPStan-level%208-brightgreen.svg?style=flat)](https://phpstan.org/) Auto-migrate applications in regard to new core releases using module manifests. diff --git a/composer.json b/composer.json index 0a7d18fe..c3718c92 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "description": "Integrator module", "license": "proprietary", "require": { - "php": ">=8.0", + "php": ">=8.1", "ext-dom": "*", "ext-json": "*", "ext-simplexml": "*", @@ -13,7 +13,7 @@ "composer/composer": "^2.6.0", "czproject/git-php": "^4.1", "guzzlehttp/guzzle": "^7.4", - "nikic/php-parser": "^4.13.0", + "nikic/php-parser": "^5.1.0", "sebastian/diff": "^4.0.0", "spryker-sdk/utils": "^0.2.2", "symfony/console": "^6.0", diff --git a/src/Builder/Checker/ClassMethodChecker.php b/src/Builder/Checker/ClassMethodChecker.php index 4861bf49..48f62dff 100644 --- a/src/Builder/Checker/ClassMethodChecker.php +++ b/src/Builder/Checker/ClassMethodChecker.php @@ -52,11 +52,6 @@ class ClassMethodChecker extends AbstractMethodChecker implements ClassMethodChe */ public const METHOD_FIELD_NAME = 'name'; - /** - * @var string - */ - public const METHOD_FIELD_PARTS = 'parts'; - /** * @var array */ @@ -138,7 +133,7 @@ public function isMethodNodeSameAsValue(?ClassMethod $methodNode, $value): bool if (!$methodNode || !$methodNode->stmts) { return true; } - $parser = $this->parserFactory->create(ParserFactory::PREFER_PHP7); + $parser = $this->parserFactory->createForHostVersion(); $previousValue = $parser->parse(sprintf('name) && is_string($currentValue->name) && $previousValue->name !== $currentValue->name) { return false; } + if ( - $this->isExistsStatementField($previousValue->name, $currentValue->name, 'parts') - && $previousValue->name->parts !== $currentValue->name->parts + $this->isExistsStatementField($previousValue->name, $currentValue->name, 'name') + && $previousValue->name->name !== $currentValue->name->name ) { return false; } - if (property_exists($previousValue->name, 'parts') && !property_exists($currentValue->name, 'parts')) { + + if (property_exists($previousValue->name, 'name') && !property_exists($currentValue->name, 'name')) { return false; } - if (!property_exists($previousValue->name, 'parts') && property_exists($currentValue->name, 'parts')) { + + if (!property_exists($previousValue->name, 'name') && property_exists($currentValue->name, 'name')) { return false; } diff --git a/src/Builder/Checker/MethodStatementChecker/PartsMethodStatementChecker.php b/src/Builder/Checker/MethodStatementChecker/PartsMethodStatementChecker.php index 4dbc4a8a..4eaa81ff 100644 --- a/src/Builder/Checker/MethodStatementChecker/PartsMethodStatementChecker.php +++ b/src/Builder/Checker/MethodStatementChecker/PartsMethodStatementChecker.php @@ -22,7 +22,7 @@ class PartsMethodStatementChecker extends AbstractMethodChecker implements Metho */ public function isApplicable($previousValue, $currentValue): bool { - return $this->isExistsStatementField($previousValue, $currentValue, ClassMethodChecker::METHOD_FIELD_PARTS); + return $this->isExistsStatementField($previousValue, $currentValue, ClassMethodChecker::METHOD_FIELD_NAME); } /** @@ -33,6 +33,6 @@ public function isApplicable($previousValue, $currentValue): bool */ public function isSameStatement($previousValue, $currentValue): bool { - return $this->isSameStatementsArrayPart($currentValue->parts, $previousValue->parts); + return $this->isSameStatementsArrayPart($currentValue->name, $previousValue->name); } } diff --git a/src/Builder/ClassLoader/AbstractLoader.php b/src/Builder/ClassLoader/AbstractLoader.php index d10cb379..009b4484 100644 --- a/src/Builder/ClassLoader/AbstractLoader.php +++ b/src/Builder/ClassLoader/AbstractLoader.php @@ -9,7 +9,6 @@ namespace SprykerSdk\Integrator\Builder\ClassLoader; -use PhpParser\Lexer; use PhpParser\NodeTraverser; use PhpParser\NodeVisitor\CloningVisitor; use PhpParser\NodeVisitor\NameResolver; @@ -22,19 +21,12 @@ abstract class AbstractLoader */ protected $parser; - /** - * @var \PhpParser\Lexer - */ - protected $lexer; - /** * @param \PhpParser\Parser $parser - * @param \PhpParser\Lexer $lexer */ - public function __construct(Parser $parser, Lexer $lexer) + public function __construct(Parser $parser) { $this->parser = $parser; - $this->lexer = $lexer; } /** diff --git a/src/Builder/ClassLoader/ClassLoader.php b/src/Builder/ClassLoader/ClassLoader.php index aed4689e..97377132 100644 --- a/src/Builder/ClassLoader/ClassLoader.php +++ b/src/Builder/ClassLoader/ClassLoader.php @@ -51,7 +51,7 @@ public function loadClass(string $className): ClassInformationTransfer $classInformationTransfer->setTokenTree($syntaxTree) ->setOriginalTokenTree($originalSyntaxTree) - ->setTokens($this->lexer->getTokens()) + ->setTokens($this->parser->getTokens()) ->setFilePath(realpath($fileName)); $parentClass = $this->getParent($syntaxTree); diff --git a/src/Builder/ClassLoader/FileLoader.php b/src/Builder/ClassLoader/FileLoader.php index f4f83735..445d5c93 100644 --- a/src/Builder/ClassLoader/FileLoader.php +++ b/src/Builder/ClassLoader/FileLoader.php @@ -36,7 +36,7 @@ public function loadFile(string $path): FileInformationTransfer $fileInformationTransfer->setTokenTree($syntaxTree) ->setOriginalTokenTree($originalSyntaxTree) - ->setTokens($this->lexer->getTokens()); + ->setTokens($this->parser->getTokens()); return $fileInformationTransfer; } diff --git a/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php b/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php index 4ca6ad1a..af0d19fa 100644 --- a/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php +++ b/src/Builder/ClassModifier/ClassConstant/ClassConstantModifier.php @@ -109,7 +109,7 @@ protected function parseValue($value, bool $isLiteral) protected function parseSingleValue(string $value): Expr { /** @var array<\PhpParser\Node\Stmt\Expression> $tree */ - $tree = $this->parserFactory->create(ParserFactory::PREFER_PHP7)->parse(sprintf('parserFactory->createForHostVersion()->parse(sprintf('expressionPartialParser->parse(sprintf('$var = %s;', $value)); - /** @var \PhpParser\Node\Expr\ArrayItem|null $arrayItem */ + /** @var \PhpParser\Node\ArrayItem|null $arrayItem */ $arrayItem = (new NodeFinder())->findFirst($valueStm, function (Node $node) { return $node instanceof ArrayItem; }); diff --git a/src/Builder/Comparer/ClassConstExpressionCompareStrategy.php b/src/Builder/Comparer/ClassConstExpressionCompareStrategy.php index 2bb5c9b8..828a7ff1 100644 --- a/src/Builder/Comparer/ClassConstExpressionCompareStrategy.php +++ b/src/Builder/Comparer/ClassConstExpressionCompareStrategy.php @@ -14,7 +14,7 @@ use PhpParser\Node\Identifier; use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; -use PhpParser\Node\Stmt\UseUse; +use PhpParser\Node\UseItem; use SprykerSdk\Integrator\Builder\Finder\UseStatementsFinder\UseStatementsFinderInterface; class ClassConstExpressionCompareStrategy implements CompareStrategyInterface @@ -109,7 +109,7 @@ protected function getUseClassNames(array $classTokenTree): array $useStatements = $this->useStatementsFinder->findUseStatements($classTokenTree); foreach ($useStatements as $useStatement) { - $names[] = array_map(static fn (UseUse $use): string => $use->name->toString(), $useStatement->uses); + $names[] = array_map(static fn (UseItem $use): string => $use->name->toString(), $useStatement->uses); } return array_merge(...$names); diff --git a/src/Builder/Creator/MethodCreator.php b/src/Builder/Creator/MethodCreator.php index 464e9359..bba9bebd 100644 --- a/src/Builder/Creator/MethodCreator.php +++ b/src/Builder/Creator/MethodCreator.php @@ -10,13 +10,14 @@ namespace SprykerSdk\Integrator\Builder\Creator; use PhpParser\Comment\Doc; +use PhpParser\Modifiers; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Identifier; +use PhpParser\Node\Name; use PhpParser\Node\Name\FullyQualified; use PhpParser\Node\NullableType; use PhpParser\Node\Scalar\String_; -use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\Return_; @@ -102,7 +103,7 @@ public function createMethodBody(ClassInformationTransfer $classInformationTrans } $preparedValue = $this->createPreparedValueForParser($value); - $tree = $this->parserFactory->create(ParserFactory::PREFER_PHP7)->parse($preparedValue); + $tree = $this->parserFactory->createForHostVersion()->parse($preparedValue); if (!$tree) { throw new LiteralValueParsingException(sprintf('Value is not valid PHP code: `%s`', $value)); } @@ -148,7 +149,7 @@ public function createMethod( $parentReturnType = $parentClassMethod ? $this->getReturnType($parentClassMethod) : null; } $returnType = $parentReturnType ?: $this->methodReturnTypeCreator->createMethodReturnType($value); - $flags = $parentClassMethod ? $this->getModifierFromClassMethod($parentClassMethod) : Class_::MODIFIER_PUBLIC; + $flags = $parentClassMethod ? $this->getModifierFromClassMethod($parentClassMethod) : Modifiers::PUBLIC; $docType = $parentClassMethod && $parentClassMethod->getDocComment() ? new Doc($parentClassMethod->getDocComment()->getText()) : $this->methodDocBlockCreator->createMethodDocBlock($value); @@ -192,7 +193,7 @@ public function getReturnType(ClassMethod $classMethod) $parentReturnType = $parentReturnType->type; } if ($parentReturnType instanceof Identifier) { - $returnType = $nullable . $parentReturnType->name; + return new Identifier($nullable . $parentReturnType->name); } if ($parentReturnType instanceof FullyQualified) { return new FullyQualified($parentReturnType->toString()); @@ -208,7 +209,7 @@ public function getReturnType(ClassMethod $classMethod) */ protected function getModifierFromClassMethod(ClassMethod $classMethod): int { - return $classMethod->isProtected() ? Class_::MODIFIER_PROTECTED : Class_::MODIFIER_PUBLIC; + return $classMethod->isProtected() ? Modifiers::PROTECTED : Modifiers::PUBLIC; } /** @@ -276,7 +277,7 @@ protected function createClassConstantReturnStatement(ClassInformationTransfer $ $expressionName = $expressionStatement->name; /** @var \PhpParser\Node\Name\FullyQualified $expressionClass */ $expressionClass = $expressionStatement->class; - $expressionClass->parts = [$expressionClass->toString()]; + $expressionClass->name = (new Name([$expressionClass->toString()]))->name; $returnClassConstExpression = $this->createClassConstantExpression( $classInformationTransfer, $expressionClass->toString(), diff --git a/src/Builder/Creator/MethodStatementsCreator.php b/src/Builder/Creator/MethodStatementsCreator.php index 0c4709b2..eb7972e2 100644 --- a/src/Builder/Creator/MethodStatementsCreator.php +++ b/src/Builder/Creator/MethodStatementsCreator.php @@ -10,7 +10,8 @@ namespace SprykerSdk\Integrator\Builder\Creator; use PhpParser\BuilderFactory; -use PhpParser\Node\Expr\ArrayItem; +use PhpParser\Node\ArrayItem; +use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ConstFetch; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Identifier; @@ -122,7 +123,7 @@ protected function createNodeTreeFromArrayValue(ClassInformationTransfer $classI * @param array $keyParts * @param array $insideArrayItems * - * @return \PhpParser\Node\Expr\ArrayItem + * @return \PhpParser\Node\ArrayItem */ protected function createArrayItem( ClassInformationTransfer $classInformationTransfer, @@ -150,7 +151,9 @@ protected function createArrayItem( if ($insideArrayItems) { return new ArrayItem( - (new BuilderFactory())->val($insideArrayItems), + (new BuilderFactory())->val( + new Array_($insideArrayItems), + ), $key, ); } @@ -166,7 +169,7 @@ protected function createArrayItem( * @param array $itemParts * @param array $keyParts * - * @return \PhpParser\Node\Expr\ArrayItem + * @return \PhpParser\Node\ArrayItem */ protected function createSingleSemicolonVariableArrayItem(ClassInformationTransfer $classInformationTransfer, array $itemParts, array $keyParts): ArrayItem { diff --git a/src/Builder/Printer/ClassPrinter.php b/src/Builder/Printer/ClassPrinter.php index fb788f0d..3fccaaf9 100644 --- a/src/Builder/Printer/ClassPrinter.php +++ b/src/Builder/Printer/ClassPrinter.php @@ -34,7 +34,7 @@ protected function isMultiline(array $nodes): bool $node = current($nodes); $startPos = $node->getStartTokenPos() - 1; $endPos = $node->getEndTokenPos() + 1; - $text = $this->origTokens->getTokenCode($startPos, $endPos, 0); + $text = $this->origTokens !== null ? $this->origTokens->getTokenCode($startPos, $endPos, 0) : ''; return strpos($text, "\n") !== false; } diff --git a/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php b/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php index 9d739cc8..817c9e84 100644 --- a/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php +++ b/src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php @@ -10,9 +10,9 @@ namespace SprykerSdk\Integrator\Builder\Visitor; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\Variable; @@ -27,7 +27,7 @@ class AddArrayItemToEnvConfigVisitor extends NodeVisitorAbstract protected $target; /** - * @var \PhpParser\Node\Expr\ArrayItem + * @var \PhpParser\Node\ArrayItem */ protected $value; @@ -48,7 +48,7 @@ class AddArrayItemToEnvConfigVisitor extends NodeVisitorAbstract /** * @param string $target - * @param \PhpParser\Node\Expr\ArrayItem $value + * @param \PhpParser\Node\ArrayItem $value */ public function __construct(string $target, ArrayItem $value) { diff --git a/src/Builder/Visitor/AddClassToClassListVisitor.php b/src/Builder/Visitor/AddClassToClassListVisitor.php index a9eb0f00..e11daf9f 100644 --- a/src/Builder/Visitor/AddClassToClassListVisitor.php +++ b/src/Builder/Visitor/AddClassToClassListVisitor.php @@ -12,14 +12,14 @@ use PhpParser\BuilderFactory; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Name; use PhpParser\Node\Stmt\ClassMethod; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; use SprykerSdk\Integrator\Helper\ClassHelper; @@ -60,11 +60,6 @@ class AddClassToClassListVisitor extends NodeVisitorAbstract */ protected $after; - /** - * @var \PhpParser\Node - */ - protected $parentNode; - /** * @param string $methodName * @param string $className @@ -123,7 +118,7 @@ public function enterNode(Node $node) */ protected function isArrayMergeFuncCallNode(FuncCall $node): bool { - return $node->name instanceof Name && $node->name->parts[0] === static::ARRAY_MERGE_FUNCTION; + return $node->name instanceof Name && $node->name->name === static::ARRAY_MERGE_FUNCTION; } /** @@ -257,7 +252,7 @@ protected function addArrayElementToPosition(Node $node): array } /** - * @return \PhpParser\Node\Expr\ArrayItem + * @return \PhpParser\Node\ArrayItem */ protected function createArrayItemWithInstanceOf(): ArrayItem { @@ -273,6 +268,6 @@ protected function successfullyProcessed(): int { $this->methodFound = false; - return NodeTraverser::DONT_TRAVERSE_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CHILDREN; } } diff --git a/src/Builder/Visitor/AddMethodCallToCallListVisitor.php b/src/Builder/Visitor/AddMethodCallToCallListVisitor.php index fc4015cf..87c81dfb 100644 --- a/src/Builder/Visitor/AddMethodCallToCallListVisitor.php +++ b/src/Builder/Visitor/AddMethodCallToCallListVisitor.php @@ -11,8 +11,8 @@ use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\Variable; @@ -100,7 +100,7 @@ public function enterNode(Node $node) */ protected function isArrayMergeFuncCallNode(FuncCall $node): bool { - return $node->name instanceof Name && $node->name->parts[0] === static::ARRAY_MERGE_FUNCTION; + return $node->name instanceof Name && $node->name->name === static::ARRAY_MERGE_FUNCTION; } /** @@ -341,7 +341,7 @@ protected function addNewCallIntoArrayNodeByPosition(Array_ $node, int $position } /** - * @return \PhpParser\Node\Expr\ArrayItem + * @return \PhpParser\Node\ArrayItem */ protected function createArrayItemWithMethodCall(): ArrayItem { diff --git a/src/Builder/Visitor/AddPluginToPluginListVisitor.php b/src/Builder/Visitor/AddPluginToPluginListVisitor.php index 38bad1dd..bb6312c7 100644 --- a/src/Builder/Visitor/AddPluginToPluginListVisitor.php +++ b/src/Builder/Visitor/AddPluginToPluginListVisitor.php @@ -12,10 +12,10 @@ use PhpParser\BuilderFactory; use PhpParser\Node; use PhpParser\Node\Arg; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\ConstFetch; @@ -30,7 +30,7 @@ use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; use PhpParser\Node\Stmt\Return_; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; use PhpParser\PrettyPrinter\Standard; use SprykerSdk\Integrator\Builder\ArgumentBuilder\ArgumentBuilderInterface; @@ -40,11 +40,6 @@ class AddPluginToPluginListVisitor extends NodeVisitorAbstract { - /** - * @var string - */ - public const STMTS = 'stmts'; - /** * @var string */ @@ -252,7 +247,7 @@ protected function createNewConditionStatement(Expr $name): Stmt new Name((string)$this->classMetadataTransfer->getCondition()), ), [ - static::STMTS => [ + 'stmts' => [ $this->getAssignPlugin($name), ], ], @@ -269,7 +264,7 @@ protected function getAssignPlugin(Expr $name): Expression return new Expression( new Assign( new ArrayDimFetch($name), - $this->createArrayItemWithInstanceOf(), + $this->createArrayItemWithInstanceOf()->value, ), ); } @@ -313,7 +308,7 @@ protected function getIfClausePrettyPrint(If_ $ifCondition): string */ protected function isArrayMergeFuncCallNode(FuncCall $node): bool { - return $node->name instanceof Name && $node->name->parts[0] === static::ARRAY_MERGE_FUNCTION; + return $node->name instanceof Name && $node->name->name === static::ARRAY_MERGE_FUNCTION; } /** @@ -371,9 +366,6 @@ protected function addNewPluginInstance(If_ $statement): void { foreach ($statement->stmts as $stmt) { if ($stmt instanceof Expression && $stmt->expr instanceof Assign) { - if ($stmt->expr->expr instanceof ArrayItem && $this->isArrayItemEqual($stmt->expr->expr)) { - continue; - } if ($stmt->expr->expr instanceof New_ && $stmt->expr->expr->class->toString() === $this->classMetadataTransfer->getSource()) { continue; } @@ -525,7 +517,7 @@ protected function isPluginAdded(Array_ $node): bool } /** - * @param \PhpParser\Node\Expr\ArrayItem|null $item + * @param \PhpParser\Node\ArrayItem|null $item * * @return bool */ @@ -555,7 +547,7 @@ protected function isArrayItemEqual(?ArrayItem $item): bool } /** - * @param \PhpParser\Node\Expr\ArrayItem $item + * @param \PhpParser\Node\ArrayItem $item * * @return bool */ @@ -594,7 +586,7 @@ protected function isArgumentEqual(array $args): bool } /** - * @param \PhpParser\Node\Expr\ArrayItem $node + * @param \PhpParser\Node\ArrayItem $node * * @return bool */ @@ -606,7 +598,7 @@ protected function isKeyEqualsToCurrentOne(ArrayItem $node): bool } /** - * @param \PhpParser\Node\Expr\ArrayItem $node + * @param \PhpParser\Node\ArrayItem $node * * @return string|null */ @@ -628,7 +620,7 @@ protected function getArrayItemNodeKey(ArrayItem $node): ?string } /** - * @return \PhpParser\Node\Expr\ArrayItem + * @return \PhpParser\Node\ArrayItem */ protected function createArrayItemWithInstanceOf(): ArrayItem { @@ -647,6 +639,6 @@ protected function successfullyProcessed(): int { $this->methodFound = false; - return NodeTraverser::DONT_TRAVERSE_CHILDREN; + return NodeVisitor::DONT_TRAVERSE_CHILDREN; } } diff --git a/src/Builder/Visitor/AddStatementToStatementListStrategy/AbstractAddStatementToStatementListStrategy.php b/src/Builder/Visitor/AddStatementToStatementListStrategy/AbstractAddStatementToStatementListStrategy.php index bc7bd72f..f7264488 100644 --- a/src/Builder/Visitor/AddStatementToStatementListStrategy/AbstractAddStatementToStatementListStrategy.php +++ b/src/Builder/Visitor/AddStatementToStatementListStrategy/AbstractAddStatementToStatementListStrategy.php @@ -34,6 +34,6 @@ public function isArrayMergeNode(Node $node): bool return $node->stmts[0] instanceof Return_ && $node->stmts[0]->expr instanceof FuncCall - && $expression->name->parts[0] === static::ARRAY_MERGE_FUNCTION; + && $expression->name->name === static::ARRAY_MERGE_FUNCTION; } } diff --git a/src/Builder/Visitor/RemovePluginFromPluginListVisitor.php b/src/Builder/Visitor/RemovePluginFromPluginListVisitor.php index 1719f94c..92355808 100644 --- a/src/Builder/Visitor/RemovePluginFromPluginListVisitor.php +++ b/src/Builder/Visitor/RemovePluginFromPluginListVisitor.php @@ -11,13 +11,13 @@ use InvalidArgumentException; use PhpParser\Node; +use PhpParser\Node\ArrayItem; use PhpParser\Node\Expr\Array_; -use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\New_; use PhpParser\Node\Stmt\Expression; use PhpParser\Node\Stmt\If_; -use PhpParser\NodeTraverser; +use PhpParser\NodeVisitor; use PhpParser\NodeVisitorAbstract; use PhpParser\PrettyPrinter\Standard; use SprykerSdk\Integrator\Builder\ArgumentBuilder\ArgumentBuilderInterface; @@ -25,16 +25,6 @@ class RemovePluginFromPluginListVisitor extends NodeVisitorAbstract { - /** - * @var string - */ - protected const STATEMENT_ARRAY = 'Expr_Array'; - - /** - * @var string - */ - protected const STATEMENT_ASSIGN = 'Expr_Assign'; - /** * @var string */ @@ -112,7 +102,7 @@ public function leaveNode(Node $node) if ($this->cleanUpMethod) { $this->cleanUpMethod = false; - return NodeTraverser::REMOVE_NODE; + return NodeVisitor::REMOVE_NODE; } return $node; diff --git a/src/Builder/Visitor/ReplaceAndCollectFullyQualifiedClassNamesVisitor.php b/src/Builder/Visitor/ReplaceAndCollectFullyQualifiedClassNamesVisitor.php index f989a81c..9b92858d 100644 --- a/src/Builder/Visitor/ReplaceAndCollectFullyQualifiedClassNamesVisitor.php +++ b/src/Builder/Visitor/ReplaceAndCollectFullyQualifiedClassNamesVisitor.php @@ -38,7 +38,7 @@ public function enterNode(Node $node) return $node; } - $this->fullyQualifiedClassNames->append(implode('\\', $node->parts)); + $this->fullyQualifiedClassNames->append($node->name); return new Name($node->getLast()); } diff --git a/src/ConfigReader/ConfigReader.php b/src/ConfigReader/ConfigReader.php index 24ff50b5..1c357d38 100644 --- a/src/ConfigReader/ConfigReader.php +++ b/src/ConfigReader/ConfigReader.php @@ -56,7 +56,7 @@ protected function getAst(string $configPath): array { $configFileContent = $this->getFileContent($configPath); - $parser = $this->parserFactory->create(ParserFactory::PREFER_PHP7); + $parser = $this->parserFactory->createForHostVersion(); $ast = $parser->parse($configFileContent); diff --git a/src/ConfigReader/ConfigValuesVisitor.php b/src/ConfigReader/ConfigValuesVisitor.php index ca6aa937..84319271 100644 --- a/src/ConfigReader/ConfigValuesVisitor.php +++ b/src/ConfigReader/ConfigValuesVisitor.php @@ -91,7 +91,7 @@ protected function getValuesFromArray(Array_ $array): array { $values = []; - /** @var \PhpParser\Node\Expr\ArrayItem $item */ + /** @var \PhpParser\Node\ArrayItem $item */ foreach ($array->items as $item) { $itemValue = $item->value; diff --git a/src/IntegratorFactory.php b/src/IntegratorFactory.php index 2a5f686b..71aed90b 100644 --- a/src/IntegratorFactory.php +++ b/src/IntegratorFactory.php @@ -12,11 +12,8 @@ use CzProject\GitPhp\Runners\CliRunner; use GuzzleHttp\Client; use PhpParser\BuilderFactory; -use PhpParser\Lexer; -use PhpParser\Lexer\Emulative; use PhpParser\NodeTraverser; use PhpParser\Parser; -use PhpParser\Parser\Php7; use PhpParser\ParserFactory; use SprykerSdk\Integrator\Builder\ArgumentBuilder\ArgumentBuilder; use SprykerSdk\Integrator\Builder\ArgumentBuilder\ArgumentBuilderInterface; @@ -670,11 +667,8 @@ protected function createPrefixedConstNameResolver(): PrefixedConstNameResolverI */ public function createClassLoader(): ClassLoaderInterface { - $lexer = $this->createPhpParserLexer(); - return new ClassLoader( - $this->createPhpParserParser($lexer), - $lexer, + $this->createPhpParserParser(), ); } @@ -683,11 +677,8 @@ public function createClassLoader(): ClassLoaderInterface */ public function createFileLoader(): FileLoaderInterface { - $lexer = $this->createPhpParserLexer(); - return new FileLoader( - $this->createPhpParserParser($lexer), - $lexer, + $this->createPhpParserParser(), ); } @@ -905,17 +896,11 @@ public function createClassHelper(): ClassHelperInterface } /** - * @param \PhpParser\Lexer|null $lexer - * * @return \PhpParser\Parser */ - public function createPhpParserParser(?Lexer $lexer = null): Parser + public function createPhpParserParser(): Parser { - if (!$lexer) { - $lexer = $this->createPhpParserLexer(); - } - - return new Php7($lexer); + return (new ParserFactory())->createForHostVersion(); } /** @@ -926,20 +911,6 @@ public function getPhpParserNodeTraverser(): NodeTraverser return new NodeTraverser(); } - /** - * @return \PhpParser\Lexer - */ - public function createPhpParserLexer(): Lexer - { - return new Emulative([ - 'usedAttributes' => [ - 'comments', - 'startLine', 'endLine', - 'startTokenPos', 'endTokenPos', - ], - ]); - } - /** * @return array<\SprykerSdk\Integrator\ManifestStrategy\ManifestStrategyInterface> */ @@ -1163,7 +1134,7 @@ public function createArgumentBuilder(): ArgumentBuilderInterface public function createNodeExpressionPartialParser(): ExpressionPartialParserInterface { return new ExpressionPartialParser( - (new ParserFactory())->create(ParserFactory::PREFER_PHP7), + $this->createPhpParserParser(), ); } diff --git a/tests/SprykerSdkTest/Integrator/Builder/PartialParser/ExpressionPartialParserTest.php b/tests/SprykerSdkTest/Integrator/Builder/PartialParser/ExpressionPartialParserTest.php index 30a11d1b..ef382b97 100644 --- a/tests/SprykerSdkTest/Integrator/Builder/PartialParser/ExpressionPartialParserTest.php +++ b/tests/SprykerSdkTest/Integrator/Builder/PartialParser/ExpressionPartialParserTest.php @@ -25,7 +25,7 @@ class ExpressionPartialParserTest extends TestCase public function testParseShouldReturnStringExprWhenInvalidPhpCode(): void { // Arrange - $parser = new ExpressionPartialParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)); + $parser = new ExpressionPartialParser((new ParserFactory())->createForHostVersion()); $code = 'some invalid code'; // Act @@ -59,7 +59,7 @@ public function testParseShouldReturnStringExprWhenAstIsNull(): void public function testParseShouldReturnStringExprWhenGlobalConstantSet(): void { // Arrange - $parser = new ExpressionPartialParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)); + $parser = new ExpressionPartialParser((new ParserFactory())->createForHostVersion()); $code = 'SOME_VALUE'; // Act @@ -76,7 +76,7 @@ public function testParseShouldReturnStringExprWhenGlobalConstantSet(): void public function testParseShouldReturnExprWhenWellFormedPhpCodeSet(): void { // Arrange - $parser = new ExpressionPartialParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)); + $parser = new ExpressionPartialParser((new ParserFactory())->createForHostVersion()); $code = 'assertInstanceOf(New_::class, $parserResult->expr); - $this->assertSame('ArrayObject', $parserResult->expr->class->parts[0]); + $this->assertSame('ArrayObject', $parserResult->expr->class->name); } /** @@ -93,25 +93,20 @@ public function testParseShouldReturnExprWhenWellFormedPhpCodeSet(): void public function testParseShouldReturnExprWithUsedClassesWhenFQCNSet(): void { // Arrange - $parser = new ExpressionPartialParser((new ParserFactory())->create(ParserFactory::PREFER_PHP7)); + $parser = new ExpressionPartialParser((new ParserFactory())->createForHostVersion()); $code = '\\Spryker\\Shared\\Config\\Config::get(\\Spryker\\Shared\\Log\\LogConstants::LOG_QUEUE_NAME)'; $dumper = new NodeDumper(); // Act $parserResult = $parser->parse($code); - $dumpedExpr = $dumper->dump($parserResult->expr); + $dumpedExpr = $dumper->dump($parserResult->expr, $code); // Assert $this->assertEquals( <<<'DUMP' Expr_StaticCall( class: Name_FullyQualified( - parts: array( - 0: Spryker - 1: Shared - 2: Config - 3: Config - ) + name: Spryker\Shared\Config\Config ) name: Identifier( name: get @@ -121,12 +116,7 @@ class: Name_FullyQualified( name: null value: Expr_ClassConstFetch( class: Name_FullyQualified( - parts: array( - 0: Spryker - 1: Shared - 2: Log - 3: LogConstants - ) + name: Spryker\Shared\Log\LogConstants ) name: Identifier( name: LOG_QUEUE_NAME