Skip to content

Commit

Permalink
Rectify (#5324)
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 4, 2023
1 parent 526f4cd commit 005ccc3
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 51 deletions.
58 changes: 18 additions & 40 deletions build/target-repository/docs/rector_rules_overview.md
@@ -1,12 +1,12 @@
# 353 Rules Overview
# 351 Rules Overview

<br>

## Categories

- [Arguments](#arguments) (4)

- [CodeQuality](#codequality) (72)
- [CodeQuality](#codequality) (73)

- [CodingStyle](#codingstyle) (27)

Expand All @@ -30,7 +30,7 @@

- [Php70](#php70) (19)

- [Php71](#php71) (8)
- [Php71](#php71) (7)

- [Php72](#php72) (9)

Expand All @@ -56,7 +56,7 @@

- [Transform](#transform) (22)

- [TypeDeclaration](#typedeclaration) (40)
- [TypeDeclaration](#typedeclaration) (39)

- [Visibility](#visibility) (3)

Expand Down Expand Up @@ -942,6 +942,19 @@ Remove `sprintf()` wrapper if not needed

<br>

### RemoveUselessIsObjectCheckRector

Remove useless `is_object()` check on combine with instanceof check

- class: [`Rector\CodeQuality\Rector\BooleanAnd\RemoveUselessIsObjectCheckRector`](../rules/CodeQuality/Rector/BooleanAnd/RemoveUselessIsObjectCheckRector.php)

```diff
-is_object($obj) && $obj instanceof DateTime
+$obj instanceof DateTime
```

<br>

### ReplaceMultipleBooleanNotRector

Replace the Double not operator (!!) by type-casting to boolean
Expand Down Expand Up @@ -3818,7 +3831,7 @@ Changes PHP 4 style constructor to __construct.

### RandomFunctionRector

Changes rand, srand, mt_rand and getrandmax to newer alternatives.
Changes rand, srand, and getrandmax to newer alternatives

- class: [`Rector\Php70\Rector\FuncCall\RandomFunctionRector`](../rules/Php70/Rector/FuncCall/RandomFunctionRector.php)

Expand Down Expand Up @@ -4005,20 +4018,6 @@ Change binary operation between some number + string to PHP 7.1 compatible versi

<br>

### CountOnNullRector

Changes `count()` on null to safe ternary check

- class: [`Rector\Php71\Rector\FuncCall\CountOnNullRector`](../rules/Php71/Rector/FuncCall/CountOnNullRector.php)

```diff
$values = null;
-$count = count($values);
+$count = $values === null ? 0 : count($values);
```

<br>

### IsIterableRector

Changes is_array + Traversable check to is_iterable
Expand Down Expand Up @@ -6990,27 +6989,6 @@ Add typed properties based only on strict constructor types

<br>

### TypedPropertyFromStrictGetterMethodReturnTypeRector

Complete property type based on getter strict types

- class: [`Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictGetterMethodReturnTypeRector`](../rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictGetterMethodReturnTypeRector.php)

```diff
final class SomeClass
{
- public $name;
+ public ?string $name = null;

public function getName(): string|null
{
return $this->name;
}
}
```

<br>

### TypedPropertyFromStrictSetUpRector

Add strict typed property based on `setUp()` strict typed assigns in TestCase
Expand Down
2 changes: 1 addition & 1 deletion packages/Testing/PHPUnit/AbstractRectorTestCase.php
Expand Up @@ -205,7 +205,7 @@ private function includePreloadFilesAndScoperAutoload(): void
if (file_exists(__DIR__ . '/../../../preload.php')) {
if (file_exists(__DIR__ . '/../../../vendor')) {
require_once __DIR__ . '/../../../preload.php';
// test case in rector split package
// test case in rector split package
} elseif (file_exists(__DIR__ . '/../../../../../../vendor')) {
require_once __DIR__ . '/../../../preload-split-package.php';
}
Expand Down
15 changes: 7 additions & 8 deletions rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php
Expand Up @@ -4,8 +4,8 @@

namespace Rector\DeadCode\PhpDoc;

use PhpParser\Node\Identifier;
use PhpParser\Node;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
Expand Down Expand Up @@ -50,7 +50,7 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, ClassMethod $clas
return false;
}

if (!$this->hasUsefullPhpdocType($returnTagValueNode, $returnType)) {
if (! $this->hasUsefullPhpdocType($returnTagValueNode, $returnType)) {
return true;
}

Expand Down Expand Up @@ -132,15 +132,14 @@ private function hasTrueFalsePseudoType(BracketsAwareUnionTypeNode $bracketsAwar
*/
private function hasUsefullPhpdocType(ReturnTagValueNode $returnTagValueNode, mixed $returnType): bool
{
if ($this->isVoidReturnType($returnType)) {
if (! $returnTagValueNode->type instanceof IdentifierTypeNode || (string) $returnTagValueNode->type !== 'never') {
return false;
}
if (! $this->isVoidReturnType($returnType)) {
return ! $this->isNeverReturnType($returnType);
}
if ($this->isNeverReturnType($returnType)) {

if (! $returnTagValueNode->type instanceof IdentifierTypeNode || (string) $returnTagValueNode->type !== 'never') {
return false;
}

return true;
return ! $this->isNeverReturnType($returnType);
}
}
4 changes: 2 additions & 2 deletions rules/DeadCode/Rector/If_/RemoveDeadInstanceOfRector.php
Expand Up @@ -4,17 +4,17 @@

namespace Rector\DeadCode\Rector\If_;

use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Instanceof_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\If_;
use PhpParser\NodeTraverser;
use PHPStan\Type\MixedType;
Expand Down

0 comments on commit 005ccc3

Please sign in to comment.