Skip to content

Commit

Permalink
[DeadCode] Add RemoveNullTagValueNodeRector (#5352)
Browse files Browse the repository at this point in the history
* [DeadCode] Add RemoveNullTagValueNodeRector

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

* rename fixture

* desc

* register in missing in set command on purpose

* add fixtures

* fix param

* fix var

* [ci-review] Rector Rectify

* fix

* more fixture

* more fixture

* regenerate docs

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 10, 2023
1 parent f8c3a2e commit 287eab3
Show file tree
Hide file tree
Showing 11 changed files with 378 additions and 2 deletions.
25 changes: 23 additions & 2 deletions build/target-repository/docs/rector_rules_overview.md
@@ -1,4 +1,4 @@
# 352 Rules Overview
# 353 Rules Overview

<br>

Expand All @@ -10,7 +10,7 @@

- [CodingStyle](#codingstyle) (27)

- [DeadCode](#deadcode) (42)
- [DeadCode](#deadcode) (43)

- [EarlyReturn](#earlyreturn) (9)

Expand Down Expand Up @@ -2509,6 +2509,27 @@ Remove initialization with null value from property declarations

<br>

### RemoveNullTagValueNodeRector

Remove `@var/@param/@return` null docblock

- class: [`Rector\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector`](../rules/DeadCode/Rector/ClassMethod/RemoveNullTagValueNodeRector.php)

```diff
class SomeClass
{
- /**
- * @return null
- */
public function foo()
{
return null;
}
}
```

<br>

### RemoveParentCallWithoutParentRector

Remove unused parent call with no parent class
Expand Down
@@ -0,0 +1,30 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNullParam
{
/**
* @param null $foo
*/
function foo($foo = null)
{
return null;
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNullParam
{
function foo($foo = null)
{
return null;
}
}

?>
@@ -0,0 +1,30 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNull
{
/**
* @return null
*/
function foo()
{
return null;
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNull
{
function foo()
{
return null;
}
}

?>
@@ -0,0 +1,24 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNullVar
{
/**
* @var null
*/
public $var = null;
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNullVar
{
public $var = null;
}

?>
@@ -0,0 +1,28 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNullVar2
{
public function foo()
{
/** @var null $var */
$var = execute();
}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class RemoveNullVar2
{
public function foo()
{
$var = execute();
}
}

?>
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class SkipDifferentTagValue
{
/**
* @return mixed
*/
function foo()
{
return null;
}
}
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector\Fixture;

class SkipWithDescription
{
/**
* @return null some description
*/
function foo()
{
return null;
}
}
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
use SplFileInfo;

final class RemoveNullTagValueNodeRectorTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

/**
* @return Iterator<SplFileInfo>
*/
public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/configured_rule.php';
}
}
@@ -0,0 +1,10 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\DeadCode\Rector\ClassMethod\RemoveNullTagValueNodeRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig->rule(RemoveNullTagValueNodeRector::class);
};

0 comments on commit 287eab3

Please sign in to comment.