Skip to content

Commit 1293dde

Browse files
committed
Remove docblock * from multi-line strings in attributes
Amp-Thread-ID: https://ampcode.com/threads/T-01a17930-0285-73c5-a957-4325c77aa1b2
1 parent 2e99ab4 commit 1293dde

6 files changed

Lines changed: 24 additions & 18 deletions

File tree

‎rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/multiline_content.php.inc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
2222
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
2323

2424
#[GenericAnnotation('
25-
* summary: Send webcam reward
26-
* ')]
25+
summary: Send webcam reward
26+
')]
2727
final class MultilineContent
2828
{
2929
}

‎rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/nested_quote.php.inc‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,9 @@ namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
2323
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
2424

2525
#[GenericAnnotation('
26-
* summary: key
27-
* description: \'something `id => name`.\'
28-
* ')]
26+
summary: key
27+
description: \'something `id => name`.\'
28+
')]
2929
final class NestedQuote
3030
{
3131
}

‎rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/Fixture/nested_quoted_asterisk.php.inc‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@ namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Fixture;
2525
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
2626

2727
#[GenericAnnotation('
28-
* key: value
29-
* another_key:
30-
* another_value/*:
31-
* schema: 100
32-
* ')]
28+
key: value
29+
another_key:
30+
another_value/*:
31+
schema: 100
32+
')]
3333
final class NestedQuote
3434
{
3535
}

‎rules-tests/Php80/Rector/Class_/AnnotationToAttributeRector/FixturePhp81/sql_statement.php.inc‎

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,11 @@ namespace Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\FixturePh
2828
use Rector\Tests\Php80\Rector\Class_\AnnotationToAttributeRector\Source\GenericAnnotation;
2929

3030
#[GenericAnnotation(filters: [new GenericAnnotation(some: '
31-
* $this.id IN(
32-
* SELECT id
33-
* FROM foo
34-
* WHERE bar = \'baz\'
35-
* )')])]
31+
$this.id IN(
32+
SELECT id
33+
FROM foo
34+
WHERE bar = \'baz\'
35+
)')])]
3636
class SqlStatement
3737
{
3838
}

‎src/PhpAttribute/AnnotationToAttributeMapper/StringNodeAnnotationToAttributeMapper.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\PhpAttribute\AnnotationToAttributeMapper;
66

7+
use Nette\Utils\Strings;
78
use PhpParser\Node\Scalar\String_;
89
use Rector\BetterPhpDocParser\PhpDoc\StringNode;
910
use Rector\NodeTypeResolver\Node\AttributeKey;
@@ -14,6 +15,11 @@
1415
*/
1516
final class StringNodeAnnotationToAttributeMapper implements AnnotationToAttributeMapperInterface
1617
{
18+
/**
19+
* The "*" at the start of each line of a multi-line string in a docblock
20+
*/
21+
private const string STAR_COMMENT_REGEX = '#^[ \t]*\*#m';
22+
1723
public function isCandidate(mixed $value): bool
1824
{
1925
return $value instanceof StringNode;
@@ -24,7 +30,7 @@ public function isCandidate(mixed $value): bool
2430
*/
2531
public function map($value): String_
2632
{
27-
return new String_($value->value, [
33+
return new String_(Strings::replace($value->value, self::STAR_COMMENT_REGEX), [
2834
AttributeKey::KIND => $value->getAttribute(AttributeKey::KIND),
2935
]);
3036
}

‎tests/Issues/PlainValueParser/Fixture/fixture.php.inc‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ use Rector\Tests\Issues\PlainValueParser\Source\CustomAnnotation;
2626
final class SomeFixture
2727
{
2828
#[CustomAnnotation(description: 'List of value:
29-
* - <b>TRY</b>: To try
30-
* - <b>TEST</b>: to test (Default if no parameters given)')]
29+
- <b>TRY</b>: To try
30+
- <b>TEST</b>: to test (Default if no parameters given)')]
3131
public function test()
3232
{}
3333
}

0 commit comments

Comments
 (0)