Skip to content

Commit

Permalink
[tests] fix rectors custom naming convention (#188)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Jun 9, 2021
1 parent db1e416 commit e50ad80
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 17 deletions.
22 changes: 17 additions & 5 deletions build/target-repository/docs/create_own_rule.md
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
```
Expand All @@ -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"
}
}
}
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ private function createArrayMerge(Array_ $array, array $items): FuncCall
* 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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,8 +199,7 @@ private function renameParamDoc(
Param $param,
string $paramVarName,
string $desiredPropertyName
): void
{
): void {
$paramTagValueNode = $phpDocInfo->getParamTagValueNodeByName($paramVarName);

if (! $paramTagValueNode instanceof ParamTagValueNode) {
Expand Down
7 changes: 0 additions & 7 deletions rules/Php74/Rector/Property/TypedPropertyRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,8 @@
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;
Expand All @@ -23,10 +18,8 @@
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;
Expand Down
3 changes: 1 addition & 2 deletions src/NodeAnalyzer/PropertyFetchAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -172,8 +172,7 @@ private function isParamFilledStmts(
array $stmts,
string $propertyName,
string $kindPropertyFetch
): bool
{
): bool {
foreach ($params as $param) {
$paramVariable = $param->var;
$isAssignWithParamVarName = $this->betterNodeFinder->findFirst($stmts, function (Node $node) use (
Expand Down

0 comments on commit e50ad80

Please sign in to comment.