Skip to content

Commit

Permalink
[BetterPhpDocParser] Move split new line with @\ to regex to support …
Browse files Browse the repository at this point in the history
…windows new line (#5615)

* [BetterPhpDocParser] Move split new line with @\ to regex to support windows new line

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Feb 13, 2024
1 parent 95f9772 commit 539cfeb
Showing 1 changed file with 9 additions and 3 deletions.
Expand Up @@ -44,6 +44,12 @@
*/
private const NESTED_ANNOTATION_END_REGEX = '#(\s+)?\}\)(\s+)?#';

/**
* @see https://regex101.com/r/8rWY4r/1
* @var string
*/
private const NEWLINE_ANNOTATION_FQCN_REGEX = '#\r?\n@\\\\#';

public function __construct(
private ClassAnnotationMatcher $classAnnotationMatcher,
private StaticDoctrineAnnotationParser $staticDoctrineAnnotationParser,
Expand Down Expand Up @@ -166,10 +172,10 @@ private function processTextSpacelessInTextNode(
return;
}

$texts = explode("\n@\\", $phpDocTextNode->text);
$texts = Strings::split($phpDocTextNode->text, self::NEWLINE_ANNOTATION_FQCN_REGEX);
$otherText = $texts[0];

if (! str_starts_with($otherText, '@\\') && trim($otherText) !== '') {
if (! str_starts_with((string) $otherText, '@\\') && trim((string) $otherText) !== '') {
$phpDocNode->children[$key] = new PhpDocTextNode($otherText);
array_splice($phpDocNode->children, $key + 1, 0, $spacelessPhpDocTagNodes);

Expand Down Expand Up @@ -263,7 +269,7 @@ private function transformGenericTagValueNodesToDoctrineAnnotationTagValueNodes(

Assert::isAOf($phpDocNode->children[$key], PhpDocTagNode::class);

$texts = explode("\n@\\", $phpDocChildNode->value->value);
$texts = Strings::split($phpDocChildNode->value->value, self::NEWLINE_ANNOTATION_FQCN_REGEX);
$phpDocNode->children[$key]->value = new GenericTagValueNode($texts[0]);
$phpDocNode->children[$key]->value->setAttribute(PhpDocAttributeKey::START_AND_END, $startAndEnd);

Expand Down

0 comments on commit 539cfeb

Please sign in to comment.