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
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
26 changes: 9 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 @@ -116,21 +116,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 +132,12 @@
}
},
"minimum-stability": "dev",
"prefer-stable": true
"prefer-stable": true,
"repositories": [
{
"type": "vcs",
"url": "https://github.com/tomasVotruba/php-parser",
"no-api": true
}
]
}
6 changes: 5 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,7 @@ 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
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,7 @@ 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__ . '/src/Contract/PhpParser/Node/ContainsStmts.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
2 changes: 1 addition & 1 deletion preload.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ 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__ . '/src/Contract/PhpParser/Node/ContainsStmts.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
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\MakeUseOfContaintsStmtsRector;

return RectorConfig::configure()
->withPreparedSets(
Expand Down Expand Up @@ -35,6 +36,7 @@
__DIR__ . '/config',
__DIR__ . '/build/build-preload.php',
])
->withRules([MakeUseOfContaintsStmtsRector::class])
->withRootFiles()
->withImportNames(removeUnusedImports: true)
->withSkip([
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@ final class ExistingAssertStaticCallResolver
*/
public function resolve(ClassMethod $classMethod): array
{
if ($classMethod->stmts === null) {
if ($classMethod->getStmts() === []) {
return [];
}

$existingAssertCallHashes = [];
$standard = new Standard();

foreach ($classMethod->stmts as $currentStmt) {
foreach ($classMethod->getStmts() as $currentStmt) {
if (! $currentStmt instanceof Expression) {
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public function refactor(Node $node): ?ClassMethod
return null;
}

if ($node->stmts === null || $node->isAbstract()) {
if ($node->getStmts() === [] || $node->isAbstract()) {
return null;
}

Expand Down
4 changes: 2 additions & 2 deletions rules/CodeQuality/NodeAnalyzer/ForeachAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ public function __construct(
*/
public function matchAssignItemsOnlyForeachArrayVariable(Foreach_ $foreach): ?Expr
{
if (count($foreach->stmts) !== 1) {
if (count($foreach->getStmts()) !== 1) {
return null;
}

$onlyStatement = $foreach->stmts[0];
$onlyStatement = $foreach->getStmts()[0];
if ($onlyStatement instanceof Expression) {
$onlyStatement = $onlyStatement->expr;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public function refactor(Node $node): ?Node
}

$isChanged = false;
$this->traverseNodesWithCallable($node->stmts, function (Node $node) use (
$this->traverseNodesWithCallable($node->getStmts(), function (Node $node) use (
$caughtThrowableVariable,
&$isChanged
): ?int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ public function refactor(Node $node): ?Node
}

$hasChanged = false;
$this->traverseNodesWithCallable((array) $node->stmts, static function (Node $node) use (
$this->traverseNodesWithCallable((array) $node->getStmts(), static function (Node $node) use (
&$hasChanged
): int|null|Return_ {
if ($node instanceof Class_ || $node instanceof Function_ || $node instanceof Closure) {
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 @@ -81,7 +81,7 @@ public function refactor(Node $node): ?Node
return null;
}

if ($constructClassMethod->stmts === null) {
if ($constructClassMethod->getStmts() === []) {
return null;
}

Expand Down Expand Up @@ -182,14 +182,14 @@ private function refactorProperty(
AttributeKey::COMMENTS,
array_merge(
$classStmt->getComments(),
isset($constructClassMethod->stmts[$key])
? $constructClassMethod->stmts[$key]->getComments()
isset($constructClassMethod->getStmts()[$key])
? $constructClassMethod->getStmts()[$key]->getComments()
: [],
)
);

// remove assign
unset($constructClassMethod->stmts[$key]);
unset($constructClassMethod->getStmts()[$key]);

return true;
}
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
14 changes: 7 additions & 7 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,15 +64,15 @@ 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
{
if ($node->stmts === null) {
if ($node->getStmts() === []) {
return null;
}

Expand Down Expand Up @@ -162,11 +162,11 @@ private function shouldSkipForeach(Foreach_ $foreach): bool
return true;
}

if (count($foreach->stmts) > 1) {
if (count($foreach->getStmts()) > 1) {
return true;
}

if (! $foreach->stmts[0] instanceof If_) {
if (! $foreach->getStmts()[0] instanceof If_) {
return true;
}

Expand Down Expand Up @@ -196,7 +196,7 @@ private function matchNodes(Equal|Identical $binaryOp, Expr $expr): ?TwoNodeMatc

private function isIfBodyABoolReturnNode(If_ $if): bool
{
$ifStatement = $if->stmts[0];
$ifStatement = $if->getStmts()[0];
if (! $ifStatement instanceof Return_) {
return false;
}
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,15 +57,15 @@ 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
{
if ($node->stmts === null) {
if ($node->getStmts() === []) {
return null;
}

Expand Down Expand Up @@ -147,11 +147,11 @@ public function provideMinPhpVersion(): int
*/
private function matchForeachReturnOrAssign(Foreach_ $foreach): Expression|Return_|null
{
if (count($foreach->stmts) !== 1) {
if (count($foreach->getStmts()) !== 1) {
return null;
}

$onlyForeachStmt = $foreach->stmts[0];
$onlyForeachStmt = $foreach->getStmts()[0];
if (! $onlyForeachStmt instanceof If_) {
return null;
}
Expand All @@ -161,7 +161,7 @@ private function matchForeachReturnOrAssign(Foreach_ $foreach): Expression|Retur
return null;
}

if (count($if->stmts) !== 1) {
if (count($if->getStmts()) !== 1) {
return null;
}

Expand All @@ -174,7 +174,7 @@ private function matchForeachReturnOrAssign(Foreach_ $foreach): Expression|Retur
return null;
}

$innerStmt = $if->stmts[0];
$innerStmt = $if->getStmts()[0];
if ($innerStmt instanceof Return_) {
return $innerStmt;
}
Expand Down Expand Up @@ -205,7 +205,7 @@ private function processForeachNodeWithReturnInside(
}

/** @var If_ $ifNode */
$ifNode = $foreach->stmts[0];
$ifNode = $foreach->getStmts()[0];

/** @var Identical $identicalNode */
$identicalNode = $ifNode->cond;
Expand All @@ -229,7 +229,7 @@ private function processForeachNodeWithReturnInside(
private function processForeachNodeWithAssignInside(Foreach_ $foreach, Assign $assign): ?Assign
{
/** @var If_ $ifNode */
$ifNode = $foreach->stmts[0];
$ifNode = $foreach->getStmts()[0];

/** @var Identical $identicalNode */
$identicalNode = $ifNode->cond;
Expand Down
Loading
Loading