Skip to content
Closed
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
2 changes: 1 addition & 1 deletion .github/workflows/code_analysis.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ jobs:
-
name: 'Active Classes'
run: |
vendor/bin/class-leak check bin config src rules utils --skip-suffix "Rector" --skip-type="Rector\\Utils\\Compiler\\Unprefixer" --skip-type="Rector\\NodeCollector\\BinaryOpConditionsCollector" --skip-type="Rector\\Set\\Contract\\SetListInterface"
vendor/bin/class-leak check bin config src rules utils --skip-suffix "Rector" --skip-type="Rector\\Utils\\Compiler\\Unprefixer" --skip-type="Rector\\NodeCollector\\BinaryOpConditionsCollector" --skip-type="Rector\\Set\\Contract\\SetListInterface" --skip-type="Rector\\Contract\\PhpParser\\Node\\StmtsAwareInterface"

-
name: 'Compatible PHPStan versions'
Expand Down
7 changes: 1 addition & 6 deletions build/build-preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -361,12 +361,7 @@ private function findPhpParserFilesAndSortThem(string $vendorDir): array
}
}

$fileInfos = array_values($fileInfos);

$stmtsAwareInterface = new SplFileInfo(__DIR__ . '/../src/Contract/PhpParser/Node/StmtsAwareInterface.php');
array_splice($fileInfos, 1, 0, [$stmtsAwareInterface]);

return $fileInfos;
return array_values($fileInfos);
}

/**
Expand Down
27 changes: 10 additions & 17 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"doctrine/inflector": "^2.1",
"illuminate/container": "^11.46",
"nette/utils": "^4.0",
"nikic/php-parser": "^5.6.1",
"nikic/php-parser": "dev-tv-add-stmts-iterable as 5.4",
"ondram/ci-detector": "^4.2",
"phpstan/phpdoc-parser": "^2.3",
"phpstan/phpstan": "^2.1.26",
Expand Down Expand Up @@ -81,6 +81,7 @@
"rules-tests",
"tests"
],
"Rector\\Utils\\Tests\\": "utils-tests",
"E2e\\Parallel\\Reflection\\Resolver\\": [
"e2e/parallel-reflection-resolver/src/",
"e2e/no-parallel-reflection-resolver/src"
Expand Down Expand Up @@ -116,21 +117,6 @@
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/illuminate-container-container-php.patch"
],
"nikic/php-parser": [
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-expr-closure-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-finally-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-function-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-do-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-catch-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-trycatch-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-for-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-classmethod-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-else-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-while-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-foreach-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-if-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-case-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-elseif-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-node-stmt-namespace-php.patch",
"https://raw.githubusercontent.com/rectorphp/vendor-patches/main/patches/nikic-php-parser-lib-phpparser-nodetraverser-php.patch"
]
},
Expand All @@ -147,5 +133,12 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/tomasVotruba/php-parser",
"no-api": true
}
]
}
7 changes: 6 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ parameters:

-
identifier: symplify.seeAnnotationToTest
path: utils/PHPStan/Rule/PreferDirectIsNameRule.php
path: utils/

-
identifier: arrayValues.list
Expand All @@ -356,3 +356,8 @@ parameters:
-
identifier: offsetAccess.invalidOffset
path: src/CustomRules/SimpleNodeDumper.php

-
message: '#Method Rector\\Utils\\Rector\\MakeUseOfContaintsStmtsRector\:\:refactor\(\) should return 4\|PhpParser\\Node\\Expr\\BinaryOp\\Identical\|PhpParser\\Node\\Expr\\MethodCall\|null but returns int\|null#'
path: utils/Rector/MakeUseOfContaintsStmtsRector.php
- message: '#Method Rector\\Utils\\Rector\\MakeUseOfContainsStmtsRector\:\:refactor\(\) should return 4\|PhpParser\\Node\\Expr\\BinaryOp\\Identical\|PhpParser\\Node\\Expr\\MethodCall\|null but returns int\|null#'
2 changes: 1 addition & 1 deletion preload-split-package.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function isPHPStanTestPreloaded(): bool
}

require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node.php';
require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php';
Expand Down Expand Up @@ -104,6 +103,7 @@ function isPHPStanTestPreloaded(): bool
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/ClosureUse.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/Const_.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/ContainsStmts.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/DeclareItem.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php';
require_once __DIR__ . '/../../../vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php';
Expand Down
2 changes: 1 addition & 1 deletion preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ function isPHPStanTestPreloaded(): bool
}

require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeVisitor.php';
Expand Down Expand Up @@ -104,6 +103,7 @@ function isPHPStanTestPreloaded(): bool
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/AttributeGroup.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/ClosureUse.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Const_.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/ContainsStmts.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/DeclareItem.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/ArrayDimFetch.php';
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr/Array_.php';
Expand Down
2 changes: 2 additions & 0 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ConstFetch\RemovePhpVersionIdCheckRector;
use Rector\Php55\Rector\String_\StringClassNameToClassConstantRector;
use Rector\Utils\Rector\MakeUseOfContainsStmtsRector;

return RectorConfig::configure()
->withPreparedSets(
Expand Down Expand Up @@ -35,6 +36,7 @@
__DIR__ . '/config',
__DIR__ . '/build/build-preload.php',
])
->withRules([MakeUseOfContainsStmtsRector::class])
->withRootFiles()
->withImportNames(removeUnusedImports: true)
->withSkip([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\CodeQuality\Rector\ClassMethod;

use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
Expand All @@ -16,7 +17,6 @@
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\CodeQuality\NodeAnalyzer\VariableDimFetchAssignResolver;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Exception\NotImplementedYetException;
use Rector\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
Expand Down Expand Up @@ -66,11 +66,11 @@ function getPerson()
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\CodeQuality\Rector\Foreach_;

use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayDimFetch;
Expand All @@ -15,7 +16,6 @@
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\NodeVisitor;
use Rector\CodeQuality\NodeAnalyzer\ForeachAnalyzer;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeAnalyzer\ExprAnalyzer;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -75,11 +75,11 @@ public function run($items)
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
6 changes: 3 additions & 3 deletions rules/CodeQuality/Rector/Foreach_/ForeachToInArrayRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\CodeQuality\Rector\Foreach_;

use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Equal;
use PhpParser\Node\Expr\BinaryOp\Identical;
Expand All @@ -15,7 +16,6 @@
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use PhpParser\NodeFinder;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeManipulator\BinaryOpManipulator;
use Rector\Php71\ValueObject\TwoNodeMatch;
use Rector\PhpParser\Node\Value\ValueResolver;
Expand Down Expand Up @@ -64,11 +64,11 @@ public function getRuleDefinition(): RuleDefinition
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace Rector\CodeQuality\Rector\Foreach_;

use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ArrayDimFetch;
use PhpParser\Node\Expr\Assign;
Expand All @@ -16,7 +17,6 @@
use PhpParser\Node\Stmt\Foreach_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Rector\AbstractRector;
use Rector\ValueObject\PhpVersionFeature;
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
Expand Down Expand Up @@ -57,11 +57,11 @@ public function getRuleDefinition(): RuleDefinition
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

use PhpParser\Node;
use PhpParser\Node\ArrayItem;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\List_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\Foreach_;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\DeadCode\NodeAnalyzer\ExprUsedInNodeAnalyzer;
use Rector\NodeManipulator\StmtsManipulator;
use Rector\PhpParser\Node\BetterNodeFinder;
Expand Down Expand Up @@ -71,11 +71,11 @@ public function run()
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Comment\Doc;
use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\AssignOp;
use PhpParser\Node\Expr\Ternary;
Expand All @@ -15,7 +16,6 @@
use PhpParser\Node\Stmt\Return_;
use PHPStan\Type\MixedType;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\Contract\Rector\ConfigurableRectorInterface;
use Rector\NodeAnalyzer\CallAnalyzer;
use Rector\NodeAnalyzer\VariableAnalyzer;
Expand Down Expand Up @@ -106,11 +106,11 @@ function () {
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down Expand Up @@ -152,11 +152,11 @@ public function refactor(Node $node): ?Node
}

private function processSimplifyUselessVariable(
StmtsAwareInterface $stmtsAware,
ContainsStmts $stmtsAware,
Return_ $return,
Assign|AssignOp $assign,
int $key
): ?StmtsAwareInterface {
): ?ContainsStmts {
if (! $assign instanceof Assign) {
$binaryClass = $this->assignAndBinaryMap->getAlternative($assign);
if ($binaryClass === null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
namespace Rector\CodeQuality\Rector\If_;

use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp\Coalesce;
use PhpParser\Node\Expr\Throw_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeManipulator\IfManipulator;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -72,11 +72,11 @@ public function run()
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?Node
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
namespace Rector\CodeQuality\Rector\If_;

use PhpParser\Node;
use PhpParser\Node\ContainsStmts;
use PhpParser\Node\Expr;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\Return_;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\NodeManipulator\IfManipulator;
use Rector\PhpParser\Node\Value\ValueResolver;
use Rector\Rector\AbstractRector;
Expand Down Expand Up @@ -56,13 +56,13 @@ public function getRuleDefinition(): RuleDefinition
*/
public function getNodeTypes(): array
{
return [StmtsAwareInterface::class];
return [ContainsStmts::class];
}

/**
* @param StmtsAwareInterface $node
* @param ContainsStmts $node
*/
public function refactor(Node $node): ?StmtsAwareInterface
public function refactor(Node $node): ?ContainsStmts
{
foreach ((array) $node->stmts as $key => $stmt) {
if (! $stmt instanceof If_) {
Expand Down
Loading
Loading