rename ValueObjectRemover*Rector to more propper ObjectToScalar*Rector

This commit is contained in:
Tomas Votruba 2018-12-14 20:34:40 +01:00
parent c10a32a67b
commit 2b29db0839
23 changed files with 165 additions and 196 deletions

View File

@ -1,15 +1,14 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Rector\ValueObjectRemover;
namespace Rector\DomainDrivenDesign\Rector\ObjectToScalar;
use PhpParser\Node;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\DocBlockAnalyzer;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\NamespaceAnalyzer;
use Rector\NodeTypeResolver\PhpDoc\NodeAnalyzer\NamespaceAnalyzer as RectorNamespaceAnalyzer;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Rector\AbstractRector;
abstract class AbstractValueObjectRemoverRector extends AbstractRector
abstract class AbstractObjectToScalarRector extends AbstractRector
{
/**
* @var string[]
@ -38,12 +37,12 @@ abstract class AbstractValueObjectRemoverRector extends AbstractRector
array $valueObjectsToSimpleTypes,
DocBlockAnalyzer $docBlockAnalyzer,
BetterNodeFinder $betterNodeFinder,
RectorNamespaceAnalyzer $rectorNamespaceAnalyzer
NamespaceAnalyzer $namespaceAnalyzer
) {
$this->valueObjectsToSimpleTypes = $valueObjectsToSimpleTypes;
$this->docBlockAnalyzer = $docBlockAnalyzer;
$this->betterNodeFinder = $betterNodeFinder;
$this->namespaceAnalyzer = $rectorNamespaceAnalyzer;
$this->namespaceAnalyzer = $namespaceAnalyzer;
}
protected function matchNewType(Node $node): ?string

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Rector\ValueObjectRemover;
namespace Rector\DomainDrivenDesign\Rector\ObjectToScalar;
use PhpParser\Node;
use PhpParser\Node\Expr;
@ -13,7 +13,7 @@ use Rector\NodeTypeResolver\Node\Attribute;
use Rector\RectorDefinition\ConfiguredCodeSample;
use Rector\RectorDefinition\RectorDefinition;
final class ValueObjectRemoverDocBlockRector extends AbstractValueObjectRemoverRector
final class ObjectToScalarDocBlockRector extends AbstractObjectToScalarRector
{
public function getDefinition(): RectorDefinition
{
@ -24,6 +24,9 @@ final class ValueObjectRemoverDocBlockRector extends AbstractValueObjectRemoverR
* @var ValueObject|null
*/
private $name;
/** @var ValueObject|null */
$name;
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
@ -31,21 +34,7 @@ CODE_SAMPLE
* @var string|null
*/
private $name;
CODE_SAMPLE
,
[
'$valueObjectsToSimpleTypes' => [
'ValueObject' => 'string',
],
]
),
new ConfiguredCodeSample(
<<<'CODE_SAMPLE'
/** @var ValueObject|null */
$name;
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
/** @var string|null */
$name;
CODE_SAMPLE

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Rector\ValueObjectRemover;
namespace Rector\DomainDrivenDesign\Rector\ObjectToScalar;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
@ -12,41 +12,26 @@ use Rector\NodeTypeResolver\Node\Attribute;
use Rector\RectorDefinition\ConfiguredCodeSample;
use Rector\RectorDefinition\RectorDefinition;
final class ValueObjectRemoverRector extends AbstractValueObjectRemoverRector
final class ObjectToScalarRector extends AbstractObjectToScalarRector
{
public function getDefinition(): RectorDefinition
{
return new RectorDefinition('Remove values objects and use directly the value.', [
new ConfiguredCodeSample(
'$name = new ValueObject("name");',
'$name = "name";',
[
'$valueObjectsToSimpleTypes' => [
'ValueObject' => 'string',
],
]
),
new ConfiguredCodeSample(
'function someFunction(ValueObject $name) { }',
'function someFunction(string $name) { }',
[
'$valueObjectsToSimpleTypes' => [
'ValueObject' => 'string',
],
]
),
new ConfiguredCodeSample(
'function someFunction(): ValueObject { }',
'function someFunction(): string { }',
[
'$valueObjectsToSimpleTypes' => [
'ValueObject' => 'string',
],
]
),
new ConfiguredCodeSample(
'function someFunction(): ?ValueObject { }',
'function someFunction(): ?string { }',
<<<'CODE_SAMPLE'
$name = new ValueObject("name");
function someFunction(ValueObject $name): ?ValueObject {
}
CODE_SAMPLE
,
<<<'CODE_SAMPLE'
$name = "name";
function someFunction(string $name): ?string {
}
CODE_SAMPLE
,
[
'$valueObjectsToSimpleTypes' => [
'ValueObject' => 'string',

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Fixture;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Fixture;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeChildOfValueObject;
class FirstActionClass
{
@ -23,9 +23,9 @@ class FirstActionClass
-----
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Fixture;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Fixture;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeChildOfValueObject;
class FirstActionClass
{

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Fixture;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Fixture;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeValueObject;
class FourthActionClass
{
@ -17,9 +17,9 @@ class FourthActionClass
-----
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Fixture;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Fixture;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeValueObject;
class FourthActionClass
{

View File

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

View File

@ -0,0 +1,32 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector;
use Rector\DomainDrivenDesign\Rector\ObjectToScalar\ObjectToScalarDocBlockRector;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeValueObject;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class ObjectToScalarDocBlockRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles([
__DIR__ . '/Fixture/fixture.php.inc',
__DIR__ . '/Fixture/fixture2.php.inc',
__DIR__ . '/Fixture/fixture3.php.inc',
]);
}
protected function getRectorClass(): string
{
return ObjectToScalarDocBlockRector::class;
}
/**
* @return mixed[]
*/
protected function getRectorConfiguration(): array
{
return [SomeValueObject::class => 'string'];
}
}

View File

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

View File

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

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeChildOfValueObject;
class ActionClass
{
@ -23,9 +23,9 @@ class ActionClass
-----
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeChildOfValueObject;
class ActionClass
{

View File

@ -4,7 +4,7 @@ namespace SomeNamespace;
class SecondActionClass
{
public function someFunction(\Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeChildOfValueObject $name)
public function someFunction(\Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeChildOfValueObject $name)
{
}
}

View File

@ -2,7 +2,7 @@
namespace SomeNamespace;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeValueObject;
class ThirdActionClass
{
@ -20,7 +20,7 @@ class ThirdActionClass
namespace SomeNamespace;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeValueObject;
class ThirdActionClass
{

View File

@ -2,7 +2,7 @@
namespace SomeNamespace;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeValueObject;
class FourthActionClass
{
@ -19,7 +19,7 @@ class FourthActionClass
namespace SomeNamespace;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeValueObject;
class FourthActionClass
{

View File

@ -0,0 +1,33 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector;
use Rector\DomainDrivenDesign\Rector\ObjectToScalar\ObjectToScalarRector;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source\SomeValueObject;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class ObjectToScalarRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles([
__DIR__ . '/Fixture/fixture.php.inc',
__DIR__ . '/Fixture/fixture2.php.inc',
__DIR__ . '/Fixture/fixture3.php.inc',
__DIR__ . '/Fixture/fixture4.php.inc',
]);
}
protected function getRectorClass(): string
{
return ObjectToScalarRector::class;
}
/**
* @return mixed[]
*/
protected function getRectorConfiguration(): array
{
return [SomeValueObject::class => 'string'];
}
}

View File

@ -1,6 +1,6 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarRector\Source;
class SomeChildOfValueObject extends SomeValueObject
{

View File

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

View File

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

View File

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

View File

@ -1,34 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector;
use Rector\DomainDrivenDesign\Rector\ValueObjectRemover\ValueObjectRemoverDocBlockRector;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class ValueObjectRemoverDocBlockRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles(
[
__DIR__ . '/Fixture/fixture.php.inc',
__DIR__ . '/Fixture/fixture2.php.inc',
__DIR__ . '/Fixture/fixture3.php.inc',
]
);
}
protected function getRectorClass(): string
{
return ValueObjectRemoverDocBlockRector::class;
}
/**
* @return mixed[]
*/
protected function getRectorConfiguration(): array
{
return [SomeValueObject::class => 'string'];
}
}

View File

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

View File

@ -1,35 +0,0 @@
<?php declare(strict_types=1);
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector;
use Rector\DomainDrivenDesign\Rector\ValueObjectRemover\ValueObjectRemoverRector;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverRector\Source\SomeValueObject;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
final class ValueObjectRemoverRectorTest extends AbstractRectorTestCase
{
public function test(): void
{
$this->doTestFiles(
[
__DIR__ . '/Fixture/fixture.php.inc',
__DIR__ . '/Fixture/fixture2.php.inc',
__DIR__ . '/Fixture/fixture3.php.inc',
__DIR__ . '/Fixture/fixture4.php.inc',
]
);
}
protected function getRectorClass(): string
{
return ValueObjectRemoverRector::class;
}
/**
* @return mixed[]
*/
protected function getRectorConfiguration(): array
{
return [SomeValueObject::class => 'string'];
}
}

View File

@ -4,8 +4,8 @@ namespace Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver
use Iterator;
use PhpParser\Node\Stmt\Property;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeValueObject;
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\AbstractNodeTypeResolverTest;
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source\ClassThatExtendsHtml;
use Rector\NodeTypeResolver\Tests\PerNodeTypeResolver\PropertyTypeResolver\Source\Html;

View File

@ -1,8 +1,8 @@
<?php
namespace Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector;
namespace Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector;
use Rector\DomainDrivenDesign\Tests\Rector\ValueObjectRemoverDocBlockRector\Source\SomeChildOfValueObject;
use Rector\DomainDrivenDesign\Tests\Rector\ObjectToScalarDocBlockRector\Source\SomeChildOfValueObject;
class ActionClass
{