[Naming] Skip return without type and with args

This commit is contained in:
TomasVotruba 2020-07-19 15:47:23 +02:00
parent fc347413f3
commit 133683dc3d
5 changed files with 26 additions and 4 deletions

View File

@ -21,7 +21,8 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$parameters = $containerConfigurator->parameters();
$parameters->set(Option::SETS, [
'coding-style', 'code-quality', 'dead-code', 'nette-utils-code-quality', 'solid', 'privatization', 'naming',
// @todo use constants here, so we don't have to google the strings that can be used here
'coding-style', 'code-quality', 'dead-code', 'nette-utils-code-quality', 'solid', 'privatization', 'naming', 'decomplex',
]);
$parameters->set(Option::PATHS, [

View File

@ -3,7 +3,7 @@
declare(strict_types=1);
use Rector\Core\Configuration\Option;
use Rector\Decomplex\Rector\MethodCall\UseMessageVariableForSprintfInSymfonyStyleRector;
use Rector\Naming\Rector\Assign\RenameVariableToMatchGetMethodNameRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
return static function (ContainerConfigurator $containerConfigurator): void {
@ -11,7 +11,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();
$services->set(UseMessageVariableForSprintfInSymfonyStyleRector::class);
$services->set(RenameVariableToMatchGetMethodNameRector::class);
$parameters = $containerConfigurator->parameters();

View File

@ -181,8 +181,13 @@ final class ExpectedNameResolver
return $expectedName;
}
// call with args can return different value, so skip there if not sure about the type
if (count($call->args) > 0) {
return null;
}
// @see https://regex101.com/r/hnU5pm/2/
$matches = Strings::match($name, '#^get(([A-Z]).+)#');
$matches = Strings::match($name, '#^get([A-Z].+)#');
if ($matches === null) {
return null;
}

View File

@ -105,6 +105,7 @@ PHP
}
$newName = $this->expectedNameResolver->resolveForGetCallExpr($node->expr);
if ($newName === null || $this->isName($node, $newName)) {
return null;
}

View File

@ -0,0 +1,15 @@
<?php
namespace Rector\Naming\Tests\Rector\Assign\RenameVariableToMatchGetMethodNameRector\Fixture;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\NodeTypeResolver\Node\AttributeKey;
class SkipAttributeUseCase
{
public function readMethodAnnotation(ClassMethod $classMethod)
{
/** @var string $className */
$className = $classMethod->getAttribute(AttributeKey::CLASS_NAME);
}
}