-
-
Notifications
You must be signed in to change notification settings - Fork 336
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[TypeDeclaration] Move Rector Enterprise TypeDeclaration rules here (#…
…3125) * [TypeDeclaration] Move Rector Enterprise TypeDeclaration rules here * [ci-review] Rector Rectify * fix duplicate register * remove unnecesary import config * fix doc * fix config * fix config * fix doc * Fix @see * Fix space * Remove duplicate register * Fix phpstan * Fix phpstan * [ci-review] Rector Rectify * rollback array check * rollback array check * fix union * [ci-review] Rector Rectify * [ci-review] Rector Rectify Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
ecec40c
commit 2b35d2e
Showing
62 changed files
with
2,105 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...Rector/ClassMethod/ReturnTypeFromReturnDirectArrayRector/Fixture/add_return_array.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector\Fixture; | ||
|
||
final class AddReturnArray | ||
{ | ||
public function getArray() | ||
{ | ||
return [1, 2, 3]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector\Fixture; | ||
|
||
final class AddReturnArray | ||
{ | ||
public function getArray(): array | ||
{ | ||
return [1, 2, 3]; | ||
} | ||
} | ||
|
||
?> |
31 changes: 31 additions & 0 deletions
31
...hod/ReturnTypeFromReturnDirectArrayRector/Fixture/add_return_array_arrow_function.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector\Fixture; | ||
|
||
final class AddReturnArrayArrowFunction | ||
{ | ||
public function getArray() | ||
{ | ||
$items = fn () => [1, 2, 3]; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector\Fixture; | ||
|
||
final class AddReturnArrayArrowFunction | ||
{ | ||
public function getArray() | ||
{ | ||
$items = fn (): array => [1, 2, 3]; | ||
} | ||
} | ||
|
||
?> |
13 changes: 13 additions & 0 deletions
13
...ssMethod/ReturnTypeFromReturnDirectArrayRector/Fixture/skip_undirect_array_return.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector\Fixture; | ||
|
||
final class SkipUndirectArrayReturn | ||
{ | ||
public function getArray(array $items) | ||
{ | ||
return $items; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...ethod/ReturnTypeFromReturnDirectArrayRector/ReturnTypeFromReturnDirectArrayRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class ReturnTypeFromReturnDirectArrayRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...ation/Rector/ClassMethod/ReturnTypeFromReturnDirectArrayRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnDirectArrayRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(ReturnTypeFromReturnDirectArrayRector::class); | ||
}; |
24 changes: 24 additions & 0 deletions
24
...ctor/ClassMethod/ReturnTypeFromReturnNewRector/Fixture/skip_child_class_has_typed.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromReturnNewRector\Fixture; | ||
|
||
use stdClass; | ||
|
||
class SkipChildClassHasTyped | ||
{ | ||
public function action() | ||
{ | ||
return new stdClass(); | ||
} | ||
} | ||
|
||
class SomeChild extends SkipChildClassHasTyped | ||
{ | ||
public function run(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
} |
27 changes: 27 additions & 0 deletions
27
...ethod/ReturnTypeFromStrictBoolReturnExprRector/Fixture/skip_child_class_has_typed.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictBoolReturnExprRector\Fixture; | ||
|
||
class SkipChildClassHasTyped | ||
{ | ||
public function run() | ||
{ | ||
return $this->first() && true; | ||
} | ||
|
||
public function first() | ||
{ | ||
return true; | ||
} | ||
} | ||
|
||
class SomeChild extends SkipChildClassHasTyped | ||
{ | ||
public function run(): string | ||
{ | ||
return 'test'; | ||
} | ||
|
||
} |
22 changes: 22 additions & 0 deletions
22
...ethod/ReturnTypeFromStrictConstantReturnRector/Fixture/skip_child_class_has_typed.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector\Fixture; | ||
|
||
class SkipChildClassHasTyped | ||
{ | ||
public const NAME = 'name'; | ||
|
||
public function run() | ||
{ | ||
return self::NAME; | ||
} | ||
} | ||
|
||
class SomeChild extends SkipChildClassHasTyped | ||
{ | ||
public function run(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
} |
15 changes: 15 additions & 0 deletions
15
...n/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector/Fixture/skip_nested.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector\Fixture; | ||
|
||
class SkipNested | ||
{ | ||
public const NAME = 'name'; | ||
|
||
public function run() | ||
{ | ||
if (mt_rand(1, 0)) { | ||
return self::NAME; | ||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
...on/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector/Fixture/some_class.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public const NAME = 'name'; | ||
|
||
public function run() | ||
{ | ||
return self::NAME; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector\Fixture; | ||
|
||
class SomeClass | ||
{ | ||
public const NAME = 'name'; | ||
|
||
public function run(): string | ||
{ | ||
return self::NAME; | ||
} | ||
} | ||
|
||
?> |
29 changes: 29 additions & 0 deletions
29
...ReturnTypeFromStrictConstantReturnRector/ReturnTypeFromStrictConstantReturnRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
|
||
final class ReturnTypeFromStrictConstantReturnRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(string $filePath): void | ||
{ | ||
$this->doTestFile($filePath); | ||
} | ||
|
||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...on/Rector/ClassMethod/ReturnTypeFromStrictConstantReturnRector/config/configured_rule.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Config\RectorConfig; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictConstantReturnRector; | ||
|
||
return static function (RectorConfig $rectorConfig): void { | ||
$rectorConfig->rule(ReturnTypeFromStrictConstantReturnRector::class); | ||
}; |
20 changes: 20 additions & 0 deletions
20
...assMethod/ReturnTypeFromStrictNativeCallRector/Fixture/skip_child_class_has_typed.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNativeCallRector\Fixture; | ||
|
||
class SkipChildClassHasTyped | ||
{ | ||
public function run() | ||
{ | ||
return strlen('value'); | ||
} | ||
} | ||
|
||
class SomeChild extends SkipChildClassHasTyped | ||
{ | ||
public function run(): string | ||
{ | ||
return 'test'; | ||
} | ||
|
||
} |
24 changes: 24 additions & 0 deletions
24
...ClassMethod/ReturnTypeFromStrictNewArrayRector/Fixture/skip_child_class_has_typed.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictNewArrayRector\Fixture; | ||
|
||
class SkipChildClassHasTyped | ||
{ | ||
public function run() | ||
{ | ||
$values = []; | ||
|
||
return $values; | ||
} | ||
} | ||
|
||
class SomeChild extends SkipChildClassHasTyped | ||
{ | ||
public function run(): string | ||
{ | ||
return 'test'; | ||
} | ||
|
||
} |
Oops, something went wrong.