Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FRW-8778 Increased min PHP version, increased nikic/parser dependency version. #181

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ jobs:
fail-fast: false
matrix:
php-version: [
'8.0',
'8.1',
'8.2',
'8.3'
]
Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Integrator module",
"license": "proprietary",
"require": {
"php": ">=8.0",
"php": ">=8.1",
"ext-dom": "*",
"ext-json": "*",
"ext-simplexml": "*",
Expand All @@ -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",
Expand Down
7 changes: 1 addition & 6 deletions src/Builder/Checker/ClassMethodChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
*/
Expand Down Expand Up @@ -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('<?php %s;', $value));
if (!$previousValue) {
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,19 @@ public function isSameStatement($previousValue, $currentValue): bool
if (is_string($previousValue->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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/**
Expand All @@ -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);
}
}
10 changes: 1 addition & 9 deletions src/Builder/ClassLoader/AbstractLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace SprykerSdk\Integrator\Builder\ClassLoader;

use PhpParser\Lexer;
use PhpParser\NodeTraverser;
use PhpParser\NodeVisitor\CloningVisitor;
use PhpParser\NodeVisitor\NameResolver;
Expand All @@ -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;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/ClassLoader/ClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/ClassLoader/FileLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<?php %s;', $value));
$tree = $this->parserFactory->createForHostVersion()->parse(sprintf('<?php %s;', $value));

if ($tree === null) {
throw new LiteralValueParsingException(sprintf('Value is not valid statement PHP code: `%s`', $value));
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/ClassModifier/ConfigFile/ConfigFileModifier.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
namespace SprykerSdk\Integrator\Builder\ClassModifier\ConfigFile;

use PhpParser\Node;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\ArrayItem;
use PhpParser\NodeFinder;
use PhpParser\NodeTraverser;
use SprykerSdk\Integrator\Builder\PartialParser\ExpressionPartialParserInterface;
Expand Down Expand Up @@ -43,7 +43,7 @@ public function addArrayItemToEnvConfig(
): FileInformationTransfer {
$valueStm = $this->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;
});
Expand Down
4 changes: 2 additions & 2 deletions src/Builder/Comparer/ClassConstExpressionCompareStrategy.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
13 changes: 7 additions & 6 deletions src/Builder/Creator/MethodCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down Expand Up @@ -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));
}
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand All @@ -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;
}

/**
Expand Down Expand Up @@ -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(),
Expand Down
11 changes: 7 additions & 4 deletions src/Builder/Creator/MethodStatementsCreator.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -150,7 +151,9 @@ protected function createArrayItem(

if ($insideArrayItems) {
return new ArrayItem(
(new BuilderFactory())->val($insideArrayItems),
(new BuilderFactory())->val(
new Array_($insideArrayItems),
),
$key,
);
}
Expand All @@ -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
{
Expand Down
2 changes: 1 addition & 1 deletion src/Builder/Printer/ClassPrinter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 3 additions & 3 deletions src/Builder/Visitor/AddArrayItemToEnvConfigVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,7 +27,7 @@ class AddArrayItemToEnvConfigVisitor extends NodeVisitorAbstract
protected $target;

/**
* @var \PhpParser\Node\Expr\ArrayItem
* @var \PhpParser\Node\ArrayItem
*/
protected $value;

Expand All @@ -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)
{
Expand Down
15 changes: 5 additions & 10 deletions src/Builder/Visitor/AddClassToClassListVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -60,11 +60,6 @@ class AddClassToClassListVisitor extends NodeVisitorAbstract
*/
protected $after;

/**
* @var \PhpParser\Node
*/
protected $parentNode;

/**
* @param string $methodName
* @param string $className
Expand Down Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -257,7 +252,7 @@ protected function addArrayElementToPosition(Node $node): array
}

/**
* @return \PhpParser\Node\Expr\ArrayItem
* @return \PhpParser\Node\ArrayItem
*/
protected function createArrayItemWithInstanceOf(): ArrayItem
{
Expand All @@ -273,6 +268,6 @@ protected function successfullyProcessed(): int
{
$this->methodFound = false;

return NodeTraverser::DONT_TRAVERSE_CHILDREN;
return NodeVisitor::DONT_TRAVERSE_CHILDREN;
}
}
Loading
Loading