Skip to content

Commit d33e50b

Browse files
committed
[Php80] Handle OpenApi\Attributes\Property example to keep numeric string on AnnotationToAttributeRector
1 parent 6535bab commit d33e50b

3 files changed

Lines changed: 51 additions & 0 deletions

File tree

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
4+
5+
use OpenApi\Annotations as OA;
6+
7+
final class OpenAPIPropertyExampleKeepNumericString
8+
{
9+
/**
10+
* @OA\Property(
11+
* example="01112"
12+
* )
13+
*/
14+
public ?string $uid = null;
15+
}
16+
17+
?>
18+
-----
19+
<?php
20+
21+
namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
22+
23+
use OpenApi\Attributes as OA;
24+
25+
final class OpenAPIPropertyExampleKeepNumericString
26+
{
27+
#[OA\Property(example: '1112')]
28+
public ?string $uid = null;
29+
}
30+
31+
?>

rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/config/configured_rule.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -71,5 +71,8 @@
7171
'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\Annotation\SomeProperty',
7272
'Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\Attribute\OpenApi\Attribute\SomeProperty'
7373
),
74+
75+
// for testing allow numeric string keep as string
76+
new AnnotationToAttribute('OpenApi\\Annotations\\Property', 'OpenApi\\Attributes\\Property'),
7477
]);
7578
};
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
namespace OpenApi\Attributes;
6+
7+
if (class_exists('OpenApi\Attributes\Property')) {
8+
return;
9+
}
10+
11+
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::TARGET_PROPERTY | \Attribute::TARGET_PARAMETER | \Attribute::TARGET_CLASS_CONSTANT | \Attribute::IS_REPEATABLE)]
12+
class Property
13+
{
14+
public function __construct(mixed $example)
15+
{
16+
}
17+
}

0 commit comments

Comments
 (0)