-
-
Notifications
You must be signed in to change notification settings - Fork 338
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Fix array callable with constructor args (#5770)
* run fix-cs * [DeadCode] Skip Array Callable dynamic method while defining a constructor without default args on RemoveUnusedPrivateMethodRector * use hasNativeMethod (get information about native methods)
- Loading branch information
Showing
5 changed files
with
100 additions
and
8 deletions.
There are no files selected for viewing
27 changes: 27 additions & 0 deletions
27
...RemoveUnusedPrivateMethodRector/Fixture/skip_array_callables_fqn_with_constructor.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 | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector\Fixture; | ||
|
||
final class SkipArrayCallablesFqnWithConstuctor | ||
{ | ||
private $args; | ||
|
||
public function __construct(...$args) | ||
{ | ||
$this->args = $args; | ||
} | ||
|
||
public function run() | ||
{ | ||
$array = [3, 2, 1]; | ||
|
||
usort($array, [SkipArrayCallablesFqnWithConstuctor::class, 'sort']); | ||
|
||
return $array; | ||
} | ||
|
||
private function sort($a, $b) | ||
{ | ||
return $a <=> $b; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...emoveUnusedPrivateMethodRector/Fixture/skip_array_callables_self_with_constructor.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 | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector\Fixture; | ||
|
||
final class SkipArrayCallablesSelfWithConstructor | ||
{ | ||
private $args; | ||
|
||
public function __construct(...$args) | ||
{ | ||
$this->args = $args; | ||
} | ||
|
||
public function run() | ||
{ | ||
$array = [3, 2, 1]; | ||
|
||
usort($array, [self::class, 'sort']); | ||
|
||
return $array; | ||
} | ||
|
||
private function sort($a, $b) | ||
{ | ||
return $a <=> $b; | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...oveUnusedPrivateMethodRector/Fixture/skip_array_callables_static_with_constructor.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 | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUnusedPrivateMethodRector\Fixture; | ||
|
||
final class SkipArrayCallablesStaticWithConstructor | ||
{ | ||
private $args; | ||
|
||
public function __construct(...$args) | ||
{ | ||
$this->args = $args; | ||
} | ||
|
||
public function run() | ||
{ | ||
$array = [3, 2, 1]; | ||
|
||
usort($array, [static::class, 'sort']); | ||
|
||
return $array; | ||
} | ||
|
||
private function sort($a, $b) | ||
{ | ||
return $a <=> $b; | ||
} | ||
} |
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
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