Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 10 additions & 13 deletions packages/Testing/Fixture/FixtureSplitter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, string>
* @return array<int, string>
*/
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<string, string>
* @return array<int, string>
*/
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);
}
}
2 changes: 1 addition & 1 deletion rules/Naming/Matcher/ForeachMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion rules/Naming/Matcher/VariableAndCallAssignMatcher.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down