-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Feature] Add configurable InlineSimplePropertyAnnotationRector for i…
…nlining of simple annotations (#2070) * [Feature] Add configurable InlineSimplePropertyAnnotationRector for inlining of simple annotations * [Feature] CR fix - use AllowEmptyConfigurableRectorInterface * [Feature] CR fix - ltrim @ if user provides it in configuration by accident * [Feature] CR fix - Renaming in tests Co-authored-by: Jiří Bok <jiri.bok@protonmail.com>
- Loading branch information
1 parent
c509923
commit d30a863
Showing
16 changed files
with
491 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
...tationRector/Fixture/CustomConfig/inline_simple_var_annotation_with_custom_config.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\CustomConfig; | ||
|
||
final class InlineSimpleVarAnnotationWithCustomConfig | ||
{ | ||
/** | ||
* @custom-var \DateTime[]|null | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\CustomConfig; | ||
|
||
final class InlineSimpleVarAnnotationWithCustomConfig | ||
{ | ||
/** @custom-var \DateTime[]|null */ | ||
private ?array $dateTimes; | ||
} | ||
?> |
12 changes: 12 additions & 0 deletions
12
...tationRector/Fixture/CustomConfig/skip_unconfigured_annotation_with_custom_config.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\CustomConfig; | ||
|
||
final class SkipUnconfiguredAnnotationWithCustomConfig | ||
{ | ||
/** | ||
* @var \DateTime[]|null A datetime! | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> |
23 changes: 23 additions & 0 deletions
23
...neSimplePropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotation | ||
{ | ||
/** | ||
* @var \DateTime[]|null | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotation | ||
{ | ||
/** @var \DateTime[]|null */ | ||
private ?array $dateTimes; | ||
} | ||
?> |
39 changes: 39 additions & 0 deletions
39
...notationRector/Fixture/EmptyConfig/inline_simple_var_annotation_above_class_const.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotationAboveClassConstant | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private const AXES = ['x', 'y', 'z']; | ||
|
||
/** | ||
* @phpstan-var int[] | ||
*/ | ||
public const NUMBERS = [1, 2, 3]; | ||
|
||
/** | ||
* @psalm-var \DateTime[]|null | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotationAboveClassConstant | ||
{ | ||
/** @var string[] */ | ||
private const AXES = ['x', 'y', 'z']; | ||
|
||
/** @phpstan-var int[] */ | ||
public const NUMBERS = [1, 2, 3]; | ||
|
||
/** @psalm-var \DateTime[]|null */ | ||
private ?array $dateTimes; | ||
} | ||
?> |
23 changes: 23 additions & 0 deletions
23
...ropertyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_combined.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotationAboveClassConstant | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private const AXES = ['x', 'y', 'z']; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotationAboveClassConstant | ||
{ | ||
/** @var string[] */ | ||
private const AXES = ['x', 'y', 'z']; | ||
} | ||
?> |
23 changes: 23 additions & 0 deletions
23
...rtyAnnotationRector/Fixture/EmptyConfig/inline_simple_var_annotation_with_comment.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotationWithComment | ||
{ | ||
/** | ||
* @var \DateTime[]|null A datetime! | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineSimpleVarAnnotationWithComment | ||
{ | ||
/** @var \DateTime[]|null A datetime! */ | ||
private ?array $dateTimes; | ||
} | ||
?> |
12 changes: 12 additions & 0 deletions
12
...neSimplePropertyAnnotationRector/Fixture/EmptyConfig/skip_unconfigured_annotation.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class SkipUnconfiguredAnnotation | ||
{ | ||
/** | ||
* @unconfiguredAnnotation \DateTime[]|null A datetime! | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> |
13 changes: 13 additions & 0 deletions
13
...tyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_with_multiline_comment.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineVarAnnotationWithMultilineComment | ||
{ | ||
/** | ||
* @var \DateTime[]|null A datetime with multiline | ||
* description! | ||
*/ | ||
private ?array $dateTimes; | ||
} | ||
?> |
18 changes: 18 additions & 0 deletions
18
...tyAnnotationRector/Fixture/EmptyConfig/skip_var_annotation_within_complex_comment.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class InlineVarAnnotationWithinComplexComment | ||
{ | ||
/** | ||
* @Serializer\VirtualProperty | ||
* @Serializer\Type("array<DateTime>") | ||
* @Assert\All({ | ||
* @Assert\NotBlank, | ||
* @AppAssert\Country, | ||
* }) | ||
* @var \DateTime[] $dateTimes | ||
*/ | ||
private array $dateTimes; | ||
} | ||
?> |
25 changes: 25 additions & 0 deletions
25
...nnotationRector/Fixture/EmptyConfig/skip_var_types_which_break_on_stringification.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class SkipVarTypesWhichBreakOnStringification | ||
{ | ||
/** | ||
* @phpstan-var 'week'|'month'|'year' | ||
*/ | ||
private string $interval; | ||
} | ||
?> | ||
----- | ||
<?php | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector\Fixture\EmptyConfig; | ||
|
||
final class SkipVarTypesWhichBreakOnStringification | ||
{ | ||
/** | ||
* @phpstan-var 'week'|'month'|'year' | ||
*/ | ||
private string $interval; | ||
} | ||
?> |
33 changes: 33 additions & 0 deletions
33
...roperty/InlineSimplePropertyAnnotationRector/InlineSimplePropertyAnnotationRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class InlineSimplePropertyAnnotationRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture/EmptyConfig'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configure_rule_empty_config.php'; | ||
} | ||
} |
33 changes: 33 additions & 0 deletions
33
...mplePropertyAnnotationRector/InlineSimplePropertyAnnotationWithCustomConfigRectorTest.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; | ||
|
||
use Iterator; | ||
use Rector\Testing\PHPUnit\AbstractRectorTestCase; | ||
use Symplify\SmartFileSystem\SmartFileInfo; | ||
|
||
final class InlineSimplePropertyAnnotationWithCustomConfigRectorTest extends AbstractRectorTestCase | ||
{ | ||
/** | ||
* @dataProvider provideData() | ||
*/ | ||
public function test(SmartFileInfo $fileInfo): void | ||
{ | ||
$this->doTestFileInfo($fileInfo); | ||
} | ||
|
||
/** | ||
* @return Iterator<SmartFileInfo> | ||
*/ | ||
public function provideData(): Iterator | ||
{ | ||
return $this->yieldFilesFromDirectory(__DIR__ . '/Fixture/CustomConfig'); | ||
} | ||
|
||
public function provideConfigFilePath(): string | ||
{ | ||
return __DIR__ . '/config/configure_rule_custom_config.php'; | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...tor/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_custom_config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; | ||
|
||
use Rector\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$rectorServiceConfigurator = $services->set(InlineSimplePropertyAnnotationRector::class); | ||
/** @phpstan-ignore-next-line */ | ||
$rectorServiceConfigurator->configure(['custom-var']); | ||
}; |
13 changes: 13 additions & 0 deletions
13
...ctor/Property/InlineSimplePropertyAnnotationRector/config/configure_rule_empty_config.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\Tests\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; | ||
|
||
use Rector\CodingStyle\Rector\Property\InlineSimplePropertyAnnotationRector; | ||
use Symfony\Component\DependencyInjection\Loader\Configurator\ContainerConfigurator; | ||
|
||
return static function (ContainerConfigurator $containerConfigurator): void { | ||
$services = $containerConfigurator->services(); | ||
$services->set(InlineSimplePropertyAnnotationRector::class); | ||
}; |
Oops, something went wrong.