Skip to content

Commit 03329e0

Browse files
authored
[Commenting] Handle remove generated doctrine ORM comment (#61)
* [Commenting] Handle remove generated doctrine ORM comment * implemented
1 parent 5de5266 commit 03329e0

File tree

2 files changed

+34
-1
lines changed

2 files changed

+34
-1
lines changed

src/DocBlock/UselessDocBlockCleaner.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,12 @@ final class UselessDocBlockCleaner
6060
*/
6161
private const COMMENT_CONSTRUCTOR_CLASS_REGEX = '#^(\/\/|(\s|\*)+)(\s\w+\s)?constructor(\.)?$#i';
6262

63+
/**
64+
* @see https://regex101.com/r/1kcgR5/1
65+
* @var string
66+
*/
67+
private const DOCTRINE_GENERATED_COMMENT_REGEX = '#^(\/\*{2}\s+?)?(\*|\/\/)\s+This class was generated by the Doctrine ORM\. Add your own custom\r?\n\s+\*\s+repository methods below\.(\s+\*\/)$#';
68+
6369
public function clearDocTokenContent(Token $currentToken, ?string $classLikeName): string
6470
{
6571
$docContent = $currentToken->getContent();
@@ -87,7 +93,10 @@ public function clearDocTokenContent(Token $currentToken, ?string $classLikeName
8793
return '';
8894
}
8995

90-
return implode("\n", $cleanedCommentLines);
96+
$commentText = implode("\n", $cleanedCommentLines);
97+
98+
// run multilines regex on final result
99+
return Strings::replace($commentText, self::DOCTRINE_GENERATED_COMMENT_REGEX);
91100
}
92101

93102
/**
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;
4+
5+
/**
6+
* This class was generated by the Doctrine ORM. Add your own custom
7+
* repository methods below.
8+
*/
9+
class SomeClass1
10+
{
11+
}
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Symplify\CodingStandard\Tests\Fixer\Commenting\RemoveUselessDefaultCommentFixer\Fixture;
18+
19+
20+
class SomeClass1
21+
{
22+
}
23+
24+
?>

0 commit comments

Comments
 (0)