Skip to content

Commit

Permalink
Reduce private accessor usage on get parent class name not autoload (#…
Browse files Browse the repository at this point in the history
…4726)

* Reduce private accessor usage on get parent class name not autoload

* [ci-review] Rector Rectify

* [ci-review] Rector Rectify

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Aug 9, 2023
1 parent 662cbb9 commit ea91c99
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 3 deletions.
4 changes: 3 additions & 1 deletion packages/VendorLocker/ParentClassMethodTypeOverrideGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\VendorLocker;

use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\MethodReflection;
Expand Down Expand Up @@ -107,7 +108,8 @@ private function hasClassParent(ClassReflection $classReflection): bool
$nativeReflection,
'betterReflectionClass'
);
$parentClassName = $this->privatesAccessor->getPrivateProperty($betterReflectionClass, 'parentClassName');
/** @var ReflectionClass $betterReflectionClass */
$parentClassName = $betterReflectionClass->getParentClassName();
return $parentClassName !== null;
}
}
4 changes: 3 additions & 1 deletion rules/Privatization/Guard/ParentPropertyLookupGuard.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Privatization\Guard;

use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PhpParser\Node;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticPropertyFetch;
Expand Down Expand Up @@ -53,7 +54,8 @@ public function isLegal(Property $property, ?ClassReflection $classReflection):
$nativeReflection,
'betterReflectionClass'
);
$parentClassName = $this->privatesAccessor->getPrivateProperty($betterReflectionClass, 'parentClassName');
/** @var ReflectionClass $betterReflectionClass */
$parentClassName = $betterReflectionClass->getParentClassName();

if ($parentClassName === null) {
return true;
Expand Down
4 changes: 3 additions & 1 deletion src/PhpParser/Node/Value/ValueResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\Core\PhpParser\Node\Value;

use PHPStan\BetterReflection\Reflection\ReflectionClass;
use PhpParser\ConstExprEvaluationException;
use PhpParser\ConstExprEvaluator;
use PhpParser\Node\Expr;
Expand Down Expand Up @@ -340,7 +341,8 @@ private function resolveClassFromSelfStaticParent(ClassConstFetch $classConstFet
$nativeReflection,
'betterReflectionClass'
);
$parentClassName = $this->privatesAccessor->getPrivateProperty($betterReflectionClass, 'parentClassName');
/** @var ReflectionClass $betterReflectionClass */
$parentClassName = $betterReflectionClass->getParentClassName();

if ($parentClassName === null) {
throw new ShouldNotHappenException();
Expand Down

0 comments on commit ea91c99

Please sign in to comment.