diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TagValueNodeReprintTest.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TagValueNodeReprintTest.php index ef17037f8ea..1f2e341eb93 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TagValueNodeReprintTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TagValueNodeReprintTest.php @@ -6,7 +6,6 @@ use Iterator; use Nette\Utils\FileSystem; -use Nette\Utils\Strings; use PhpParser\Comment\Doc; use PhpParser\Node; use PHPUnit\Framework\Attributes\DataProvider; @@ -17,17 +16,12 @@ use Rector\Core\PhpParser\Node\BetterNodeFinder; use Rector\FileSystemRector\Parser\FileInfoParser; use Rector\Testing\Fixture\FixtureFileFinder; +use Rector\Testing\Fixture\FixtureSplitter; use Rector\Testing\Fixture\FixtureTempFileDumper; use Rector\Testing\PHPUnit\AbstractLazyTestCase; final class TagValueNodeReprintTest extends AbstractLazyTestCase { - /** - * @var string - * @see https://regex101.com/r/0UHYBt/1 - */ - private const SPLIT_LINE_REGEX = "#-----\n#"; - private FileInfoParser $fileInfoParser; private BetterNodeFinder $betterNodeFinder; @@ -51,14 +45,9 @@ protected function setUp(): void #[DataProvider('provideDataNested')] public function test(string $filePath): void { - $fixtureFileContents = FileSystem::read($filePath); - - [$fileContents, $nodeClass, $tagValueNodeClasses] = Strings::split( - $fixtureFileContents, - self::SPLIT_LINE_REGEX - ); + [$fileContents, $nodeClass, $tagValueNodeClasses] = FixtureSplitter::split($filePath); - $nodeClass = trim((string) $nodeClass); + $nodeClass = trim($nodeClass); $tagValueNodeClasses = $this->splitListByEOL($tagValueNodeClasses); $fixtureFilePath = FixtureTempFileDumper::dump($fileContents); diff --git a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TestModifyReprintTest.php b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TestModifyReprintTest.php index e020510bcb1..adf4ff230f5 100644 --- a/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TestModifyReprintTest.php +++ b/packages-tests/BetterPhpDocParser/PhpDocParser/TagValueNodeReprint/TestModifyReprintTest.php @@ -59,7 +59,7 @@ public function test(): void ]); $doctrineAnnotationTagValueNode->values[] = new ArrayItemNode($methodsCurlyListNode, 'methods'); - $expectedDocContent = trim((string) $expectedContent); + $expectedDocContent = trim($expectedContent); $printedPhpDocInfo = $this->phpDocInfoPrinter->printFormatPreserving($phpDocInfo); $this->assertSame($expectedDocContent, $printedPhpDocInfo); diff --git a/packages-tests/Comments/CommentRemover/CommentRemoverTest.php b/packages-tests/Comments/CommentRemover/CommentRemoverTest.php index 3775d6dc504..395fd5d5d65 100644 --- a/packages-tests/Comments/CommentRemover/CommentRemoverTest.php +++ b/packages-tests/Comments/CommentRemover/CommentRemoverTest.php @@ -45,7 +45,7 @@ public function test(string $filePath): void $fileContent = $this->betterStandardPrinter->print($nodesWithoutComments); $fileContent = trim($fileContent); - $expectedContent = trim((string) $expectedOutputContents); + $expectedContent = trim($expectedOutputContents); $this->assertSame($fileContent, $expectedContent); // original nodes are not touched diff --git a/packages/Testing/Fixture/FixtureSplitter.php b/packages/Testing/Fixture/FixtureSplitter.php index 38a1320ff1d..2504a2308c4 100644 --- a/packages/Testing/Fixture/FixtureSplitter.php +++ b/packages/Testing/Fixture/FixtureSplitter.php @@ -4,40 +4,37 @@ namespace Rector\Testing\Fixture; use Nette\Utils\FileSystem; -use Nette\Utils\Strings; /** * @api */ final class FixtureSplitter { - /** - * @api - * @var string - * @see https://regex101.com/r/zZDoyy/1 - */ - public const SPLIT_LINE_REGEX = '#\-\-\-\-\-\r?\n#'; - public static function containsSplit(string $fixtureFileContent): bool { - return Strings::match($fixtureFileContent, self::SPLIT_LINE_REGEX) !== null; + return str_contains($fixtureFileContent, "-----\n") || str_contains($fixtureFileContent, "-----\r\n"); } /** - * @return array + * @return array */ public static function split(string $filePath): array { $fixtureFileContents = FileSystem::read($filePath); - return Strings::split($fixtureFileContents, self::SPLIT_LINE_REGEX); + return self::splitFixtureFileContents($fixtureFileContents); } /** - * @return array + * @return array */ public static function splitFixtureFileContents(string $fixtureFileContents): array { - return Strings::split($fixtureFileContents, self::SPLIT_LINE_REGEX); + $posixContents = explode("-----\n", $fixtureFileContents); + if (isset($posixContents[1])) { + return $posixContents; + } + + return explode("-----\r\n", $fixtureFileContents); } } diff --git a/rules/Naming/Matcher/ForeachMatcher.php b/rules/Naming/Matcher/ForeachMatcher.php index 3fdb33bbd89..fbb4ece98e4 100644 --- a/rules/Naming/Matcher/ForeachMatcher.php +++ b/rules/Naming/Matcher/ForeachMatcher.php @@ -24,7 +24,7 @@ public function __construct( public function match(Foreach_ $foreach, ClassMethod|Closure|Function_ $functionLike): ?VariableAndCallForeach { $call = $this->callMatcher->matchCall($foreach); - if (!$call instanceof Node) { + if (! $call instanceof Node) { return null; } diff --git a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php index d116c5ec237..04907493378 100644 --- a/rules/Naming/Matcher/VariableAndCallAssignMatcher.php +++ b/rules/Naming/Matcher/VariableAndCallAssignMatcher.php @@ -26,7 +26,7 @@ public function __construct( public function match(Assign $assign, ClassMethod|Closure|Function_ $functionLike): ?VariableAndCallAssign { $call = $this->callMatcher->matchCall($assign); - if (!$call instanceof Node) { + if (! $call instanceof Node) { return null; } diff --git a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php index e885e270c82..63a9f964685 100644 --- a/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php +++ b/rules/TypeDeclaration/Rector/ArrowFunction/AddArrowFunctionReturnTypeRector.php @@ -56,7 +56,7 @@ public function refactor(Node $node): ?Node } $returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN); - if (!$returnTypeNode instanceof Node) { + if (! $returnTypeNode instanceof Node) { return null; } diff --git a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php index 1ad48fc5aa7..ed3b55c0b91 100644 --- a/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php +++ b/rules/TypeDeclaration/Rector/Property/AddPropertyTypeDeclarationRector.php @@ -90,7 +90,7 @@ public function refactorWithScope(Node $node, Scope $scope): ?Node $addPropertyTypeDeclaration->getType(), TypeKind::PROPERTY ); - if (!$typeNode instanceof Node) { + if (! $typeNode instanceof Node) { // invalid configuration throw new ShouldNotHappenException(); } diff --git a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php index a1260455fc2..9863a266999 100644 --- a/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php +++ b/rules/TypeDeclaration/Rector/Property/TypedPropertyFromAssignsRector.php @@ -147,7 +147,7 @@ public function refactor(Node $node): ?Node $inferredType = $this->decorateTypeWithNullableIfDefaultPropertyNull($property, $inferredType); $typeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($inferredType, TypeKind::PROPERTY); - if (!$typeNode instanceof Node) { + if (! $typeNode instanceof Node) { continue; }