-
-
Notifications
You must be signed in to change notification settings - Fork 697
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Rector to commit ed16cab5a2fa6982539e06ad70ac9c119c7dc346
rectorphp/rector-src@ed16cab [Php80] Add typed property Closure support on ClassPropertyAssignToConstructorPromotionRector (#3453)
- Loading branch information
1 parent
b66a828
commit 57f48de
Showing
7 changed files
with
105 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/StaticReflection/SourceLocator/RenamedClassesSourceLocator.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace Rector\Core\StaticReflection\SourceLocator; | ||
|
||
use PhpParser\Builder\Class_; | ||
use PHPStan\BetterReflection\Identifier\Identifier; | ||
use PHPStan\BetterReflection\Identifier\IdentifierType; | ||
use PHPStan\BetterReflection\Reflection\Reflection; | ||
use PHPStan\BetterReflection\Reflection\ReflectionClass; | ||
use PHPStan\BetterReflection\Reflector\Reflector; | ||
use PHPStan\BetterReflection\SourceLocator\Type\SourceLocator; | ||
use Rector\Core\Configuration\RenamedClassesDataCollector; | ||
/** | ||
* Inspired from \PHPStan\BetterReflection\SourceLocator\Type\StringSourceLocator | ||
*/ | ||
final class RenamedClassesSourceLocator implements SourceLocator | ||
{ | ||
/** | ||
* @readonly | ||
* @var \Rector\Core\Configuration\RenamedClassesDataCollector | ||
*/ | ||
private $renamedClassesDataCollector; | ||
public function __construct(RenamedClassesDataCollector $renamedClassesDataCollector) | ||
{ | ||
$this->renamedClassesDataCollector = $renamedClassesDataCollector; | ||
} | ||
public function locateIdentifier(Reflector $reflector, Identifier $identifier) : ?Reflection | ||
{ | ||
if (!$identifier->isClass()) { | ||
return null; | ||
} | ||
$identifierName = $identifier->getName(); | ||
foreach ($this->renamedClassesDataCollector->getOldClasses() as $oldClass) { | ||
if ($identifierName !== $oldClass) { | ||
continue; | ||
} | ||
/* Use ReflectionProvider causes infinite loop */ | ||
if (!\class_exists($oldClass)) { | ||
continue; | ||
} | ||
return $this->createFakeReflectionClassFromClassName($oldClass); | ||
} | ||
return null; | ||
} | ||
/** | ||
* @return array<int, Reflection> | ||
*/ | ||
public function locateIdentifiersByType(Reflector $reflector, IdentifierType $identifierType) : array | ||
{ | ||
return []; | ||
} | ||
private function createFakeReflectionClassFromClassName(string $oldClass) : ReflectionClass | ||
{ | ||
$classBuilder = new Class_($oldClass); | ||
$class = $classBuilder->getNode(); | ||
return ReflectionClass::createFromInstance($class); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters