Skip to content

Commit

Permalink
Remove ReturnArrayClassMethodToYieldRector, add to PHPUnit Rector (#4213
Browse files Browse the repository at this point in the history
)
  • Loading branch information
TomasVotruba committed Jun 13, 2023
1 parent fd3c90c commit b4eb417
Show file tree
Hide file tree
Showing 24 changed files with 19 additions and 743 deletions.
88 changes: 2 additions & 86 deletions build/target-repository/docs/rector_rules_overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# 370 Rules Overview
# 368 Rules Overview

<br>

Expand All @@ -8,7 +8,7 @@

- [CodeQuality](#codequality) (71)

- [CodingStyle](#codingstyle) (34)
- [CodingStyle](#codingstyle) (32)

- [DeadCode](#deadcode) (43)

Expand Down Expand Up @@ -2004,47 +2004,6 @@ Use ++$value or --$value instead of `$value++` or `$value--`

<br>

### PreferThisOrSelfMethodCallRector

Changes `$this->...` and static:: to self:: or vise versa for given types

:wrench: **configure it!**

- class: [`Rector\CodingStyle\Rector\MethodCall\PreferThisOrSelfMethodCallRector`](../rules/CodingStyle/Rector/MethodCall/PreferThisOrSelfMethodCallRector.php)

```php
<?php

declare(strict_types=1);

use PHPUnit\Framework\TestCase;
use Rector\CodingStyle\Rector\MethodCall\PreferThisOrSelfMethodCallRector;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(PreferThisOrSelfMethodCallRector::class, [
TestCase::class => 'prefer_self',
]);
};
```


```diff
use PHPUnit\Framework\TestCase;

final class SomeClass extends TestCase
{
public function run()
{
- $this->assertEquals('a', 'a');
+ self::assertEquals('a', 'a');
}
}
```

<br>

### RemoveFinalFromConstRector

Remove final from constants in classes defined as final
Expand All @@ -2061,49 +2020,6 @@ Remove final from constants in classes defined as final

<br>

### ReturnArrayClassMethodToYieldRector

Turns array return to yield return in specific type and method

:wrench: **configure it!**

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

```php
<?php

declare(strict_types=1);

use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector;
use Rector\CodingStyle\ValueObject\ReturnArrayClassMethodToYield;
use Rector\Config\RectorConfig;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->ruleWithConfiguration(ReturnArrayClassMethodToYieldRector::class, [
new ReturnArrayClassMethodToYield('PHPUnit\Framework\TestCase', '*provide*'),
]);
};
```


```diff
use PHPUnit\Framework\TestCase;

final class SomeTest implements TestCase
{
public static function provideData()
{
- return [
- ['some text']
- ];
+ yield ['some text'];
}
}
```

<br>

### SeparateMultiUseImportsRector

Split multi use imports and trait statements to standalone lines
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,15 @@

namespace Rector\NodeTypeResolver\NodeTypeResolver;

use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassConst;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\Type;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\NodeTypeResolver\Contract\NodeTypeResolverInterface;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Symfony\Contracts\Service\Attribute\Required;

/**
Expand Down Expand Up @@ -43,7 +42,7 @@ public function getNodeClasses(): array
public function resolve(Node $node): Type
{
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
if (!$classReflection instanceof ClassReflection || $classReflection->isAnonymous()) {
if (! $classReflection instanceof ClassReflection || $classReflection->isAnonymous()) {
// anonymous class
return new ObjectWithoutClassType();
}
Expand Down
4 changes: 0 additions & 4 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -647,10 +647,6 @@ parameters:
- '#Fetching deprecated class constant PARENT_NODE#'
- '#Return type \(int\|PhpParser\\Node\\Expr\\FuncCall\|PhpParser\\Node\\Expr\\Ternary\|null\) of method Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector\:\:refactorWithScope\(\) should be covariant with return type \(1\|2\|3\|4\|array<PhpParser\\Node>\|PhpParser\\Node\|null\) of method Rector\\Core\\Contract\\Rector\\ScopeAwarePhpRectorInterface\:\:refactorWithScope\(\)#'

-
message: '#Offset 0 does not exist on array<PhpParser\\Node\\Stmt>\|null#'
path: rules/CodingStyle/Rector/ClassMethod/ReturnArrayClassMethodToYieldRector.php

# looks like a bug in the PHPStan rule, see https://github.com/rectorphp/rector-src/pull/3645#issuecomment-1561294527
-
message: '#Method name "(get|has|set)Attribute\(\)" is used in multiple traits\. Make it unique to avoid conflicts#'
Expand Down
6 changes: 0 additions & 6 deletions rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

declare(strict_types=1);

use Rector\CodingStyle\Rector\ClassMethod\ReturnArrayClassMethodToYieldRector;
use Rector\CodingStyle\Rector\String_\UseClassKeywordForClassNameResolutionRector;
use Rector\CodingStyle\ValueObject\ReturnArrayClassMethodToYield;
use Rector\Config\RectorConfig;
use Rector\Naming\Rector\Assign\RenameVariableToMatchMethodCallReturnTypeRector;
use Rector\Naming\Rector\Class_\RenamePropertyToMatchTypeRector;
Expand Down Expand Up @@ -33,10 +31,6 @@

$rectorConfig->rules([DeclareStrictTypesRector::class]);

$rectorConfig->ruleWithConfiguration(ReturnArrayClassMethodToYieldRector::class, [
new ReturnArrayClassMethodToYield('PHPUnit\Framework\TestCase', '*provide*'),
]);

$rectorConfig->paths([
__DIR__ . '/bin',
__DIR__ . '/src',
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit b4eb417

Please sign in to comment.