Skip to content

Commit

Permalink
Bump Symplify to 10.0.16 + improve complexity (#1725)
Browse files Browse the repository at this point in the history
Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Jan 25, 2022
1 parent 420dc93 commit caeeb78
Show file tree
Hide file tree
Showing 15 changed files with 198 additions and 142 deletions.
45 changes: 23 additions & 22 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"ext-json": "*",
"clue/ndjson-react": "^1.2",
"composer/semver": "^3.2",
"composer/xdebug-handler": "^2.0",
"composer/xdebug-handler": "^2.0|^3.0",
"doctrine/inflector": "^2.0",
"ergebnis/json-printer": "^3.2",
"idiosyncratic/editorconfig": "^0.1.3",
Expand Down Expand Up @@ -45,25 +45,26 @@
"symfony/process": "^6.0",
"symfony/string": "^6.0",
"symfony/yaml": "^5.4|^6.0",
"symplify/astral": "^10.0.11",
"symplify/autowire-array-parameter": "^10.0.11",
"symplify/composer-json-manipulator": "^10.0.11",
"symplify/console-color-diff": "^10.0.11",
"symplify/easy-parallel": "^10.0.11",
"symplify/package-builder": "^10.0.11",
"symplify/rule-doc-generator-contracts": "^10.0.11",
"symplify/simple-php-doc-parser": "^10.0.11",
"symplify/skipper": "^10.0.11",
"symplify/smart-file-system": "^10.0.11",
"symplify/symfony-php-config": "^10.0.11",
"symplify/vendor-patches": "^10.0.11",
"symplify/astral": "^10.0.16",
"symplify/symplify-kernel": "^10.0.16",
"symplify/autowire-array-parameter": "^10.0.16",
"symplify/composer-json-manipulator": "^10.0.16",
"symplify/console-color-diff": "^10.0.16",
"symplify/easy-parallel": "^10.0.16",
"symplify/package-builder": "^10.0.16",
"symplify/rule-doc-generator-contracts": "^10.0.16",
"symplify/simple-php-doc-parser": "^10.0.16",
"symplify/skipper": "^10.0.16",
"symplify/smart-file-system": "^10.0.16",
"symplify/symfony-php-config": "^10.0.16",
"symplify/vendor-patches": "^10.0.16",
"tracy/tracy": "^2.9",
"webmozart/assert": "^1.10",
"helmich/typo3-typoscript-parser": "dev-master#0ccb3a6"
},
"require-dev": {
"brianium/paratest": "^6.3",
"friendsofphp/php-cs-fixer": "^3.4",
"friendsofphp/php-cs-fixer": "^3.5",
"nategood/httpful": "^0.3.2",
"phpstan/extension-installer": "^1.1",
"phpstan/phpstan-nette": "^1.0",
Expand All @@ -73,14 +74,14 @@
"phpunit/phpunit": "^9.5",
"rector/phpstan-rules": "^0.4.15",
"spatie/enum": "^3.10",
"symplify/coding-standard": "^10.0.11",
"symplify/easy-ci": "^10.0.11",
"symplify/easy-coding-standard": "^10.0.11",
"symplify/easy-testing": "^10.0.11",
"symplify/monorepo-builder": "^10.0.11",
"symplify/phpstan-extensions": "^10.0.11",
"symplify/phpstan-rules": "^10.0.11",
"symplify/rule-doc-generator": "^10.0.11",
"symplify/coding-standard": "^10.0.16",
"symplify/easy-ci": "^10.0.16",
"symplify/easy-coding-standard": "^10.0.16",
"symplify/easy-testing": "^10.0.16",
"symplify/monorepo-builder": "^10.0.16",
"symplify/phpstan-extensions": "^10.0.16",
"symplify/phpstan-rules": "^10.0.16",
"symplify/rule-doc-generator": "^10.0.16",
"timeweb/phpstan-enum": "dev-22-upgrade-phpstan-to-1.0"
},
"replace": {
Expand Down
8 changes: 6 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@ parameters:
- rules/Php70/EregToPcreTransformer.php
- packages/NodeTypeResolver/NodeTypeResolver.php
- rules/Renaming/NodeManipulator/ClassRenamer.php
- rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php

- "#^Cognitive complexity for \"Rector\\\\Php70\\\\EregToPcreTransformer\\:\\:(.*?)\" is (.*?), keep it under 10$#"
- '#Cognitive complexity for "Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver\:\:getValue\(\)" is \d+, keep it under 10#'
Expand Down Expand Up @@ -417,7 +416,6 @@ parameters:
message: '#Offset (.*?) on array(.*?) on left side of \?\? always exists and is not nullable#'
paths:
- packages/NodeTypeResolver/DependencyInjection/PHPStanServicesFactory.php
- src/Bootstrap/ExtensionConfigResolver.php

-
message: '#Method Rector\\VersionBonding\\PhpVersionedFilter\:\:filter\(\) should return array<T of Rector\\Core\\Contract\\Rector\\RectorInterface\> but returns array<int, \(Rector\\VersionBonding\\Contract\\MinPhpVersionInterface&T of Rector\\Core\\Contract\\Rector\\RectorInterface\)\|T of Rector\\Core\\Contract\\Rector\\RectorInterface\>#'
Expand Down Expand Up @@ -608,3 +606,9 @@ parameters:
-
message: '#Only booleans are allowed in an if condition, array\|null given#'
path: rules/Naming/Naming/PropertyNaming.php

- '#Parameter \#1 \$objectOrClass of class ReflectionClass constructor expects class\-string<Rector\\RectorInstaller\\GeneratedConfig\>\|Rector\\RectorInstaller\\GeneratedConfig, string given#'

-
path: src/Bootstrap/ExtensionConfigResolver.php
message: '#Offset (.*?)includes(.*?) always exists and is not nullable#'
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final class SkipParentConstructOverrideInPHP72Test extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @see https://phpunit.readthedocs.io/en/8.3/incomplete-and-skipped-tests.html#incomplete-and-skipped-tests-requires-tables-api
*
* @dataProvider provideData()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final class DowngradeParameterTypeWideningRectorTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final class EmptyConfigTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final class DowngradeJsonDecodeNullAssociativeArgRectorTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final class DowngradePregUnmatchedAsNullConstantRectorTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
final class DowngradeObjectTypeDeclarationRectorTest extends AbstractRectorTestCase
{
/**
* @requires PHP 7.2
* @dataProvider provideData()
*/
public function test(SmartFileInfo $fileInfo): void
Expand Down
74 changes: 74 additions & 0 deletions rules/DowngradePhp72/NodeAnalyzer/RegexFuncAnalyzer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
<?php

declare(strict_types=1);

namespace Rector\DowngradePhp72\NodeAnalyzer;

use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Ternary;
use PhpParser\Node\Expr\Variable;
use Rector\Core\PhpParser\Comparing\NodeComparator;
use Rector\Core\PhpParser\Node\BetterNodeFinder;
use Rector\Core\PhpParser\Node\Value\ValueResolver;
use Rector\NodeNameResolver\NodeNameResolver;

final class RegexFuncAnalyzer
{
/**
* @var string[]
*/
private const REGEX_FUNCTION_NAMES = ['preg_match', 'preg_match_all'];

public function __construct(
private readonly NodeNameResolver $nodeNameResolver,
private readonly BetterNodeFinder $betterNodeFinder,
private readonly NodeComparator $nodeComparator,
private readonly ValueResolver $valueResolver,
) {
}

public function isRegexFunctionNames(FuncCall $funcCall): bool
{
if ($this->nodeNameResolver->isNames($funcCall, self::REGEX_FUNCTION_NAMES)) {
return true;
}

$variable = $funcCall->name;
if (! $variable instanceof Variable) {
return false;
}

/** @var Assign|null $assignExprVariable */
$assignExprVariable = $this->betterNodeFinder->findFirstPreviousOfNode($funcCall, function (Node $node) use (
$variable
): bool {
if (! $node instanceof Assign) {
return false;
}

return $this->nodeComparator->areNodesEqual($node->var, $variable);
});

if (! $assignExprVariable instanceof Assign) {
return false;
}

$expr = $assignExprVariable->expr;
if (! $expr instanceof Ternary) {
return false;
}

if (! $expr->if instanceof Expr) {
return false;
}

if (! $this->valueResolver->isValues($expr->if, self::REGEX_FUNCTION_NAMES)) {
return false;
}

return $this->valueResolver->isValues($expr->else, self::REGEX_FUNCTION_NAMES);
}
}
67 changes: 67 additions & 0 deletions rules/DowngradePhp72/NodeManipulator/BitwiseFlagCleaner.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php

declare(strict_types=1);

namespace Rector\DowngradePhp72\NodeManipulator;

use PhpParser\Node\Arg;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\BitwiseOr;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\FuncCall;
use Rector\NodeNameResolver\NodeNameResolver;

final class BitwiseFlagCleaner
{
public function __construct(
private readonly NodeNameResolver $nodeNameResolver
) {
}

public function cleanFuncCall(FuncCall $funcCall, BitwiseOr $bitwiseOr, Expr $expr = null, string $flag): void
{
if ($bitwiseOr->left instanceof BitwiseOr) {
/** @var BitwiseOr $leftLeft */
$leftLeft = $bitwiseOr->left;
if ($leftLeft->left instanceof ConstFetch && $this->nodeNameResolver
->isName($leftLeft->left, $flag)) {
$bitwiseOr = new BitwiseOr($leftLeft->right, $bitwiseOr->right);
}

/** @var BitwiseOr $leftRight */
$leftRight = $bitwiseOr->left;
if ($leftRight->right instanceof ConstFetch && $this->nodeNameResolver
->isName($leftRight->right, $flag)) {
$bitwiseOr = new BitwiseOr($leftRight->left, $bitwiseOr->right);
}

if ($bitwiseOr->left instanceof BitwiseOr) {
$this->cleanFuncCall($funcCall, $bitwiseOr->left, $bitwiseOr->right, $flag);
return;
}
}

if ($expr instanceof Expr) {
$bitwiseOr = new BitwiseOr($bitwiseOr, $expr);
}

$this->assignThirdArgsValue($funcCall, $bitwiseOr, $flag);
}

private function assignThirdArgsValue(FuncCall $funcCall, BitwiseOr $bitwiseOr, string $flag): void
{
if ($bitwiseOr->right instanceof ConstFetch && $this->nodeNameResolver
->isName($bitwiseOr->right, $flag)) {
$bitwiseOr = $bitwiseOr->left;
} elseif ($bitwiseOr->left instanceof ConstFetch && $this->nodeNameResolver
->isName($bitwiseOr->left, $flag)) {
$bitwiseOr = $bitwiseOr->right;
}

if (! $funcCall->args[3] instanceof Arg) {
return;
}

$funcCall->args[3]->value = $bitwiseOr;
}
}
Loading

0 comments on commit caeeb78

Please sign in to comment.