drop FixDataProviderAnnotationTypoRector, fixing typos in single docblock annotation is too narrow

This commit is contained in:
TomasVotruba 2020-05-05 15:43:55 +02:00
parent 97ebca9541
commit 73a5c61a92
4 changed files with 4 additions and 196 deletions

View File

@ -1,4 +1,4 @@
# All 501 Rectors Overview
# All 500 Rectors Overview
- [Projects](#projects)
- [General](#general)
@ -4288,7 +4288,7 @@ Nextras/Form upgrade of addDatePicker method call to DateControl assign
- class: [`Rector\Nette\Rector\Identical\EndsWithFunctionToNetteUtilsStringsRector`](/../master/rules/nette/src/Rector/Identical/EndsWithFunctionToNetteUtilsStringsRector.php)
- [test fixtures](/../master/rules/nette/tests/Rector/Identical/EndsWithFunctionToNetteUtilsStringsRector/Fixture)
Use Nette\Utils\Strings over bare string-functions
Use Nette\Utils\Strings::endWith() over bare string-functions
```diff
class SomeClass
@ -4298,9 +4298,7 @@ Use Nette\Utils\Strings over bare string-functions
$content = 'Hi, my name is Tom';
- $yes = substr($content, -strlen($needle)) === $needle;
- $no = $needle !== substr($content, -strlen($needle));
+ $yes = \Nette\Utils\Strings::endsWith($content, $needle);
+ $no = !\Nette\Utils\Strings::endsWith($content, $needle);
}
}
```
@ -4437,7 +4435,7 @@ Change setClass with class and arguments to separated methods
- class: [`Rector\Nette\Rector\Identical\StartsWithFunctionToNetteUtilsStringsRector`](/../master/rules/nette/src/Rector/Identical/StartsWithFunctionToNetteUtilsStringsRector.php)
- [test fixtures](/../master/rules/nette/tests/Rector/Identical/StartsWithFunctionToNetteUtilsStringsRector/Fixture)
Use Nette\Utils\Strings over bare string-functions
Use Nette\Utils\Strings::startsWith() over bare string-functions
```diff
class SomeClass
@ -4447,9 +4445,7 @@ Use Nette\Utils\Strings over bare string-functions
$content = 'Hi, my name is Tom';
- $yes = substr($content, 0, strlen($needle)) === $needle;
- $no = $needle !== substr($content, 0, strlen($needle));
+ $yes = \Nette\Utils\Strings::startwith($content, $needle);
+ $no = !\Nette\Utils\Strings::startwith($content, $needle);
+ $yes = \Nette\Utils\Strings::startsWith($content, $needle);
}
}
```
@ -5777,29 +5773,6 @@ Use explicit API for expecting PHP errors, warnings, and notices
<br>
### `FixDataProviderAnnotationTypoRector`
- class: [`Rector\PHPUnit\Rector\ClassMethod\FixDataProviderAnnotationTypoRector`](/../master/rules/phpunit/src/Rector/ClassMethod/FixDataProviderAnnotationTypoRector.php)
- [test fixtures](/../master/rules/phpunit/tests/Rector/ClassMethod/FixDataProviderAnnotationTypoRector/Fixture)
Fix data provider annotation typos
```diff
class SomeClass extends \PHPUnit\Framework\TestCase
{
/**
- * @dataProvidor testProvideData()
+ * @dataProvider testProvideData()
*/
public function test()
{
$nothing = 5;
}
}
```
<br>
### `GetMockBuilderGetMockToCreateMockRector`
- class: [`Rector\PHPUnit\Rector\MethodCall\GetMockBuilderGetMockToCreateMockRector`](/../master/rules/phpunit/src/Rector/MethodCall/GetMockBuilderGetMockToCreateMockRector.php)

View File

@ -1,96 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\Rector\ClassMethod;
use PhpParser\Node;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\PhpDocParser\Ast\PhpDoc\PhpDocTagNode;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\Core\Rector\AbstractPHPUnitRector;
use Rector\Core\RectorDefinition\CodeSample;
use Rector\Core\RectorDefinition\RectorDefinition;
use Rector\NodeTypeResolver\Node\AttributeKey;
/**
* @see https://stackoverflow.com/questions/10175414/phpunit-dataprovider-simply-doesnt-work/36339907#36339907
*
* @see \Rector\PHPUnit\Tests\Rector\ClassMethod\FixDataProviderAnnotationTypoRector\FixDataProviderAnnotationTypoRectorTest
*/
final class FixDataProviderAnnotationTypoRector extends AbstractPHPUnitRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Fix data provider annotation typos', [
new CodeSample(
<<<'PHP'
class SomeClass extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvidor testProvideData()
*/
public function test()
{
$nothing = 5;
}
}
PHP
,
<<<'PHP'
class SomeClass extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider testProvideData()
*/
public function test()
{
$nothing = 5;
}
}
PHP
),
]);
}
/**
* @return string[]
*/
public function getNodeTypes(): array
{
return [ClassMethod::class];
}
/**
* @param ClassMethod $node
*/
public function refactor(Node $node): ?Node
{
if (! $this->isInTestClass($node)) {
return null;
}
/** @var PhpDocInfo $phpDocInfo */
$phpDocInfo = $node->getAttribute(AttributeKey::PHP_DOC_INFO);
$phpDocNode = $phpDocInfo->getPhpDocNode();
foreach ($phpDocNode->children as $phpDocChildNode) {
if (! $phpDocChildNode instanceof PhpDocTagNode) {
continue;
}
$annotationName = $phpDocChildNode->name;
$annotationName = trim($annotationName, '()@');
// more than 2 letter difference, probably not a typo
if (levenshtein($annotationName, 'dataProvider') > 4) {
continue;
}
$phpDocChildNode->name = '@dataProvider ';
}
return $node;
}
}

View File

@ -1,30 +0,0 @@
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\Tests\Rector\ClassMethod\FixDataProviderAnnotationTypoRector;
use Iterator;
use Rector\Core\Testing\PHPUnit\AbstractRectorTestCase;
use Rector\PHPUnit\Rector\ClassMethod\FixDataProviderAnnotationTypoRector;
final class FixDataProviderAnnotationTypoRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideData()
*/
public function test(string $file): void
{
$this->doTestFile($file);
}
public function provideData(): Iterator
{
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture');
}
protected function getRectorClass(): string
{
return FixDataProviderAnnotationTypoRector::class;
}
}

View File

@ -1,39 +0,0 @@
<?php
namespace Rector\PHPUnit\Tests\Rector\ClassMethod\FixDataProviderAnnotationTypoRector\Fixture;
class SomeClass extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvidor testProvideData()
* @dataPravider testProvideData()
* @datapravider testProvideData()
* @datapravider testProvideData()
*/
public function test()
{
$nothing = 5;
}
}
?>
-----
<?php
namespace Rector\PHPUnit\Tests\Rector\ClassMethod\FixDataProviderAnnotationTypoRector\Fixture;
class SomeClass extends \PHPUnit\Framework\TestCase
{
/**
* @dataProvider testProvideData()
* @dataProvider testProvideData()
* @dataProvider testProvideData()
* @dataProvider testProvideData()
*/
public function test()
{
$nothing = 5;
}
}
?>