Skip to content

Commit

Permalink
Updated Rector to commit a6732a5b0e80868a6542c9bd5443f27750577e64
Browse files Browse the repository at this point in the history
rectorphp/rector-src@a6732a5 [FamilyTree] Remove AstResolver on FamilyRelationsAnalyzer (#5117)
  • Loading branch information
TomasVotruba committed Oct 5, 2023
1 parent a40e240 commit 9696ef6
Show file tree
Hide file tree
Showing 8 changed files with 28 additions and 32 deletions.
31 changes: 13 additions & 18 deletions packages/FamilyTree/Reflection/FamilyRelationsAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use PhpParser\Node\Stmt\Interface_;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\ReflectionProvider;
use Rector\Core\PhpParser\AstResolver;
use Rector\Core\Util\Reflection\PrivatesAccessor;
use Rector\NodeNameResolver\NodeNameResolver;
final class FamilyRelationsAnalyzer
Expand All @@ -28,17 +27,11 @@ final class FamilyRelationsAnalyzer
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\Core\PhpParser\AstResolver
*/
private $astResolver;
public function __construct(ReflectionProvider $reflectionProvider, PrivatesAccessor $privatesAccessor, NodeNameResolver $nodeNameResolver, AstResolver $astResolver)
public function __construct(ReflectionProvider $reflectionProvider, PrivatesAccessor $privatesAccessor, NodeNameResolver $nodeNameResolver)
{
$this->reflectionProvider = $reflectionProvider;
$this->privatesAccessor = $privatesAccessor;
$this->nodeNameResolver = $nodeNameResolver;
$this->astResolver = $astResolver;
}
/**
* @return ClassReflection[]
Expand Down Expand Up @@ -69,22 +62,24 @@ public function getClassLikeAncestorNames($classOrName) : array
$ancestorNames = [];
if ($classOrName instanceof Name) {
$fullName = $this->nodeNameResolver->getName($classOrName);
$classLike = $this->astResolver->resolveClassFromName($fullName);
} else {
$classLike = $classOrName;
$classReflection = $this->reflectionProvider->getClass($fullName);
$ancestors = \array_merge($classReflection->getParents(), $classReflection->getInterfaces());
return \array_map(static function (ClassReflection $classReflection) : string {
return $classReflection->getName();
}, $ancestors);
}
if ($classLike instanceof Interface_) {
foreach ($classLike->extends as $extendInterfaceName) {
if ($classOrName instanceof Interface_) {
foreach ($classOrName->extends as $extendInterfaceName) {
$ancestorNames[] = $this->nodeNameResolver->getName($extendInterfaceName);
$ancestorNames = \array_merge($ancestorNames, $this->getClassLikeAncestorNames($extendInterfaceName));
}
}
if ($classLike instanceof Class_) {
if ($classLike->extends instanceof Name) {
$ancestorNames[] = $this->nodeNameResolver->getName($classLike->extends);
$ancestorNames = \array_merge($ancestorNames, $this->getClassLikeAncestorNames($classLike->extends));
if ($classOrName instanceof Class_) {
if ($classOrName->extends instanceof Name) {
$ancestorNames[] = $this->nodeNameResolver->getName($classOrName->extends);
$ancestorNames = \array_merge($ancestorNames, $this->getClassLikeAncestorNames($classOrName->extends));
}
foreach ($classLike->implements as $implement) {
foreach ($classOrName->implements as $implement) {
$ancestorNames[] = $this->nodeNameResolver->getName($implement);
$ancestorNames = \array_merge($ancestorNames, $this->getClassLikeAncestorNames($implement));
}
Expand Down
10 changes: 5 additions & 5 deletions rules/Php80/Rector/Class_/StringableForToStringRector.php
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ public function refactor(Node $node) : ?Node
// warning, classes that implements __toString() will return Stringable interface even if they don't implemen it
// reflection cannot be used for real detection
$classLikeAncestorNames = $this->familyRelationsAnalyzer->getClassLikeAncestorNames($node);
if (\in_array(self::STRINGABLE, $classLikeAncestorNames, \true)) {
return null;
}
$isAncestorHasStringable = \in_array(self::STRINGABLE, $classLikeAncestorNames, \true);
$returnType = $this->returnTypeInferer->inferFunctionLike($toStringClassMethod);
if (!$returnType->isString()->yes()) {
$this->processNotStringType($toStringClassMethod);
}
// add interface
$node->implements[] = new FullyQualified(self::STRINGABLE);
if (!$isAncestorHasStringable) {
// add interface
$node->implements[] = new FullyQualified(self::STRINGABLE);
}
// add return type
if ($toStringClassMethod->returnType === null) {
$toStringClassMethod->returnType = new Identifier('string');
Expand Down
4 changes: 2 additions & 2 deletions src/Application/VersionResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,12 @@ final class VersionResolver
* @api
* @var string
*/
public const PACKAGE_VERSION = 'a0f2f32c7970d925681fc4cec64efa1ee90b6ea8';
public const PACKAGE_VERSION = 'a6732a5b0e80868a6542c9bd5443f27750577e64';
/**
* @api
* @var string
*/
public const RELEASE_DATE = '2023-10-05 12:35:58';
public const RELEASE_DATE = '2023-10-05 14:30:52';
/**
* @var int
*/
Expand Down
1 change: 1 addition & 0 deletions src/PhpParser/AstResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ public function __construct(SmartPhpParser $smartPhpParser, NodeScopeAndMetadata
$this->methodReflectionResolver = $methodReflectionResolver;
}
/**
* @api downgrade
* @return \PhpParser\Node\Stmt\Class_|\PhpParser\Node\Stmt\Trait_|\PhpParser\Node\Stmt\Interface_|\PhpParser\Node\Stmt\Enum_|null
*/
public function resolveClassFromName(string $className)
Expand Down
8 changes: 4 additions & 4 deletions vendor/composer/installed.json
Original file line number Diff line number Diff line change
Expand Up @@ -1879,12 +1879,12 @@
"source": {
"type": "git",
"url": "https:\/\/github.com\/rectorphp\/rector-symfony.git",
"reference": "24ea3ecd82cfab1d040bed6c0cd7a0cf69a11a85"
"reference": "873458ca73a73f9becd1680963a347bbcb8e5f43"
},
"dist": {
"type": "zip",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/24ea3ecd82cfab1d040bed6c0cd7a0cf69a11a85",
"reference": "24ea3ecd82cfab1d040bed6c0cd7a0cf69a11a85",
"url": "https:\/\/api.github.com\/repos\/rectorphp\/rector-symfony\/zipball\/873458ca73a73f9becd1680963a347bbcb8e5f43",
"reference": "873458ca73a73f9becd1680963a347bbcb8e5f43",
"shasum": ""
},
"require": {
Expand Down Expand Up @@ -1917,7 +1917,7 @@
"tomasvotruba\/unused-public": "^0.2",
"tracy\/tracy": "^2.10"
},
"time": "2023-10-01T11:40:39+00:00",
"time": "2023-10-05T05:47:32+00:00",
"default-branch": true,
"type": "rector-extension",
"extra": {
Expand Down
2 changes: 1 addition & 1 deletion vendor/composer/installed.php

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion vendor/rector/extension-installer/src/GeneratedConfig.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*/
final class GeneratedConfig
{
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a846e7f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 850b492'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 383d079'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 24ea3ec'));
public const EXTENSIONS = array('rector/rector-doctrine' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-doctrine', 'relative_install_path' => '../../rector-doctrine', 'extra' => NULL, 'version' => 'dev-main a846e7f'), 'rector/rector-downgrade-php' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-downgrade-php', 'relative_install_path' => '../../rector-downgrade-php', 'extra' => NULL, 'version' => 'dev-main 850b492'), 'rector/rector-phpunit' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-phpunit', 'relative_install_path' => '../../rector-phpunit', 'extra' => NULL, 'version' => 'dev-main 383d079'), 'rector/rector-symfony' => array('install_path' => '/home/runner/work/rector-src/rector-src/rector-build/vendor/rector/rector-symfony', 'relative_install_path' => '../../rector-symfony', 'extra' => NULL, 'version' => 'dev-main 873458c'));
private function __construct()
{
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ private function decorateCommandConstructor(Class_ $class) : void
return;
}
// empty stmts? add parent::__construct() to setup command
if (\count((array) $constuctClassMethod->stmts) === 0) {
if ((array) $constuctClassMethod->stmts === []) {
$parentConstructStaticCall = new StaticCall(new Name('parent'), '__construct');
$constuctClassMethod->stmts[] = new Expression($parentConstructStaticCall);
}
Expand Down

0 comments on commit 9696ef6

Please sign in to comment.