-
-
Notifications
You must be signed in to change notification settings - Fork 335
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode][TypeDeclaration] Handle Nullable Param on RemoveUnusedPriv…
…ateMethodParameterRector+RemoveUnreachableStatementRector+AddArrayParamDocTypeRector (#1216) * [DeadCode][TypeDeclaration] Handle RemoveUnusedPrivateMethodParameterRector+RemoveUnreachableStatementRector+AddArrayParamDocTypeRector * Fixed 🎉 * rename fixture * check with namespacedName attribute * [ci-review] Rector Rectify * move under NullableType * Trigger notification Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
19d01b9
commit f775b6e
Showing
4 changed files
with
106 additions
and
0 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
49 changes: 49 additions & 0 deletions
49
...ullableParamNamespaced/Fixture/do_not_add_short_fqcn_class_name_docblock_nullable.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,49 @@ | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\NullableParamNamespaced\Fixture; | ||
|
||
use PhpParser\Node\Stmt\ClassLike; | ||
|
||
class DoNotAddShortFQCNClassNameDocblockNullable | ||
{ | ||
public function run(?ClassLike $classLike): bool | ||
{ | ||
if (! $classLike instanceof ClassLike) { | ||
return false; | ||
} | ||
|
||
return $this->callPrivateMethod($classLike, true); | ||
} | ||
|
||
private function callPrivateMethod(ClassLike $classLike, bool $value) | ||
{ | ||
return $classLike->getMethods() !== []; | ||
} | ||
} | ||
|
||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Core\Tests\Issues\NullableParamNamespaced\Fixture; | ||
|
||
use PhpParser\Node\Stmt\ClassLike; | ||
|
||
class DoNotAddShortFQCNClassNameDocblockNullable | ||
{ | ||
public function run(?ClassLike $classLike): bool | ||
{ | ||
if (! $classLike instanceof ClassLike) { | ||
return false; | ||
} | ||
|
||
return $this->callPrivateMethod($classLike, true); | ||
} | ||
|
||
private function callPrivateMethod(ClassLike $classLike) | ||
{ | ||
return $classLike->getMethods() !== []; | ||
} | ||
} | ||
|
||
?> |
33 changes: 33 additions & 0 deletions
33
tests/Issues/NullableParamNamespaced/NullableParamNamespacedTest.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,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Core\Tests\Issues\NullableParamNamespaced; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class NullableParamNamespacedTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configured_rule.php'; | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
tests/Issues/NullableParamNamespaced/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,19 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
use Rector\Core\Configuration\Option; | ||
use Rector\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodParameterRector; | ||
use Rector\DeadCode\Rector\Stmt\RemoveUnreachableStatementRector; | ||
use Rector\TypeDeclaration\Rector\ClassMethod\AddArrayParamDocTypeRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(AddArrayParamDocTypeRector::class); | ||
$services->set(RemoveUnusedPrivateMethodParameterRector::class); | ||
$services->set(RemoveUnreachableStatementRector::class); | ||
|
||
$parameters = $containerConfigurator->parameters(); | ||
$parameters->set(Option::AUTO_IMPORT_NAMES, true); | ||
}; |