Skip to content

Commit 0e65933

Browse files
committed
[TypeDeclaration] Add PrivateMethodReturnTypeFromStrictNewArrayRector, split private methods from ReturnTypeFromStrictNewArrayRector
1 parent 269af16 commit 0e65933

14 files changed

Lines changed: 443 additions & 12 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;
4+
5+
final class PrivateMethod
6+
{
7+
private function run()
8+
{
9+
$values = [];
10+
11+
return $values;
12+
}
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;
20+
21+
final class PrivateMethod
22+
{
23+
private function run(): array
24+
{
25+
$values = [];
26+
27+
return $values;
28+
}
29+
}
30+
31+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;
4+
5+
final class PrivateMethodListDoc
6+
{
7+
private function run()
8+
{
9+
$values = [];
10+
$values[] = 'item';
11+
12+
return $values;
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;
21+
22+
final class PrivateMethodListDoc
23+
{
24+
/**
25+
* @return list<'item'>
26+
*/
27+
private function run(): array
28+
{
29+
$values = [];
30+
$values[] = 'item';
31+
32+
return $values;
33+
}
34+
}
35+
36+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;
4+
5+
final class SkipProtectedMethod
6+
{
7+
protected function run()
8+
{
9+
$values = [];
10+
11+
return $values;
12+
}
13+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
3+
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector\Fixture;
4+
5+
final class SkipPublicMethod
6+
{
7+
public function run()
8+
{
9+
$values = [];
10+
11+
return $values;
12+
}
13+
}
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\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class PrivateMethodReturnTypeFromStrictNewArrayRectorTest 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+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\TypeDeclaration\Rector\ClassMethod\PrivateMethodReturnTypeFromStrictNewArrayRector;
7+
8+
return RectorConfig::configure()
9+
->withRules([PrivateMethodReturnTypeFromStrictNewArrayRector::class]);
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\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector\Fixture;
4+
5+
final class SkipPrivateMethod
6+
{
7+
private function run()
8+
{
9+
$values = [];
10+
11+
return $values;
12+
}
13+
}

‎rules/CodeQuality/Rector/If_/ExplicitBoolCompareRector.php‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -276,11 +276,8 @@ private function resolveFloat(bool $isNegated, Expr $expr): Identical|NotIdentic
276276
return new NotIdentical($expr, $float);
277277
}
278278

279-
private function resolveNullable(
280-
bool $isNegated,
281-
Expr $expr,
282-
ObjectType $objectType
283-
): BooleanNot|Instanceof_ {
279+
private function resolveNullable(bool $isNegated, Expr $expr, ObjectType $objectType): BooleanNot|Instanceof_
280+
{
284281
$fullyQualified = new FullyQualified($objectType->getClassName());
285282
$instanceof = new Instanceof_($expr, $fullyQualified);
286283

‎rules/Naming/Matcher/VariableAndCallAssignMatcher.php‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ public function match(Assign $assign, ClassMethod|Closure|Function_ $functionLik
4141

4242
$isVariableFoundInCallArgs = (bool) $this->betterNodeFinder->findFirst(
4343
$call->isFirstClassCallable() ? [] : $call->getArgs(),
44-
fn (Node $subNode): bool => $subNode instanceof Variable && $this->nodeNameResolver->isName($subNode, $variableName)
44+
fn (Node $subNode): bool => $subNode instanceof Variable && $this->nodeNameResolver->isName(
45+
$subNode,
46+
$variableName
47+
)
4548
);
4649

4750
if ($isVariableFoundInCallArgs) {

‎rules/Privatization/NodeManipulator/VisibilityManipulator.php‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,8 @@ private function removeVisibility(ClassMethod|Property|ClassConst|Param $node):
188188
/**
189189
* @api
190190
*/
191-
private function addVisibilityFlag(
192-
Class_|ClassMethod|Property|ClassConst|Param $node,
193-
int $visibility
194-
): void {
191+
private function addVisibilityFlag(Class_|ClassMethod|Property|ClassConst|Param $node, int $visibility): void
192+
{
195193
$node->flags |= $visibility;
196194
}
197195

0 commit comments

Comments
 (0)