Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[StaticReflection] Fix unintended behavior in PHP 8.1 and later #3340

Merged
merged 4 commits into from
Feb 6, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 7 additions & 0 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -708,6 +708,13 @@ parameters:
count: 2
path: src/Rector/AbstractRector.php

-
message: """
#Function "class_exists\\(\\)" cannot be used/left in the code\\: use ReflectionProvider\\->has\\*\\(\\) instead#
"""
count: 1
path: src/StaticReflection/SourceLocator/RenamedClassesSourceLocator.php

-
message: """
#^Fetching class constant class of deprecated class Rector\\\\TypeDeclaration\\\\Rector\\\\FunctionLike\\\\ReturnTypeDeclarationRector\\:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\FixtureRenameMissingParent;

use Missing\ParentClass;

class MissingParent extends ParentClass
{
public function foo(): void
{
}
}

?>
-----
<?php

declare(strict_types=1);

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector\FixtureRenameMissingParent;

use Missing\ParentClass;

class MissingParent extends \Renamed\Missing\ParentWithMethod
{
public function foo(): void
{
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\Renaming\Rector\Name\RenameClassRector;

use Iterator;
use PHPUnit\Framework\Attributes\DataProvider;
use Rector\Renaming\Rector\Name\RenameClassRector;
use Rector\Testing\PHPUnit\AbstractRectorTestCase;

/**
* @see RenameClassRector
*/
final class RenameMissingParentTest extends AbstractRectorTestCase
{
#[DataProvider('provideData')]
public function test(string $filePath): void
{
$this->doTestFile($filePath);
}

public static function provideData(): Iterator
{
return self::yieldFilesFromDirectory(__DIR__ . '/FixtureRenameMissingParent');
}

public function provideConfigFilePath(): string
{
return __DIR__ . '/config/rename_missing_parent.php';
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

declare(strict_types=1);

use Rector\Config\RectorConfig;
use Rector\Renaming\Rector\Name\RenameClassRector;

return static function (RectorConfig $rectorConfig): void {
$rectorConfig
->ruleWithConfiguration(RenameClassRector::class, [
'Missing\\ParentClass' => 'Renamed\\Missing\\ParentWithMethod',
]);
};
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public function locateIdentifier(Reflector $reflector, Identifier $identifier):
continue;
}

/* Use ReflectionProvider causes infinite loop */
if (!class_exists($oldClass)) {
continue;
}

return $this->createFakeReflectionClassFromClassName($oldClass);
}

Expand Down