Updated Rector to commit 8615d40f4c8acb58a000f5bc7e0d0a0cfd353b7f

8615d40f4c [NodeTypeResolver] Handle nullable extended class on ->isObjectType() on DowngradeReflectionGetAttributesRector (#5224)
This commit is contained in:
Tomas Votruba 2023-11-05 13:58:20 +00:00
parent 37bf1c8f19
commit 1c5fde5d65
6 changed files with 17 additions and 22 deletions

View File

@ -386,7 +386,7 @@ final class NodeTypeResolver
if ($type instanceof ObjectWithoutClassType) {
return $this->isMatchObjectWithoutClassType($type, $requiredObjectType);
}
return $type->isSuperTypeOf($requiredObjectType)->yes();
return $requiredObjectType->isSuperTypeOf($type)->yes();
}
private function resolveByNodeTypeResolvers(Node $node) : ?Type
{

View File

@ -85,12 +85,7 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLa
$this->assertEmpty($rectorConfig->tagged(Collector::class));
$this->bootFromConfigFiles([$configFile]);
$rectorsGenerator = $rectorConfig->tagged(RectorInterface::class);
if ($rectorsGenerator instanceof RewindableGenerator) {
$rectors = \iterator_to_array($rectorsGenerator->getIterator());
} else {
// no rules at all, e.g. in case of only post rector run
$rectors = [];
}
$rectors = $rectorsGenerator instanceof RewindableGenerator ? \iterator_to_array($rectorsGenerator->getIterator()) : [];
/** @var RectorNodeTraverser $rectorNodeTraverser */
$rectorNodeTraverser = $rectorConfig->make(RectorNodeTraverser::class);
$rectorNodeTraverser->refreshPhpRectors($rectors);
@ -188,7 +183,7 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLa
$originalFileContent = FileSystem::read($originalFilePath);
// the file is now changed (if any rule matches)
$rectorTestResult = $this->processFilePath($originalFilePath);
$changedContent = $rectorTestResult->getChangedContents();
$changedContents = $rectorTestResult->getChangedContents();
$fixtureFilename = \basename($fixtureFilePath);
$failureMessage = \sprintf('Failed on fixture file "%s"', $fixtureFilename);
// give more context about used rules in case of set testing
@ -200,11 +195,11 @@ abstract class AbstractRectorTestCase extends \Rector\Testing\PHPUnit\AbstractLa
}
}
try {
$this->assertSame($expectedFileContents, $changedContent, $failureMessage);
$this->assertSame($expectedFileContents, $changedContents, $failureMessage);
} catch (ExpectationFailedException $exception) {
FixtureFileUpdater::updateFixtureContent($originalFileContent, $changedContent, $fixtureFilePath);
FixtureFileUpdater::updateFixtureContent($originalFileContent, $changedContents, $fixtureFilePath);
// if not exact match, check the regex version (useful for generated hashes/uuids in the code)
$this->assertStringMatchesFormat($expectedFileContents, $changedContent, $failureMessage);
$this->assertStringMatchesFormat($expectedFileContents, $changedContents, $failureMessage);
}
}
private function processFilePath(string $filePath) : RectorTestResult

View File

@ -58,7 +58,7 @@ final class PhpAttributeAnalyzer
$ancestorClassReflections = \array_merge($classReflection->getParents(), $classReflection->getInterfaces());
foreach ($ancestorClassReflections as $ancestorClassReflection) {
$nativeReflection = $ancestorClassReflection->getNativeReflection();
if ($nativeReflection->getAttributes($attributeClass) !== []) {
if ((\method_exists($nativeReflection, 'getAttributes') ? $nativeReflection->getAttributes($attributeClass) : []) !== []) {
return \true;
}
}

View File

@ -20,7 +20,7 @@ use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
* @see https://wiki.php.net/rfc/marking_overriden_methods
* @see \Rector\Tests\Php83\Rector\ClassMethod\AddOverrideAttributeToOverriddenMethodsRector\AddOverrideAttributeToOverriddenMethodsRectorTest
*/
class AddOverrideAttributeToOverriddenMethodsRector extends AbstractRector implements MinPhpVersionInterface
final class AddOverrideAttributeToOverriddenMethodsRector extends AbstractRector implements MinPhpVersionInterface
{
/**
* @readonly
@ -97,22 +97,22 @@ CODE_SAMPLE
// Fetch the parent class reflection
$parentClassReflection = $this->reflectionProvider->getClass((string) $node->extends);
$hasChanged = \false;
foreach ($node->getMethods() as $method) {
if ($method->name->toString() === '__construct') {
foreach ($node->getMethods() as $classMethod) {
if ($classMethod->name->toString() === '__construct') {
continue;
}
// Private methods should be ignored
if ($parentClassReflection->hasNativeMethod($method->name->toString())) {
if ($parentClassReflection->hasNativeMethod($classMethod->name->toString())) {
// ignore if it is a private method on the parent
$parentMethod = $parentClassReflection->getNativeMethod($method->name->toString());
$parentMethod = $parentClassReflection->getNativeMethod($classMethod->name->toString());
if ($parentMethod->isPrivate()) {
continue;
}
// ignore if it already uses the attribute
if ($this->phpAttributeAnalyzer->hasPhpAttribute($method, 'Override')) {
if ($this->phpAttributeAnalyzer->hasPhpAttribute($classMethod, 'Override')) {
continue;
}
$method->attrGroups[] = new AttributeGroup([new Attribute(new FullyQualified('Override'))]);
$classMethod->attrGroups[] = new AttributeGroup([new Attribute(new FullyQualified('Override'))]);
$hasChanged = \true;
}
}

View File

@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = '2ad03db37f187d715c3a2f189dc181063126e596';
public const PACKAGE_VERSION = '8615d40f4c8acb58a000f5bc7e0d0a0cfd353b7f';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-11-03 13:11:18';
public const RELEASE_DATE = '2023-11-05 20:55:04';
/**
* @var int
*/

View File

@ -31,7 +31,7 @@ final class Type
} elseif ($reflection instanceof \ReflectionMethod) {
$type = $reflection->getReturnType() ?? (\PHP_VERSION_ID >= 80100 ? $reflection->getTentativeReturnType() : null);
} else {
$type = $reflection instanceof \ReflectionFunctionAbstract ? $reflection->getReturnType() : (\method_exists($reflection, 'getType') ? $reflection->getType() : null);
$type = $reflection instanceof \ReflectionFunctionAbstract ? $reflection->getReturnType() : $reflection->getType();
}
return $type ? self::fromReflectionType($type, $reflection, \true) : null;
}