Skip to content

Commit 8c7656f

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

10 files changed

Lines changed: 427 additions & 0 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+
}

0 commit comments

Comments
 (0)