diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 12deeefaa82..3154a4f5ba1 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '7e741fee0551af70bb6b3f45c95905fdf9d618ce'; + public const PACKAGE_VERSION = '290926cc8b93331dd715d7ea061847dafbc1821a'; /** * @api * @var string */ - public const RELEASE_DATE = '2024-02-21 22:15:12'; + public const RELEASE_DATE = '2024-02-21 15:28:36'; /** * @var int */ diff --git a/src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php b/src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php index 0979726e548..8862737d880 100644 --- a/src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php +++ b/src/BetterPhpDocParser/PhpDocParser/StaticDoctrineAnnotationParser.php @@ -3,7 +3,6 @@ declare (strict_types=1); namespace Rector\BetterPhpDocParser\PhpDocParser; -use RectorPrefix202402\Nette\Utils\Strings; use PhpParser\Node; use PHPStan\PhpDocParser\Ast\ConstExpr\ConstExprNode; use PHPStan\PhpDocParser\Lexer\Lexer; @@ -14,6 +13,7 @@ use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayP use Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\PlainValueParser; use Rector\BetterPhpDocParser\ValueObject\Parser\BetterTokenIterator; use Rector\BetterPhpDocParser\ValueObject\PhpDoc\DoctrineAnnotation\CurlyListNode; +use Rector\Util\NewLineSplitter; /** * Better version of doctrine/annotation - with phpdoc-parser and static reflection * @see \Rector\Tests\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\StaticDoctrineAnnotationParserTest @@ -30,11 +30,6 @@ final class StaticDoctrineAnnotationParser * @var \Rector\BetterPhpDocParser\PhpDocParser\StaticDoctrineAnnotationParser\ArrayParser */ private $arrayParser; - /** - * @var string - * @see https://regex101.com/r/aU2knc/1 - */ - private const NEWLINES_REGEX = "#\r?\n#"; /** * @var string * @see https://regex101.com/r/Pthg5d/1 @@ -96,7 +91,7 @@ final class StaticDoctrineAnnotationParser // the remaining of the annotation content is the comment $comment = \substr($annotationContent, $tokenIterator->currentTokenOffset()); // we only keep the first line as this will be added as a line comment at the end of the attribute - $commentLines = Strings::split($comment, self::NEWLINES_REGEX); + $commentLines = NewLineSplitter::split($comment); return $commentLines[0]; } /** diff --git a/src/Console/Formatter/ColorConsoleDiffFormatter.php b/src/Console/Formatter/ColorConsoleDiffFormatter.php index c3cfe7f897e..f55fcd74c9e 100644 --- a/src/Console/Formatter/ColorConsoleDiffFormatter.php +++ b/src/Console/Formatter/ColorConsoleDiffFormatter.php @@ -4,6 +4,7 @@ declare (strict_types=1); namespace Rector\Console\Formatter; use RectorPrefix202402\Nette\Utils\Strings; +use Rector\Util\NewLineSplitter; use RectorPrefix202402\Symfony\Component\Console\Formatter\OutputFormatter; /** * Inspired by @see https://github.com/FriendsOfPHP/PHP-CS-Fixer/blob/master/src/Differ/DiffConsoleFormatter.php to be @@ -28,11 +29,6 @@ final class ColorConsoleDiffFormatter * @see https://regex101.com/r/CMlwa8/1 */ private const AT_START_REGEX = '#^(@.*)#'; - /** - * @var string - * @see https://regex101.com/r/qduj2O/1 - */ - private const NEWLINES_REGEX = "#\n\r|\n#"; /** * @readonly * @var string @@ -49,7 +45,7 @@ final class ColorConsoleDiffFormatter private function formatWithTemplate(string $diff, string $template) : string { $escapedDiff = OutputFormatter::escape(\rtrim($diff)); - $escapedDiffLines = Strings::split($escapedDiff, self::NEWLINES_REGEX); + $escapedDiffLines = NewLineSplitter::split($escapedDiff); // remove description of added + remove; obvious on diffs foreach ($escapedDiffLines as $key => $escapedDiffLine) { if ($escapedDiffLine === '--- Original') { diff --git a/src/PhpParser/Printer/BetterStandardPrinter.php b/src/PhpParser/Printer/BetterStandardPrinter.php index e0b25e83caf..d58c7bc9409 100644 --- a/src/PhpParser/Printer/BetterStandardPrinter.php +++ b/src/PhpParser/Printer/BetterStandardPrinter.php @@ -3,6 +3,7 @@ declare (strict_types=1); namespace Rector\PhpParser\Printer; +use PhpParser\Node\AttributeGroup; use RectorPrefix202402\Nette\Utils\Strings; use PhpParser\Comment; use PhpParser\Node; @@ -113,10 +114,10 @@ final class BetterStandardPrinter extends Standard $content = parent::p($node, $parentFormatPreserved); return $node->getAttribute(AttributeKey::WRAPPED_IN_PARENTHESES) === \true ? '(' . $content . ')' : $content; } - protected function pAttributeGroup(Node\AttributeGroup $node) : string + protected function pAttributeGroup(AttributeGroup $attributeGroup) : string { - $ret = parent::pAttributeGroup($node); - $comment = $node->getAttribute(AttributeKey::ATTRIBUTE_COMMENT); + $ret = parent::pAttributeGroup($attributeGroup); + $comment = $attributeGroup->getAttribute(AttributeKey::ATTRIBUTE_COMMENT); if (!\in_array($comment, ['', null], \true)) { $ret .= ' // ' . $comment; } diff --git a/src/Util/NewLineSplitter.php b/src/Util/NewLineSplitter.php new file mode 100644 index 00000000000..c0a8cd857ce --- /dev/null +++ b/src/Util/NewLineSplitter.php @@ -0,0 +1,21 @@ + $baseDir . '/src/Util/ArrayParametersMerger.php', 'Rector\\Util\\FileHasher' => $baseDir . '/src/Util/FileHasher.php', 'Rector\\Util\\MemoryLimiter' => $baseDir . '/src/Util/MemoryLimiter.php', + 'Rector\\Util\\NewLineSplitter' => $baseDir . '/src/Util/NewLineSplitter.php', 'Rector\\Util\\PhpVersionFactory' => $baseDir . '/src/Util/PhpVersionFactory.php', 'Rector\\Util\\Reflection\\PrivatesAccessor' => $baseDir . '/src/Util/Reflection/PrivatesAccessor.php', 'Rector\\Util\\StringUtils' => $baseDir . '/src/Util/StringUtils.php', diff --git a/vendor/composer/autoload_static.php b/vendor/composer/autoload_static.php index f870af5d75f..bd519ac65de 100644 --- a/vendor/composer/autoload_static.php +++ b/vendor/composer/autoload_static.php @@ -2641,6 +2641,7 @@ class ComposerStaticInit2d887a2f87c676eb32b3e04612865e54 'Rector\\Util\\ArrayParametersMerger' => __DIR__ . '/../..' . '/src/Util/ArrayParametersMerger.php', 'Rector\\Util\\FileHasher' => __DIR__ . '/../..' . '/src/Util/FileHasher.php', 'Rector\\Util\\MemoryLimiter' => __DIR__ . '/../..' . '/src/Util/MemoryLimiter.php', + 'Rector\\Util\\NewLineSplitter' => __DIR__ . '/../..' . '/src/Util/NewLineSplitter.php', 'Rector\\Util\\PhpVersionFactory' => __DIR__ . '/../..' . '/src/Util/PhpVersionFactory.php', 'Rector\\Util\\Reflection\\PrivatesAccessor' => __DIR__ . '/../..' . '/src/Util/Reflection/PrivatesAccessor.php', 'Rector\\Util\\StringUtils' => __DIR__ . '/../..' . '/src/Util/StringUtils.php',