[tests] fix rectors custom naming convention (#188)

This commit is contained in:
Tomas Votruba 2021-06-09 14:56:02 +02:00 committed by GitHub
parent db1e4161af
commit e50ad80290
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 17 deletions

View File

@ -14,7 +14,9 @@ Let's say we want to **change method calls from `set*` to `change*`**.
Create a class that extends [`Rector\Core\Rector\AbstractRector`](/src/Rector/AbstractRector.php). It will inherit useful methods e.g. to check node type and name. See the source (or type `$this->` in an IDE) for a list of available methods.
```php
namespace Utils\Rector;
declare(strict_types=1);
namespace Utils\Rector\Rector;
use Nette\Utils\Strings;
use PhpParser\Node;
@ -79,8 +81,17 @@ final class MyFirstRector extends AbstractRector
This is how the file structure should look like:
```bash
/src/YourCode.php
/utils/Rector/MyFirstRector.php
/src/
/YourCode.php
/utils
/rector
/src
/Rector
MyFirstRector.php
/tests
/Rector
/MyFirstRector
MyFirstRectorTest.php
rector.php
composer.json
```
@ -96,7 +107,8 @@ We also need to load Rector rules in `composer.json`:
},
"autoload-dev": {
"psr-4": {
"Utils\\": "utils"
"Utils\\Rector\\": "utils/rector/src",
"Utils\\Rector\\Tests\\": "utils/rector/tests"
}
}
}
@ -117,7 +129,7 @@ composer dump-autoload
declare(strict_types=1);
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
use Utils\Rector\MyFirstRector;
use Utils\Rector\Rector\MyFirstRector;
return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

View File

@ -186,7 +186,11 @@ CODE_SAMPLE
* as to invoke it only once and avoid potential bugs,
* such as a method executing some side-effect
*/
private function createVariableFromNonVariable(Array_ $array, ArrayItem $arrayItem, int | string $position): Variable
private function createVariableFromNonVariable(
Array_ $array,
ArrayItem $arrayItem,
int | string $position
): Variable
{
/** @var Scope $nodeScope */
$nodeScope = $array->getAttribute(AttributeKey::SCOPE);

View File

@ -199,8 +199,7 @@ CODE_SAMPLE
Param $param,
string $paramVarName,
string $desiredPropertyName
): void
{
): void {
$paramTagValueNode = $phpDocInfo->getParamTagValueNodeByName($paramVarName);
if (! $paramTagValueNode instanceof ParamTagValueNode) {

View File

@ -5,13 +5,8 @@ declare(strict_types=1);
namespace Rector\Php74\Rector\Property;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Name;
use PhpParser\Node\NullableType;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\UnionType as PhpParserUnionType;
use PHPStan\Reflection\ReflectionProvider;
@ -23,10 +18,8 @@ use PHPStan\Type\UnionType;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Core\NodeAnalyzer\PropertyFetchAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\MethodName;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\DeadCode\PhpDoc\TagRemover\VarTagRemover;
use Rector\NodeTypeResolver\Node\AttributeKey;
use Rector\PHPStanStaticTypeMapper\DoctrineTypeAnalyzer;
use Rector\PHPStanStaticTypeMapper\ValueObject\TypeKind;
use Rector\TypeDeclaration\TypeInferer\PropertyTypeInferer;

View File

@ -172,8 +172,7 @@ final class PropertyFetchAnalyzer
array $stmts,
string $propertyName,
string $kindPropertyFetch
): bool
{
): bool {
foreach ($params as $param) {
$paramVariable = $param->var;
$isAssignWithParamVarName = $this->betterNodeFinder->findFirst($stmts, function (Node $node) use (