Skip to content

Commit

Permalink
[CodeQuality] Add StaticCall support on OptionalParametersAfterRequir…
Browse files Browse the repository at this point in the history
…edRector (#2817)

* update_params_order_of_static_method_call.php.inc

* Update rules-tests/CodeQuality/Rector/ClassMethod/OptionalParametersAfterRequiredRector/Fixture/update_params_order_of_static_method_call.php.inc

Co-authored-by: Abdul Malik Ikhsan <samsonasik@gmail.com>

* Closes #2816

Co-authored-by: Alejo Moreira <alejo.moreira@729solutions.com>
Co-authored-by: Tomas Votruba <tomas.vot@gmail.com>
  • Loading branch information
3 people committed Aug 22, 2022
1 parent a4799d9 commit 55d788a
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;

final class WebUtil
{
public static function radioList($name, $items = [], $selected, $class = "", $groupingCount = 0, $groupingClass = "", $required = false)
{

}
}

WebUtil::radioList("inPersonOrVirtual", $inPersonOrVirtualItems, $selected, "", 1, "col-sm-3 margin-bottom-10");

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\ClassMethod\OptionalParametersAfterRequiredRector\Fixture;

final class WebUtil
{
public static function radioList($name, $selected, $items = [], $class = "", $groupingCount = 0, $groupingClass = "", $required = false)
{

}
}

WebUtil::radioList("inPersonOrVirtual", $selected, $inPersonOrVirtualItems, "", 1, "col-sm-3 margin-bottom-10");

?>
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpParser\Node;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\MethodReflection;
Expand Down Expand Up @@ -67,11 +68,11 @@ public function run($required, $optional = 1)
*/
public function getNodeTypes(): array
{
return [ClassMethod::class, New_::class, MethodCall::class];
return [ClassMethod::class, New_::class, MethodCall::class, StaticCall::class];
}

/**
* @param ClassMethod|New_|MethodCall $node
* @param ClassMethod|New_|MethodCall|StaticCall $node
*/
public function refactor(Node $node): ?Node
{
Expand Down Expand Up @@ -131,7 +132,7 @@ private function refactorNew(New_ $new): ?New_
return $new;
}

private function refactorMethodCall(MethodCall $methodCall): ?MethodCall
private function refactorMethodCall(MethodCall|StaticCall $methodCall): MethodCall|StaticCall|null
{
$methodReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($methodCall);
if (! $methodReflection instanceof MethodReflection) {
Expand Down Expand Up @@ -161,7 +162,7 @@ private function refactorMethodCall(MethodCall $methodCall): ?MethodCall
*/
private function resolveExpectedArgParamOrderIfDifferent(
MethodReflection $methodReflection,
New_|MethodCall|ClassMethod $node
New_|MethodCall|ClassMethod|StaticCall $node
): ?array {
if ($this->vendorLocationDetector->detectMethodReflection($methodReflection)) {
return null;
Expand Down

0 comments on commit 55d788a

Please sign in to comment.