Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\CallLike\AddNameToBooleanArgumentRector\Fixture;

use Rector\Tests\CodeQuality\Rector\CallLike\AddNameToBooleanArgumentRector\Source\NoNamedArgumentsService;

function (NoNamedArgumentsService $service, string $value): void
{
$service->configure($value, true);
NoNamedArgumentsService::create($value, true);
new NoNamedArgumentsService($value, true);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\CallLike\AddNameToBooleanArgumentRector\Source;

/**
* @no-named-arguments
*/
final class NoNamedArgumentsService
{
public function __construct(string $value, bool $strict)
{
}

public function configure(string $value, bool $strict): void
{
}

public static function create(string $value, bool $strict): self
{
return new self($value, $strict);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\CodeQuality\Rector\CallLike\AddNameToNullArgumentRector\Fixture;

use Rector\Tests\CodeQuality\Rector\CallLike\AddNameToNullArgumentRector\Source\NoNamedArgumentsService;

function (NoNamedArgumentsService $service, string $value): void
{
$service->configure($value, null);
NoNamedArgumentsService::create($value, null);
new NoNamedArgumentsService($value, null);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\CodeQuality\Rector\CallLike\AddNameToNullArgumentRector\Source;

/**
* @no-named-arguments
*/
final class NoNamedArgumentsService
{
public function __construct(string $value, ?string $default)
{
}

public function configure(string $value, ?string $default): void
{
}

public static function create(string $value, ?string $default): self
{
return new self($value, $default);
}
}
8 changes: 6 additions & 2 deletions src/NodeAnalyzer/CallLikeArgumentNameAdder.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Identifier;
use PHPStan\Reflection\ExtendedMethodReflection;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
use PHPStan\Reflection\ParameterReflection;
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
use Rector\PHPStan\ScopeFetcher;
Expand All @@ -36,7 +36,11 @@ public function addNamesToArgs(CallLike $callLike, callable $shouldNameArgValue)
}

$reflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($callLike);
if (! $reflection instanceof FunctionReflection && ! $reflection instanceof MethodReflection) {
if (! $reflection instanceof FunctionReflection && ! $reflection instanceof ExtendedMethodReflection) {
return null;
}

if (! $reflection->acceptsNamedArguments()->yes()) {
return null;
}

Expand Down
Loading