split ValueObjectRemoverDocBlockRector

This commit is contained in:
Tomas Votruba 2018-08-14 11:39:31 +02:00
parent f53e9c2127
commit d8b430ff72
16 changed files with 155 additions and 12 deletions

View File

@ -11,7 +11,6 @@ use PhpParser\Node\Name\FullyQualified;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Return_;
use Rector\Node\Attribute;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockAnalyzer;
use Rector\Rector\AbstractPHPUnitRector;
use Rector\RectorDefinition\CodeSample;

View File

@ -0,0 +1,20 @@
<?php
namespace Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector;
use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeChildOfValueObject;
class ActionClass
{
/**
* @var string|null
*/
private $someChildValueObject;
public function someFunction()
{
$this->someChildValueObject = new SomeChildOfValueObject('value');
$someChildValueObject = new SomeChildOfValueObject();
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SomeNamespace;
use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
class FourthActionClass
{
public function someFunction(?SomeValueObject $name): ?SomeValueObject
{
/** @var string|null $someValueObject */
$someValueObject = new SomeValueObject('value');
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace SomeNamespace;
use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
class ThirdActionClass
{
/**
* @param null|string $name
*/
public function someFunction(?SomeValueObject $name): ?SomeValueObject
{
}
}

View File

@ -0,0 +1,7 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source;
class SomeChildOfValueObject extends SomeValueObject
{
}

View File

@ -0,0 +1,8 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source;
class SomeValueObject
{
}

View File

@ -0,0 +1,32 @@
<?php declare(strict_types=1);
namespace Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector;
use Iterator;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
/**
* @covers \Rector\Rector\DomainDrivenDesign\ValueObjectRemover\ValueObjectRemoverDocBlockRector
*/
final class ValueObjectRemoverDocBlockRectorTest extends AbstractRectorTestCase
{
/**
* @dataProvider provideWrongToFixedFiles()
*/
public function test(string $wrong, string $fixed): void
{
$this->doTestFileMatchesExpectedContent($wrong, $fixed);
}
public function provideWrongToFixedFiles(): Iterator
{
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
yield [__DIR__ . '/Wrong/wrong3.php.inc', __DIR__ . '/Correct/correct3.php.inc'];
}
protected function provideConfig(): string
{
return __DIR__ . '/config.yml';
}
}

View File

@ -0,0 +1,20 @@
<?php
namespace Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector;
use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeChildOfValueObject;
class ActionClass
{
/**
* @var SomeChildOfValueObject|null
*/
private $someChildValueObject;
public function someFunction()
{
$this->someChildValueObject = new SomeChildOfValueObject('value');
$someChildValueObject = new SomeChildOfValueObject();
}
}

View File

@ -0,0 +1,14 @@
<?php
namespace SomeNamespace;
use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
class FourthActionClass
{
public function someFunction(?SomeValueObject $name): ?SomeValueObject
{
/** @var SomeValueObject|null $someValueObject */
$someValueObject = new SomeValueObject('value');
}
}

View File

@ -0,0 +1,15 @@
<?php
namespace SomeNamespace;
use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
class ThirdActionClass
{
/**
* @param null|SomeValueObject $name
*/
public function someFunction(?SomeValueObject $name): ?SomeValueObject
{
}
}

View File

@ -0,0 +1,4 @@
services:
Rector\Rector\DomainDrivenDesign\ValueObjectRemover\ValueObjectRemoverDocBlockRector:
$valueObjectsToSimpleTypes:
'Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverDocBlockRector\Source\SomeValueObject': 'string'

View File

@ -7,7 +7,7 @@ use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverRector\Source\SomeC
class ActionClass
{
/**
* @var string|null
* @var SomeChildOfValueObject|null
*/
private $someChildValueObject;

View File

@ -7,7 +7,7 @@ use Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverRector\Source\SomeV
class ThirdActionClass
{
/**
* @param null|string $name
* @param null|SomeValueObject $name
*/
public function someFunction(?string $name): ?string
{

View File

@ -8,7 +8,7 @@ class FourthActionClass
{
public function someFunction(?string $name): ?string
{
/** @var string|null $someValueObject */
/** @var SomeValueObject|null $someValueObject */
$someValueObject = 'value';
}
}

View File

@ -22,9 +22,9 @@ final class ValueObjectRemoverRectorTest extends AbstractRectorTestCase
public function provideWrongToFixedFiles(): Iterator
{
yield [__DIR__ . '/Wrong/wrong.php.inc', __DIR__ . '/Correct/correct.php.inc'];
// yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
// yield [__DIR__ . '/Wrong/wrong3.php.inc', __DIR__ . '/Correct/correct3.php.inc'];
// yield [__DIR__ . '/Wrong/wrong4.php.inc', __DIR__ . '/Correct/correct4.php.inc'];
yield [__DIR__ . '/Wrong/wrong2.php.inc', __DIR__ . '/Correct/correct2.php.inc'];
yield [__DIR__ . '/Wrong/wrong3.php.inc', __DIR__ . '/Correct/correct3.php.inc'];
yield [__DIR__ . '/Wrong/wrong4.php.inc', __DIR__ . '/Correct/correct4.php.inc'];
}
protected function provideConfig(): string

View File

@ -1,9 +1,4 @@
services:
# todo: combine configuration in some way
Rector\Rector\DomainDrivenDesign\ValueObjectRemover\ValueObjectRemoverDocBlockRector:
$valueObjectsToSimpleTypes:
'Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverRector\Source\SomeValueObject': 'string'
Rector\Rector\DomainDrivenDesign\ValueObjectRemover\ValueObjectRemoverRector:
$valueObjectsToSimpleTypes:
'Rector\Tests\Rector\DomainDrivenDesign\ValueObjectRemoverRector\Source\SomeValueObject': 'string'