Skip to content

Commit 24977b2

Browse files
authored
[stmts-aware] Deprecate the interface and replace with meta-type + groups (#7679)
* [enum] kick of node group, deprecate stmts aware interface * use StmtsAware meta-type * [coding-style] Decouple NewlineBetweenClassLikeStmtsRector from NewlineAfterStatementRector * skip node in RenameParamToMatchTypeRector as vague type that can be narrowed by name * update test * import FQNs * add file without ns * remove rest of instanceof checks * fixup! remove rest of instanceof checks
1 parent 7f5d49d commit 24977b2

71 files changed

Lines changed: 716 additions & 381 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

phpstan.neon

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@ parameters:
88
reportUnmatchedIgnoredErrors: false
99
errorFormat: symplify
1010

11+
# see https://phpstan.org/writing-php-code/phpdoc-types#global-type-aliases
12+
typeAliases:
13+
StmtsAware: \PhpParser\Node\Expr\Closure | \PhpParser\Node\Stmt\Case_ | \PhpParser\Node\Stmt\Catch_ | \PhpParser\Node\Stmt\ClassMethod | \PhpParser\Node\Stmt\Do_ | \PhpParser\Node\Stmt\Else_ | \PhpParser\Node\Stmt\ElseIf_ | \PhpParser\Node\Stmt\Finally_ | \PhpParser\Node\Stmt\For_ | \PhpParser\Node\Stmt\Foreach_ | \PhpParser\Node\Stmt\Function_ | \PhpParser\Node\Stmt\If_ | \PhpParser\Node\Stmt\Namespace_ | \PhpParser\Node\Stmt\TryCatch | \PhpParser\Node\Stmt\While_
14+
1115
# requires exact closure types
1216
checkMissingCallableSignature: true
1317

@@ -30,8 +34,8 @@ parameters:
3034
scanDirectories:
3135
- stubs
3236

33-
scanFiles:
34-
- src/Contract/PhpParser/Node/StmtsAwareInterface.php
37+
# scanFiles:
38+
# - src/Contract/PhpParser/Node/StmtsAwareInterface.php
3539

3640
excludePaths:
3741
- '*tests/*/Fixture/*'
@@ -207,7 +211,7 @@ parameters:
207211
message: '#Function "(class_exists|interface_exists)\(\)" cannot be used/left in the code\: use ReflectionProvider\->has\*\(\) instead#'
208212
path: src/Skipper/SkipCriteriaResolver/SkippedClassResolver.php
209213

210-
- '#(.*?)\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'
214+
# - '#(.*?)\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts#'
211215

212216
# dev rule
213217
- '#Class "Rector\\Utils\\Rector\\MoveAbstractRectorToChildrenRector" is missing @see annotation with test case class reference#'
@@ -328,10 +332,6 @@ parameters:
328332
- identifier: symplify.noConstructorOverride
329333
path: src/StaticTypeMapper/ValueObject/Type/SimpleStaticType.php
330334

331-
-
332-
identifier: symplify.seeAnnotationToTest
333-
path: utils/PHPStan/Rule/PreferDirectIsNameRule.php
334-
335335
-
336336
identifier: arrayValues.list
337337
path: rules/CodingStyle/Application/UseImportsAdder.php
@@ -363,9 +363,6 @@ parameters:
363363
identifier: symplify.multipleClassLikeInFile
364364

365365
# copied from /vendor, to keep as original as possible
366-
-
367-
identifier: symplify.forbiddenNode
368-
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
369366
-
370367
identifier: missingType.iterableValue
371368
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
@@ -381,3 +378,9 @@ parameters:
381378
-
382379
message: '#Property Rector\\PhpParser\\NodeTraverser\\AbstractImmutableNodeTraverser\:\:\$visitors \(list<PhpParser\\NodeVisitor>\) does not accept array<int\|string, PhpParser\\NodeVisitor>#'
383380
path: src/PhpParser/NodeTraverser/AbstractImmutableNodeTraverser.php
381+
382+
# false positive
383+
-
384+
message: '#Method (.*?)refactor\(\) (never returns|should return) (.*?)#'
385+
paths:
386+
- rules/Php70/Rector/If_/IfToSpaceshipRector.php

preload.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ function isPHPStanTestPreloaded(): bool
2626
}
2727

2828
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node.php';
29+
// @todo to be deprecated
2930
require_once __DIR__ . '/src/Contract/PhpParser/Node/StmtsAwareInterface.php';
3031
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/NodeAbstract.php';
3132
require_once __DIR__ . '/vendor/nikic/php-parser/lib/PhpParser/Node/Expr.php';

rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/with_comment.php.inc renamed to rules-tests/CodingStyle/Rector/ClassLike/NewlineBetweenClassLikeStmtsRector/Fixture/class_elements_with_comments.php.inc

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
<?php
22

3-
namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixture;
3+
namespace Rector\Tests\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector\Fixture;
44

5-
class WithComment
5+
final class ClassElementsWithComments
66
{
77
/**
88
* @var string
@@ -30,9 +30,9 @@ class WithComment
3030
-----
3131
<?php
3232

33-
namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixture;
33+
namespace Rector\Tests\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector\Fixture;
3434

35-
class WithComment
35+
final class ClassElementsWithComments
3636
{
3737
/**
3838
* @var string
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector\Fixture;
4+
5+
class SkipAlreadyHasNewline
6+
{
7+
private $property;
8+
9+
private $property2;
10+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector\Fixture;
4+
5+
if (mt_rand(0, 1)) { ?>
6+
<div>
7+
<h1>Hi</h1>
8+
</div>
9+
10+
<?php } else { ?>
11+
<div>
12+
<h1>Bye</h1>
13+
</div>
14+
15+
<?php } ?>
16+
17+
End of file
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Tests\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class NewlineBetweenClassLikeStmtsRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\CodingStyle\Rector\ClassLike\NewlineBetweenClassLikeStmtsRector;
6+
use Rector\Config\RectorConfig;
7+
8+
return RectorConfig::configure()
9+
->withRules([NewlineBetweenClassLikeStmtsRector::class]);

rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/no_new_line.php.inc

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,6 @@ namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixtu
44

55
class NoNewLine
66
{
7-
private $property;
8-
private $property2;
9-
private const VIEW = 'view';
10-
private const ADD = 'add';
117
public function run(array $data)
128
{
139
if (rand(0, 1)) {
@@ -30,14 +26,6 @@ namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixtu
3026

3127
class NoNewLine
3228
{
33-
private $property;
34-
35-
private $property2;
36-
37-
private const VIEW = 'view';
38-
39-
private const ADD = 'add';
40-
4129
public function run(array $data)
4230
{
4331
if (rand(0, 1)) {

rules-tests/CodingStyle/Rector/Stmt/NewlineAfterStatementRector/Fixture/skip_already_has_newline.php.inc

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,8 @@
22

33
namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixture;
44

5-
class SkipAlreadyHasNewline
5+
final class SkipAlreadyHasNewline
66
{
7-
private $property;
8-
9-
private $property2;
10-
117
public function run(array $data)
128
{
139
if (rand(0, 1)) {
@@ -23,5 +19,3 @@ class SkipAlreadyHasNewline
2319
return true;
2420
}
2521
}
26-
27-
?>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\CodingStyle\Rector\Stmt\NewlineAfterStatementRector\Fixture;
4+
5+
final class SkipClassLike
6+
{
7+
public function firstMethod()
8+
{
9+
}
10+
public function secondMethod()
11+
{
12+
}
13+
}

0 commit comments

Comments
 (0)