Skip to content

Commit

Permalink
[CodingStyle] Remove YieldClassMethodToArrayClassMethodRector, rather…
Browse files Browse the repository at this point in the history
… PHPStorm job (#576)

Co-authored-by: GitHub Action <action@github.com>
  • Loading branch information
TomasVotruba and actions-user committed Aug 2, 2021
1 parent 00fb10f commit b348090
Show file tree
Hide file tree
Showing 62 changed files with 344 additions and 625 deletions.
55 changes: 9 additions & 46 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 476 Rules Overview
# 475 Rules Overview

<br>

Expand All @@ -14,7 +14,7 @@

- [CodeQualityStrict](#codequalitystrict) (1)

- [CodingStyle](#codingstyle) (39)
- [CodingStyle](#codingstyle) (38)

- [Composer](#composer) (6)

Expand Down Expand Up @@ -2375,7 +2375,7 @@ return static function (ContainerConfigurator $containerConfigurator): void {
$services->set(ReturnArrayClassMethodToYieldRector::class)
->call('configure', [[
ReturnArrayClassMethodToYieldRector::METHODS_TO_YIELDS => ValueObjectInliner::inline([
new ReturnArrayClassMethodToYield('EventSubscriberInterface', 'getSubscribedEvents'),
new ReturnArrayClassMethodToYield('PHPUnit\Framework\TestCase', '*provide*'),
]),
]]);
};
Expand All @@ -2384,12 +2384,14 @@ return static function (ContainerConfigurator $containerConfigurator): void {

```diff
class SomeEventSubscriber implements EventSubscriberInterface
use PHPUnit\Framework\TestCase;

final class SomeTest implements TestCase
{
public static function getSubscribedEvents()
public static function provideData()
{
- return ['event' => 'callback'];
+ yield 'event' => 'callback';
- return [['some text']];
+ yield ['some text'];
}
}
```
Expand Down Expand Up @@ -2670,45 +2672,6 @@ Wrap encapsed variables in curly braces

<br>

### YieldClassMethodToArrayClassMethodRector

Turns yield return to array return in specific type and method

:wrench: **configure it!**

- class: [`Rector\CodingStyle\Rector\ClassMethod\YieldClassMethodToArrayClassMethodRector`](../rules/CodingStyle/Rector/ClassMethod/YieldClassMethodToArrayClassMethodRector.php)

```php
use Rector\CodingStyle\Rector\ClassMethod\YieldClassMethodToArrayClassMethodRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;

return static function (ContainerConfigurator $containerConfigurator): void {
$services = $containerConfigurator->services();

$services->set(YieldClassMethodToArrayClassMethodRector::class)
->call('configure', [[
YieldClassMethodToArrayClassMethodRector::METHODS_BY_TYPE => [
'EventSubscriberInterface' => ['getSubscribedEvents'],

], ]]);
};
```


```diff
class SomeEventSubscriber implements EventSubscriberInterface
{
public static function getSubscribedEvents()
{
- yield 'event' => 'callback';
+ return ['event' => 'callback'];
}
}
```

<br>

## Composer

### AddPackageToRequireComposerRector
Expand Down
32 changes: 16 additions & 16 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,16 @@
"symfony/http-kernel": "^5.3",
"symfony/process": "^5.3",
"symfony/yaml": "^5.3",
"symplify/astral": "^9.4.14",
"symplify/autowire-array-parameter": "^9.4.14",
"symplify/composer-json-manipulator": "^9.4.14",
"symplify/console-color-diff": "^9.4.14",
"symplify/package-builder": "^9.4.14",
"symplify/rule-doc-generator-contracts": "^9.4.14",
"symplify/simple-php-doc-parser": "^9.4.14",
"symplify/skipper": "^9.4.14",
"symplify/smart-file-system": "^9.4.14",
"symplify/symfony-php-config": "^9.4.14",
"symplify/astral": "^9.4.24",
"symplify/autowire-array-parameter": "^9.4.24",
"symplify/composer-json-manipulator": "^9.4.24",
"symplify/console-color-diff": "^9.4.24",
"symplify/package-builder": "^9.4.24",
"symplify/rule-doc-generator-contracts": "^9.4.24",
"symplify/simple-php-doc-parser": "^9.4.24",
"symplify/skipper": "^9.4.24",
"symplify/smart-file-system": "^9.4.24",
"symplify/symfony-php-config": "^9.4.24",
"tracy/tracy": "^2.8",
"webmozart/assert": "^1.10"
},
Expand All @@ -58,13 +58,13 @@
"phpunit/phpunit": "^9.5",
"rector/phpstan-rules": "^0.3.3",
"rector/rector-generator": "^0.3",
"symplify/coding-standard": "^9.4.14",
"symplify/easy-ci": "^9.4.14",
"symplify/coding-standard": "^9.4.24",
"symplify/easy-ci": "^9.4.23",
"symplify/easy-coding-standard": "^9.4.7",
"symplify/easy-testing": "dev-main#049d83e as 9.5.x-dev",
"symplify/phpstan-extensions": "^9.4.14",
"symplify/phpstan-rules": "^9.4.14",
"symplify/rule-doc-generator": "^9.4.14",
"symplify/easy-testing": "^9.4.24",
"symplify/phpstan-extensions": "^9.4.24",
"symplify/phpstan-rules": "^9.4.24",
"symplify/rule-doc-generator": "^9.4.24",
"timeweb/phpstan-enum": "^2.3"
},
"replace": {
Expand Down
2 changes: 1 addition & 1 deletion config/set/code-quality-strict.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
declare(strict_types=1);

use Rector\CodeQuality\Rector\Identical\FlipTypeControlToUseExclusiveTypeRector;
use Rector\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector;
use Rector\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector;
use Rector\CodingStyle\Rector\FuncCall\CountArrayToEmptyArrayComparisonRector;
use Rector\CodingStyle\Rector\MethodCall\UseMessageVariableForSprintfInSymfonyStyleRector;
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@
use PhpParser\Node;
use PHPStan\Type\Type;

/**
* @template TNode as Node
*/
interface NodeTypeResolverInterface
{
/**
* @return array<class-string<Node>>
* @return array<class-string<TNode>>
*/
public function getNodeClasses(): array;

/**
* @param TNode $node
*/
public function resolve(Node $node): Type;
}
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ public function getNodeClasses(): array
}

/**
* @param Property $propertyNode
* @param Property $node
*/
public function resolve(Node $propertyNode): Type
public function resolve(Node $node): Type
{
// fake property to local PropertyFetch → PHPStan understands that
$propertyFetch = new PropertyFetch(new Variable('this'), (string) $propertyNode->props[0]->name);
$propertyFetch->setAttribute(AttributeKey::SCOPE, $propertyNode->getAttribute(AttributeKey::SCOPE));
$propertyFetch = new PropertyFetch(new Variable('this'), (string) $node->props[0]->name);
$propertyFetch->setAttribute(AttributeKey::SCOPE, $node->getAttribute(AttributeKey::SCOPE));

return $this->nodeTypeResolver->resolve($propertyFetch);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ public function getNodeClasses(): array
}

/**
* @param Trait_ $traitNode
* @param Trait_ $node
*/
public function resolve(Node $traitNode): Type
public function resolve(Node $node): Type
{
$traitName = (string) $traitNode->namespacedName;
$traitName = (string) $node->namespacedName;
if (! $this->reflectionProvider->hasClass($traitName)) {
return new MixedType();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,5 +31,5 @@ public function mapToPHPStanPhpDocTypeNode(Type $type, TypeKind $typeKind): Type
* @param T $type
* @return Name|NullableType|UnionType|null
*/
public function mapToPhpParserNode(Type $type, TypeKind $typeTypeKind): ?Node;
public function mapToPhpParserNode(Type $type, TypeKind $typeKind): ?Node;
}
11 changes: 10 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,6 @@ parameters:
paths:
- rules/Php70/EregToPcreTransformer.php
- packages/NodeTypeResolver/NodeTypeResolver.php
- rules/CodeQualityStrict/Rector/Variable/MoveVariableDeclarationNearReferenceRector.php
- rules/Php80/Rector/If_/NullsafeOperatorRector.php
- rules/Renaming/NodeManipulator/ClassRenamer.php
- rules/DowngradePhp72/Rector/FuncCall/DowngradePregUnmatchedAsNullConstantRector.php
Expand Down Expand Up @@ -536,3 +535,13 @@ parameters:
message: '#"@\\var_export\(new \\Rector\\Caching\\ValueObject\\CacheItem\(\$variableKey, \$data\), true\)" is forbidden to use#'
paths:
- packages/Caching/ValueObject/Storage/FileCacheStorage.php

-
message: '#Arguments names conflicts with parent class method\: "\$(.*?)" should be "\$(.*?)"\. This will break named arguments#'
paths:
- src/PhpParser/Printer/BetterStandardPrinter.php
- packages/BetterPhpDocParser/PhpDocParser/BetterPhpDocParser.php
- packages/BetterPhpDocParser/PhpDocParser/BetterTypeParser.php

# resolve later
- '#Variables "\$(.*?)" are overridden\. This can lead to unwanted bugs, please pick a different name to avoid it#'
11 changes: 10 additions & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@

use PHPUnit\Framework\TestCase;
use Rector\CodingStyle\Enum\PreferenceSelfThis;
use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector;
use Rector\CodingStyle\Rector\MethodCall\PreferThisOrSelfMethodCallRector;
use Rector\CodingStyle\Rector\String_\SplitStringClassConstantToClassConstFetchRector;
use Rector\CodingStyle\ValueObject\ReturnArrayClassMethodToYield;
use Rector\Core\Configuration\Option;
use Rector\Core\Rector\AbstractRector;
use Rector\Nette\Set\NetteSetList;
Expand Down Expand Up @@ -41,19 +43,26 @@
]);

$services = $containerConfigurator->services();

$services->set(InferParamFromClassMethodReturnRector::class)
->call('configure', [[
InferParamFromClassMethodReturnRector::INFER_PARAMS_FROM_CLASS_METHOD_RETURNS => $configuration,
]]);

// phpunit
$services->set(PreferThisOrSelfMethodCallRector::class)
->call('configure', [[
PreferThisOrSelfMethodCallRector::TYPE_TO_PREFERENCE => [
TestCase::class => ValueObjectInliner::inline(PreferenceSelfThis::PREFER_THIS()),
],
]]);

$services->set(ReturnArrayClassMethodToYieldRector::class)
->call('configure', [[
ReturnArrayClassMethodToYieldRector::METHODS_TO_YIELDS => ValueObjectInliner::inline([
new ReturnArrayClassMethodToYield('PHPUnit\Framework\TestCase', '*provide*'),
]),
]]);

$parameters = $containerConfigurator->parameters();

$parameters->set(Option::PATHS, [
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class Fixture
{
Expand All @@ -17,7 +17,7 @@ class Fixture
-----
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class Fixture
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class FixtureUsedOnlyAfterIf
{
Expand All @@ -18,7 +18,7 @@ class FixtureUsedOnlyAfterIf
-----
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class FixtureUsedOnlyAfterIf
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

function variableInClosure()
{
Expand All @@ -16,7 +16,7 @@ function variableInClosure()
-----
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

function variableInClosure()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

function variableInClosureWithReturn()
{
Expand All @@ -16,7 +16,7 @@ function variableInClosureWithReturn()
-----
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

function variableInClosureWithReturn()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

function variableWithMultipleUsages()
{
Expand All @@ -15,7 +15,7 @@ function variableWithMultipleUsages()
-----
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

function variableWithMultipleUsages()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class SkipArrayDimFetchNext
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class SkipArrayDimFetchNextAsKey
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

final class SkipAssignExprArrayDimFetch
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class SkipDeclaredInExtraParentPrevious
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class SkipExprReused
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace Rector\Tests\CodeQualityStrict\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;
namespace Rector\Tests\CodeQuality\Rector\Variable\MoveVariableDeclarationNearReferenceRector\Fixture;

class SkipExprVarUsed
{
Expand Down
Loading

0 comments on commit b348090

Please sign in to comment.