Skip to content

Commit 01854ab

Browse files
authored
[jms] Add AccessorAnnotationToAttributeRector (#799)
1 parent a56ba65 commit 01854ab

File tree

12 files changed

+318
-185
lines changed

12 files changed

+318
-185
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"phpstan/phpstan": "^2.1.8",
1414
"phpstan/phpstan-webmozart-assert": "^2.0",
1515
"phpunit/phpunit": "^11.4",
16-
"rector/rector-src": "dev-main",
16+
"rector/rector-src": "dev-tv-abstract-annotation-to-attribute",
1717
"rector/type-perfect": "^2.0",
1818
"symfony/config": "^6.4",
1919
"symfony/dependency-injection": "^6.4",

config/sets/jms/annotations-to-attributes.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@
55
use Rector\Config\RectorConfig;
66
use Rector\Php80\Rector\Class_\AnnotationToAttributeRector;
77
use Rector\Php80\ValueObject\AnnotationToAttribute;
8-
use Rector\Symfony\JMS\Rector\AccessTypeAnnotationToAttributeRector;
8+
use Rector\Symfony\JMS\Rector\Class_\AccessTypeAnnotationToAttributeRector;
9+
use Rector\Symfony\JMS\Rector\Property\AccessorAnnotationToAttributeRector;
910

1011
/**
1112
* @see https://github.com/schmittjoh/serializer/pull/1320
@@ -14,7 +15,6 @@
1415
*/
1516
return static function (RectorConfig $rectorConfig): void {
1617
$rectorConfig->ruleWithConfiguration(AnnotationToAttributeRector::class, [
17-
new AnnotationToAttribute('JMS\Serializer\Annotation\Accessor'),
1818
new AnnotationToAttribute('JMS\Serializer\Annotation\AccessorOrder'),
1919
new AnnotationToAttribute('JMS\Serializer\Annotation\Discriminator'),
2020
new AnnotationToAttribute('JMS\Serializer\Annotation\Exclude'),
@@ -46,5 +46,8 @@
4646
new AnnotationToAttribute('JMS\Serializer\Annotation\XmlValue'),
4747
]);
4848

49-
$rectorConfig->rules([AccessTypeAnnotationToAttributeRector::class]);
49+
$rectorConfig->rules([
50+
AccessTypeAnnotationToAttributeRector::class,
51+
AccessorAnnotationToAttributeRector::class,
52+
]);
5053
};

rules-tests/JMS/Rector/Class_/AccessTypeAnnotationToAttributeRector/config/configured_rule.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
declare(strict_types=1);
44

55
use Rector\Config\RectorConfig;
6-
use Rector\Symfony\JMS\Rector\AccessTypeAnnotationToAttributeRector;
6+
use Rector\Symfony\JMS\Rector\Class_\AccessTypeAnnotationToAttributeRector;
77

88
return static function (RectorConfig $rectorConfig): void {
99
$rectorConfig->rule(AccessTypeAnnotationToAttributeRector::class);
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace Rector\Symfony\Tests\JMS\Rector\Property\AccessorAnnotationToAttributeRector;
6+
7+
use Iterator;
8+
use PHPUnit\Framework\Attributes\DataProvider;
9+
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
10+
11+
final class AccessorAnnotationToAttributeRectorTest extends AbstractRectorTestCase
12+
{
13+
#[DataProvider('provideData')]
14+
public function test(string $filePath): void
15+
{
16+
$this->doTestFile($filePath);
17+
}
18+
19+
public static function provideData(): Iterator
20+
{
21+
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
22+
}
23+
24+
public function provideConfigFilePath(): string
25+
{
26+
return __DIR__ . '/config/configured_rule.php';
27+
}
28+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\JMS\Rector\Property\AccessorAnnotationToAttributeRector\Fixture;
4+
5+
use JMS\Serializer\Annotation as Serializer;
6+
7+
final class AnnotationTypes
8+
{
9+
/**
10+
* @Serializer\Accessor("getSome")
11+
*/
12+
private $value;
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Symfony\Tests\JMS\Rector\Property\AccessorAnnotationToAttributeRector\Fixture;
20+
21+
use JMS\Serializer\Annotation as Serializer;
22+
23+
final class AnnotationTypes
24+
{
25+
#[Serializer\Accessor(getter: 'getSome')]
26+
private $value;
27+
}
28+
29+
?>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
<?php
2+
3+
namespace Rector\Symfony\Tests\JMS\Rector\Property\AccessorAnnotationToAttributeRector\Fixture;
4+
5+
use JMS\Serializer\Annotation as Serializer;
6+
7+
final class KeepGivenKey
8+
{
9+
/**
10+
* @Serializer\Accessor(setter="setSome")
11+
*/
12+
private $value;
13+
}
14+
15+
?>
16+
-----
17+
<?php
18+
19+
namespace Rector\Symfony\Tests\JMS\Rector\Property\AccessorAnnotationToAttributeRector\Fixture;
20+
21+
use JMS\Serializer\Annotation as Serializer;
22+
23+
final class KeepGivenKey
24+
{
25+
#[Serializer\Accessor(setter: 'setSome')]
26+
private $value;
27+
}
28+
29+
?>
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
use Rector\Config\RectorConfig;
6+
use Rector\Symfony\JMS\Rector\Property\AccessorAnnotationToAttributeRector;
7+
8+
return static function (RectorConfig $rectorConfig): void {
9+
$rectorConfig->rule(AccessorAnnotationToAttributeRector::class);
10+
};

rules/JMS/Rector/AccessTypeAnnotationToAttributeRector.php

Lines changed: 0 additions & 180 deletions
This file was deleted.

0 commit comments

Comments
 (0)