File: /home/boxelikax/public_html/demoltec.com/NodeAnalyzer.zip
PK �n]�'�� � ScopeAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Param;
final class ScopeAnalyzer
{
/**
* @var array<class-string<Node>>
*/
private const NON_REFRESHABLE_NODES = [Name::class, Identifier::class, Param::class, Arg::class, Variable::class];
public function isRefreshable(Node $node) : bool
{
foreach (self::NON_REFRESHABLE_NODES as $noScopeNode) {
if ($node instanceof $noScopeNode) {
return \false;
}
}
return \true;
}
}
PK �n]fYįz z ExprAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\ClassConstFetch;
use PhpParser\Node\Expr\ConstFetch;
use PhpParser\Node\Expr\UnaryMinus;
use PhpParser\Node\Expr\UnaryPlus;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Identifier;
use PhpParser\Node\Name;
use PhpParser\Node\Scalar;
use PhpParser\Node\Scalar\Encapsed;
use PhpParser\Node\Scalar\LNumber;
use PhpParser\Node\Scalar\String_;
use PHPStan\Analyser\Scope;
use PHPStan\Type\MixedType;
use PHPStan\Type\ObjectWithoutClassType;
use PHPStan\Type\UnionType;
use Rector\Enum\ObjectReference;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class ExprAnalyzer
{
public function isNonTypedFromParam(Expr $expr) : bool
{
if (!$expr instanceof Variable) {
return \false;
}
$scope = $expr->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
// uncertainty when scope not yet filled/overlapped on just refactored
return \true;
}
$nativeType = $scope->getNativeType($expr);
if ($nativeType instanceof MixedType && !$nativeType->isExplicitMixed()) {
return \true;
}
$type = $scope->getType($expr);
if ($nativeType instanceof ObjectWithoutClassType && !$type instanceof ObjectWithoutClassType) {
return \true;
}
if ($nativeType instanceof UnionType) {
return !$nativeType->equals($type);
}
return !$nativeType->isSuperTypeOf($type)->yes();
}
public function isDynamicExpr(Expr $expr) : bool
{
// Unwrap UnaryPlus and UnaryMinus
if ($expr instanceof UnaryPlus || $expr instanceof UnaryMinus) {
$expr = $expr->expr;
}
if ($expr instanceof Array_) {
return $this->isDynamicArray($expr);
}
if ($expr instanceof Scalar) {
// string interpolation is true, otherwise false
return $expr instanceof Encapsed;
}
return !$this->isAllowedConstFetchOrClassConstFetch($expr);
}
public function isDynamicArray(Array_ $array) : bool
{
foreach ($array->items as $item) {
if (!$item instanceof ArrayItem) {
continue;
}
if (!$this->isAllowedArrayKey($item->key)) {
return \true;
}
if (!$this->isAllowedArrayValue($item->value)) {
return \true;
}
}
return \false;
}
private function isAllowedConstFetchOrClassConstFetch(Expr $expr) : bool
{
if ($expr instanceof ConstFetch) {
return \true;
}
if ($expr instanceof ClassConstFetch) {
if (!$expr->class instanceof Name) {
return \false;
}
if (!$expr->name instanceof Identifier) {
return \false;
}
// static::class cannot be used for compile-time class name resolution
return $expr->class->toString() !== ObjectReference::STATIC;
}
return \false;
}
private function isAllowedArrayKey(?Expr $expr) : bool
{
if (!$expr instanceof Expr) {
return \true;
}
if ($expr instanceof String_) {
return \true;
}
return $expr instanceof LNumber;
}
private function isAllowedArrayValue(Expr $expr) : bool
{
if ($expr instanceof Array_) {
return !$this->isDynamicArray($expr);
}
return !$this->isDynamicExpr($expr);
}
}
PK �n]j�5? ? CompactFuncCallAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\Expr\Array_;
use PhpParser\Node\Expr\ArrayItem;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Scalar\String_;
use PhpParser\Node\VariadicPlaceholder;
use Rector\NodeNameResolver\NodeNameResolver;
final class CompactFuncCallAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
public function isInCompact(FuncCall $funcCall, Variable $variable) : bool
{
if (!$this->nodeNameResolver->isName($funcCall, 'compact')) {
return \false;
}
if (!\is_string($variable->name)) {
return \false;
}
return $this->isInArgOrArrayItemNodes($funcCall->args, $variable->name);
}
/**
* @param array<int, Arg|VariadicPlaceholder|ArrayItem|null> $nodes
*/
private function isInArgOrArrayItemNodes(array $nodes, string $variableName) : bool
{
foreach ($nodes as $node) {
if ($this->shouldSkip($node)) {
continue;
}
/** @var Arg|ArrayItem $node */
if ($node->value instanceof Array_) {
if ($this->isInArgOrArrayItemNodes($node->value->items, $variableName)) {
return \true;
}
continue;
}
if (!$node->value instanceof String_) {
continue;
}
if ($node->value->value === $variableName) {
return \true;
}
}
return \false;
}
/**
* @param \PhpParser\Node\Arg|\PhpParser\Node\VariadicPlaceholder|\PhpParser\Node\Expr\ArrayItem|null $node
*/
private function shouldSkip($node) : bool
{
if ($node === null) {
return \true;
}
return $node instanceof VariadicPlaceholder;
}
}
PK �n]�;�*� � ClassAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Stmt\Class_;
final class ClassAnalyzer
{
public function isAnonymousClass(Node $node) : bool
{
if ($node instanceof New_) {
return $this->isAnonymousClass($node->class);
}
if ($node instanceof Class_) {
return $node->isAnonymous();
}
return \false;
}
}
PK �n]�6��[ [ VariableAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Expr\Variable;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class VariableAnalyzer
{
public function isStaticOrGlobal(Variable $variable) : bool
{
if ($variable->getAttribute(AttributeKey::IS_GLOBAL_VAR) === \true) {
return \true;
}
return $variable->getAttribute(AttributeKey::IS_STATIC_VAR) === \true;
}
public function isUsedByReference(Variable $variable) : bool
{
return $variable->getAttribute(AttributeKey::IS_BYREF_VAR) === \true;
}
}
PK �n]XPS TerminatedNodeAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\Exit_;
use PhpParser\Node\Stmt;
use PhpParser\Node\Stmt\Break_;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\Continue_;
use PhpParser\Node\Stmt\Else_;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Finally_;
use PhpParser\Node\Stmt\Function_;
use PhpParser\Node\Stmt\Goto_;
use PhpParser\Node\Stmt\If_;
use PhpParser\Node\Stmt\InlineHTML;
use PhpParser\Node\Stmt\Label;
use PhpParser\Node\Stmt\Namespace_;
use PhpParser\Node\Stmt\Nop;
use PhpParser\Node\Stmt\Return_;
use PhpParser\Node\Stmt\Switch_;
use PhpParser\Node\Stmt\Throw_;
use PhpParser\Node\Stmt\TryCatch;
use Rector\Contract\PhpParser\Node\StmtsAwareInterface;
use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace;
final class TerminatedNodeAnalyzer
{
/**
* @var array<class-string<Node>>
*/
private const TERMINATED_NODES = [Return_::class, Throw_::class];
/**
* @var array<class-string<Node>>
*/
private const TERMINABLE_NODES = [Throw_::class, Return_::class, Break_::class, Continue_::class];
/**
* @var array<class-string<Node>>
*/
private const TERMINABLE_NODES_BY_ITS_STMTS = [TryCatch::class, If_::class, Switch_::class];
/**
* @var array<class-string<Node>>
*/
private const ALLOWED_CONTINUE_CURRENT_STMTS = [InlineHTML::class, Nop::class];
public function isAlwaysTerminated(StmtsAwareInterface $stmtsAware, Stmt $node, Stmt $currentStmt) : bool
{
if (\in_array(\get_class($currentStmt), self::ALLOWED_CONTINUE_CURRENT_STMTS, \true)) {
return \false;
}
if (($stmtsAware instanceof FileWithoutNamespace || $stmtsAware instanceof Namespace_) && ($currentStmt instanceof ClassLike || $currentStmt instanceof Function_)) {
return \false;
}
if (!\in_array(\get_class($node), self::TERMINABLE_NODES_BY_ITS_STMTS, \true)) {
return $this->isTerminatedNode($node, $currentStmt);
}
if ($node instanceof TryCatch) {
return $this->isTerminatedInLastStmtsTryCatch($node, $currentStmt);
}
if ($node instanceof If_) {
return $this->isTerminatedInLastStmtsIf($node, $currentStmt);
}
/** @var Switch_ $node */
return $this->isTerminatedInLastStmtsSwitch($node, $currentStmt);
}
private function isTerminatedNode(Node $previousNode, Node $currentStmt) : bool
{
if (\in_array(\get_class($previousNode), self::TERMINABLE_NODES, \true)) {
return \true;
}
if ($previousNode instanceof Expression && $previousNode->expr instanceof Exit_) {
return \true;
}
if ($previousNode instanceof Goto_) {
return !$currentStmt instanceof Label;
}
return \false;
}
private function isTerminatedInLastStmtsSwitch(Switch_ $switch, Stmt $stmt) : bool
{
if ($switch->cases === []) {
return \false;
}
$hasDefault = \false;
foreach ($switch->cases as $key => $case) {
if (!$case->cond instanceof Expr) {
$hasDefault = \true;
}
if ($case->stmts === [] && isset($switch->cases[$key + 1])) {
continue;
}
if (!$this->isTerminatedInLastStmts($case->stmts, $stmt)) {
return \false;
}
}
return $hasDefault;
}
private function isTerminatedInLastStmtsTryCatch(TryCatch $tryCatch, Stmt $stmt) : bool
{
if ($tryCatch->finally instanceof Finally_ && $this->isTerminatedInLastStmts($tryCatch->finally->stmts, $stmt)) {
return \true;
}
foreach ($tryCatch->catches as $catch) {
if (!$this->isTerminatedInLastStmts($catch->stmts, $stmt)) {
return \false;
}
}
return $this->isTerminatedInLastStmts($tryCatch->stmts, $stmt);
}
private function isTerminatedInLastStmtsIf(If_ $if, Stmt $stmt) : bool
{
// Without ElseIf_[] and Else_, after If_ is possibly executable
if ($if->elseifs === [] && !$if->else instanceof Else_) {
return \false;
}
foreach ($if->elseifs as $elseif) {
if (!$this->isTerminatedInLastStmts($elseif->stmts, $stmt)) {
return \false;
}
}
if (!$this->isTerminatedInLastStmts($if->stmts, $stmt)) {
return \false;
}
if (!$if->else instanceof Else_) {
return \false;
}
return $this->isTerminatedInLastStmts($if->else->stmts, $stmt);
}
/**
* @param Stmt[] $stmts
*/
private function isTerminatedInLastStmts(array $stmts, Node $node) : bool
{
if ($stmts === []) {
return \false;
}
\end($stmts);
$lastKey = \key($stmts);
\reset($stmts);
$lastNode = $stmts[$lastKey];
if (isset($stmts[$lastKey - 1]) && $this->isTerminatedNode($stmts[$lastKey - 1], $node)) {
return \false;
}
if ($lastNode instanceof Expression) {
return $lastNode->expr instanceof Exit_;
}
return \in_array(\get_class($lastNode), self::TERMINATED_NODES, \true);
}
}
PK �n]ox� � PropertyFetchAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafePropertyFetch;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\StaticPropertyFetch;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Name;
use PhpParser\Node\Stmt\ClassLike;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Expression;
use PhpParser\Node\Stmt\Property;
use PhpParser\Node\Stmt\Trait_;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Type\ObjectType;
use PHPStan\Type\ThisType;
use Rector\Enum\ObjectReference;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\PhpParser\AstResolver;
use Rector\PhpParser\Node\BetterNodeFinder;
use Rector\Reflection\ReflectionResolver;
use Rector\ValueObject\MethodName;
final class PropertyFetchAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
/**
* @readonly
* @var \Rector\PhpParser\AstResolver
*/
private $astResolver;
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/
private $nodeTypeResolver;
/**
* @readonly
* @var \Rector\Reflection\ReflectionResolver
*/
private $reflectionResolver;
/**
* @var string
*/
private const THIS = 'this';
public function __construct(NodeNameResolver $nodeNameResolver, BetterNodeFinder $betterNodeFinder, AstResolver $astResolver, NodeTypeResolver $nodeTypeResolver, ReflectionResolver $reflectionResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
$this->betterNodeFinder = $betterNodeFinder;
$this->astResolver = $astResolver;
$this->nodeTypeResolver = $nodeTypeResolver;
$this->reflectionResolver = $reflectionResolver;
}
public function isLocalPropertyFetch(Node $node) : bool
{
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch && !$node instanceof NullsafePropertyFetch) {
return \false;
}
$variableType = $node instanceof StaticPropertyFetch ? $this->nodeTypeResolver->getType($node->class) : $this->nodeTypeResolver->getType($node->var);
if ($variableType instanceof ObjectType) {
$classReflection = $this->reflectionResolver->resolveClassReflection($node);
if ($classReflection instanceof ClassReflection) {
return $classReflection->getName() === $variableType->getClassName();
}
return \false;
}
if (!$variableType instanceof ThisType) {
return $this->isTraitLocalPropertyFetch($node);
}
return \true;
}
public function isLocalPropertyFetchName(Node $node, string $desiredPropertyName) : bool
{
if (!$node instanceof PropertyFetch && !$node instanceof StaticPropertyFetch && !$node instanceof NullsafePropertyFetch) {
return \false;
}
if (!$this->nodeNameResolver->isName($node->name, $desiredPropertyName)) {
return \false;
}
return $this->isLocalPropertyFetch($node);
}
public function containsLocalPropertyFetchName(Trait_ $trait, string $propertyName) : bool
{
if ($trait->getProperty($propertyName) instanceof Property) {
return \true;
}
return (bool) $this->betterNodeFinder->findFirst($trait, function (Node $node) use($propertyName) : bool {
return $this->isLocalPropertyFetchName($node, $propertyName);
});
}
/**
* @phpstan-assert-if-true PropertyFetch|StaticPropertyFetch $node
*/
public function isPropertyFetch(Node $node) : bool
{
if ($node instanceof PropertyFetch) {
return \true;
}
return $node instanceof StaticPropertyFetch;
}
/**
* Matches:
* "$this->someValue = $<variableName>;"
*/
public function isVariableAssignToThisPropertyFetch(Assign $assign, string $variableName) : bool
{
if (!$assign->expr instanceof Variable) {
return \false;
}
if (!$this->nodeNameResolver->isName($assign->expr, $variableName)) {
return \false;
}
return $this->isLocalPropertyFetch($assign->var);
}
public function isFilledViaMethodCallInConstructStmts(ClassLike $classLike, string $propertyName) : bool
{
$classMethod = $classLike->getMethod(MethodName::CONSTRUCT);
if (!$classMethod instanceof ClassMethod) {
return \false;
}
$className = (string) $this->nodeNameResolver->getName($classLike);
$stmts = (array) $classMethod->stmts;
foreach ($stmts as $stmt) {
if (!$stmt instanceof Expression) {
continue;
}
if (!$stmt->expr instanceof MethodCall && !$stmt->expr instanceof StaticCall) {
continue;
}
$callerClassMethod = $this->astResolver->resolveClassMethodFromCall($stmt->expr);
if (!$callerClassMethod instanceof ClassMethod) {
continue;
}
$callerClassReflection = $this->reflectionResolver->resolveClassReflection($callerClassMethod);
if (!$callerClassReflection instanceof ClassReflection) {
continue;
}
if (!$callerClassReflection->isClass()) {
continue;
}
$callerClassName = $callerClassReflection->getName();
$isFound = $this->isPropertyAssignFoundInClassMethod($classLike, $className, $callerClassName, $callerClassMethod, $propertyName);
if ($isFound) {
return \true;
}
}
return \false;
}
private function isTraitLocalPropertyFetch(Node $node) : bool
{
if ($node instanceof PropertyFetch) {
if (!$node->var instanceof Variable) {
return \false;
}
return $this->nodeNameResolver->isName($node->var, self::THIS);
}
if ($node instanceof StaticPropertyFetch) {
if (!$node->class instanceof Name) {
return \false;
}
return $this->nodeNameResolver->isNames($node->class, [ObjectReference::SELF, ObjectReference::STATIC]);
}
return \false;
}
private function isPropertyAssignFoundInClassMethod(ClassLike $classLike, string $className, string $callerClassName, ClassMethod $classMethod, string $propertyName) : bool
{
if ($className !== $callerClassName && !$classLike instanceof Trait_) {
$objectType = new ObjectType($className);
$callerObjectType = new ObjectType($callerClassName);
if (!$callerObjectType->isSuperTypeOf($objectType)->yes()) {
return \false;
}
}
foreach ((array) $classMethod->stmts as $stmt) {
if (!$stmt instanceof Expression) {
continue;
}
if (!$stmt->expr instanceof Assign) {
continue;
}
if ($this->isLocalPropertyFetchName($stmt->expr->var, $propertyName)) {
return \true;
}
}
return \false;
}
}
PK �n]˶�� � MagicClassMethodAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\ValueObject\MethodName;
final class MagicClassMethodAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
public function isUnsafeOverridden(ClassMethod $classMethod) : bool
{
if ($this->nodeNameResolver->isName($classMethod, MethodName::INVOKE)) {
return \false;
}
return $classMethod->isMagic();
}
}
PK �n]�S� ConstFetchAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\ConstFetch;
/**
* Read-only utils for ClassConstAnalyzer Node:
* "false, true..."
*/
final class ConstFetchAnalyzer
{
public function isTrueOrFalse(Expr $expr) : bool
{
if ($this->isTrue($expr)) {
return \true;
}
return $this->isFalse($expr);
}
public function isFalse(Expr $expr) : bool
{
return $this->isConstantWithLowercasedName($expr, 'false');
}
public function isTrue(Expr $expr) : bool
{
return $this->isConstantWithLowercasedName($expr, 'true');
}
public function isNull(Expr $expr) : bool
{
return $this->isConstantWithLowercasedName($expr, 'null');
}
private function isConstantWithLowercasedName(Node $node, string $name) : bool
{
if (!$node instanceof ConstFetch) {
return \false;
}
return $node->name->toLowerString() === $name;
}
}
PK �n]�� �} } CallAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Expr;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\BooleanNot;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\NullsafeMethodCall;
use PhpParser\Node\Expr\StaticCall;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\Stmt\If_;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\ObjectType;
use Rector\NodeTypeResolver\Node\AttributeKey;
final class CallAnalyzer
{
/**
* @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/
private $reflectionProvider;
/**
* @var array<class-string<Expr>>
*/
private const OBJECT_CALL_TYPES = [MethodCall::class, NullsafeMethodCall::class, StaticCall::class];
public function __construct(ReflectionProvider $reflectionProvider)
{
$this->reflectionProvider = $reflectionProvider;
}
public function isObjectCall(Expr $expr) : bool
{
if ($expr instanceof BooleanNot) {
$expr = $expr->expr;
}
if ($expr instanceof BinaryOp) {
$isObjectCallLeft = $this->isObjectCall($expr->left);
$isObjectCallRight = $this->isObjectCall($expr->right);
return $isObjectCallLeft || $isObjectCallRight;
}
foreach (self::OBJECT_CALL_TYPES as $objectCallType) {
if ($expr instanceof $objectCallType) {
return \true;
}
}
return \false;
}
/**
* @param If_[] $ifs
*/
public function doesIfHasObjectCall(array $ifs) : bool
{
foreach ($ifs as $if) {
if ($this->isObjectCall($if->cond)) {
return \true;
}
}
return \false;
}
public function isNewInstance(Variable $variable) : bool
{
$scope = $variable->getAttribute(AttributeKey::SCOPE);
if (!$scope instanceof Scope) {
return \false;
}
$type = $scope->getNativeType($variable);
if (!$type instanceof ObjectType) {
return \false;
}
$className = $type->getClassName();
if (!$this->reflectionProvider->hasClass($className)) {
return \false;
}
$classReflection = $this->reflectionProvider->getClass($className);
return $classReflection->getNativeReflection()->isInstantiable();
}
}
PK �n]Ƨ?`� � ParamAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node;
use PhpParser\Node\Expr\Assign;
use PhpParser\Node\Expr\CallLike;
use PhpParser\Node\Expr\Closure;
use PhpParser\Node\Expr\Error;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\Variable;
use PhpParser\Node\NullableType;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PhpParser\NodeTraverser;
use Rector\NodeManipulator\FuncCallManipulator;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser;
use Rector\PhpParser\Comparing\NodeComparator;
use Rector\PhpParser\Node\BetterNodeFinder;
final class ParamAnalyzer
{
/**
* @readonly
* @var \Rector\PhpParser\Comparing\NodeComparator
*/
private $nodeComparator;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \Rector\NodeManipulator\FuncCallManipulator
*/
private $funcCallManipulator;
/**
* @readonly
* @var \Rector\PhpDocParser\NodeTraverser\SimpleCallableNodeTraverser
*/
private $simpleCallableNodeTraverser;
/**
* @readonly
* @var \Rector\PhpParser\Node\BetterNodeFinder
*/
private $betterNodeFinder;
public function __construct(NodeComparator $nodeComparator, NodeNameResolver $nodeNameResolver, FuncCallManipulator $funcCallManipulator, SimpleCallableNodeTraverser $simpleCallableNodeTraverser, BetterNodeFinder $betterNodeFinder)
{
$this->nodeComparator = $nodeComparator;
$this->nodeNameResolver = $nodeNameResolver;
$this->funcCallManipulator = $funcCallManipulator;
$this->simpleCallableNodeTraverser = $simpleCallableNodeTraverser;
$this->betterNodeFinder = $betterNodeFinder;
}
public function isParamUsedInClassMethod(ClassMethod $classMethod, Param $param) : bool
{
$isParamUsed = \false;
if ($param->var instanceof Error) {
return \false;
}
$this->simpleCallableNodeTraverser->traverseNodesWithCallable($classMethod->stmts, function (Node $node) use(&$isParamUsed, $param) : ?int {
if ($isParamUsed) {
return NodeTraverser::STOP_TRAVERSAL;
}
if ($this->isUsedAsArg($node, $param)) {
$isParamUsed = \true;
}
// skip nested anonymous class
if ($node instanceof Class_ || $node instanceof Function_) {
return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN;
}
if ($node instanceof Variable && $this->nodeComparator->areNodesEqual($node, $param->var)) {
$isParamUsed = \true;
}
if ($node instanceof Closure && $this->isVariableInClosureUses($node, $param->var)) {
$isParamUsed = \true;
}
if ($this->isParamUsed($node, $param)) {
$isParamUsed = \true;
}
return null;
});
return $isParamUsed;
}
/**
* @param Param[] $params
*/
public function hasPropertyPromotion(array $params) : bool
{
foreach ($params as $param) {
if ($param->flags !== 0) {
return \true;
}
}
return \false;
}
public function isNullable(Param $param) : bool
{
if ($param->variadic) {
return \false;
}
if ($param->type === null) {
return \false;
}
return $param->type instanceof NullableType;
}
public function isParamReassign(ClassMethod $classMethod, Param $param) : bool
{
$paramName = (string) $this->nodeNameResolver->getName($param->var);
return (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped($classMethod, function (Node $node) use($paramName) : bool {
if (!$node instanceof Assign) {
return \false;
}
if (!$node->var instanceof Variable) {
return \false;
}
return $this->nodeNameResolver->isName($node->var, $paramName);
});
}
private function isVariableInClosureUses(Closure $closure, Variable $variable) : bool
{
foreach ($closure->uses as $use) {
if ($this->nodeComparator->areNodesEqual($use->var, $variable)) {
return \true;
}
}
return \false;
}
private function isUsedAsArg(Node $node, Param $param) : bool
{
if ($node instanceof New_ || $node instanceof CallLike) {
if ($node->isFirstClassCallable()) {
return \false;
}
foreach ($node->getArgs() as $arg) {
if ($this->nodeComparator->areNodesEqual($param->var, $arg->value)) {
return \true;
}
}
}
return \false;
}
private function isParamUsed(Node $node, Param $param) : bool
{
if (!$node instanceof FuncCall) {
return \false;
}
if (!$this->nodeNameResolver->isName($node, 'compact')) {
return \false;
}
$arguments = $this->funcCallManipulator->extractArgumentsFromCompactFuncCalls([$node]);
return $this->nodeNameResolver->isNames($param, $arguments);
}
}
PK �n]��{Ӣ � ArgsAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Arg;
use PhpParser\Node\Identifier;
final class ArgsAnalyzer
{
/**
* @param Arg[] $args
*/
public function hasNamedArg(array $args) : bool
{
foreach ($args as $arg) {
if ($arg->name instanceof Identifier) {
return \true;
}
}
return \false;
}
}
PK �n]��/�� � BinaryOpAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Expr\BinaryOp;
use PhpParser\Node\Expr\FuncCall;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\ValueObject\FuncCallAndExpr;
final class BinaryOpAnalyzer
{
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
public function __construct(NodeNameResolver $nodeNameResolver)
{
$this->nodeNameResolver = $nodeNameResolver;
}
public function matchFuncCallAndOtherExpr(BinaryOp $binaryOp, string $funcCallName) : ?FuncCallAndExpr
{
if ($binaryOp->left instanceof FuncCall) {
if (!$this->nodeNameResolver->isName($binaryOp->left, $funcCallName)) {
return null;
}
return new FuncCallAndExpr($binaryOp->left, $binaryOp->right);
}
if ($binaryOp->right instanceof FuncCall) {
if (!$this->nodeNameResolver->isName($binaryOp->right, $funcCallName)) {
return null;
}
return new FuncCallAndExpr($binaryOp->right, $binaryOp->left);
}
return null;
}
}
PK �n]1��j� � PropertyAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Stmt\Property;
use PHPStan\Type\CallableType;
use PHPStan\Type\NullType;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use PHPStan\Type\UnionType;
use Rector\NodeTypeResolver\NodeTypeResolver;
use Rector\StaticTypeMapper\ValueObject\Type\NonExistingObjectType;
final class PropertyAnalyzer
{
/**
* @readonly
* @var \Rector\NodeTypeResolver\NodeTypeResolver
*/
private $nodeTypeResolver;
public function __construct(NodeTypeResolver $nodeTypeResolver)
{
$this->nodeTypeResolver = $nodeTypeResolver;
}
public function hasForbiddenType(Property $property) : bool
{
$propertyType = $this->nodeTypeResolver->getType($property);
if ($propertyType instanceof NullType) {
return \true;
}
if ($this->isForbiddenType($propertyType)) {
return \true;
}
if (!$propertyType instanceof UnionType) {
return \false;
}
$types = $propertyType->getTypes();
foreach ($types as $type) {
if ($this->isForbiddenType($type)) {
return \true;
}
}
return \false;
}
private function isForbiddenType(Type $type) : bool
{
if ($type instanceof NonExistingObjectType) {
return \true;
}
return $this->isCallableType($type);
}
private function isCallableType(Type $type) : bool
{
if ($type instanceof TypeWithClassName && $type->getClassName() === 'Closure') {
return \false;
}
return $type instanceof CallableType;
}
}
PK �n] VariadicAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
use Rector\Reflection\ReflectionResolver;
final class VariadicAnalyzer
{
/**
* @readonly
* @var \Rector\Reflection\ReflectionResolver
*/
private $reflectionResolver;
public function __construct(ReflectionResolver $reflectionResolver)
{
$this->reflectionResolver = $reflectionResolver;
}
/**
* @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\StaticCall|\PhpParser\Node\Expr\MethodCall $call
*/
public function hasVariadicParameters($call) : bool
{
$functionLikeReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($call);
if ($functionLikeReflection === null) {
return \false;
}
return $this->hasVariadicVariant($functionLikeReflection);
}
/**
* @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $functionLikeReflection
*/
private function hasVariadicVariant($functionLikeReflection) : bool
{
foreach ($functionLikeReflection->getVariants() as $parametersAcceptor) {
// can be any number of arguments → nothing to limit here
if ($parametersAcceptor->isVariadic()) {
return \true;
}
}
return \false;
}
}
PK �n]��� � DoctrineEntityAnalyzer.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Stmt\Class_;
use PHPStan\BetterReflection\Reflection\Adapter\ReflectionClass;
use PHPStan\Reflection\ClassReflection;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfo;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
/**
* @api used in doctrine
*/
final class DoctrineEntityAnalyzer
{
/**
* @readonly
* @var \Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory
*/
private $phpDocInfoFactory;
/**
* @var string[]
*/
private const DOCTRINE_MAPPING_CLASSES = ['Doctrine\\ORM\\Mapping\\Entity', 'Doctrine\\ORM\\Mapping\\Embeddable', 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\Document', 'Doctrine\\ODM\\MongoDB\\Mapping\\Annotations\\EmbeddedDocument'];
public function __construct(PhpDocInfoFactory $phpDocInfoFactory)
{
$this->phpDocInfoFactory = $phpDocInfoFactory;
}
public function hasClassAnnotation(Class_ $class) : bool
{
$phpDocInfo = $this->phpDocInfoFactory->createFromNode($class);
if (!$phpDocInfo instanceof PhpDocInfo) {
return \false;
}
return $phpDocInfo->hasByAnnotationClasses(self::DOCTRINE_MAPPING_CLASSES);
}
public function hasClassReflectionAttribute(ClassReflection $classReflection) : bool
{
/** @var ReflectionClass $nativeReflectionClass */
$nativeReflectionClass = $classReflection->getNativeReflection();
// skip early in case of no attributes at all
if ((\method_exists($nativeReflectionClass, 'getAttributes') ? $nativeReflectionClass->getAttributes() : []) === []) {
return \false;
}
foreach (self::DOCTRINE_MAPPING_CLASSES as $doctrineMappingClass) {
// skip entities
if ((\method_exists($nativeReflectionClass, 'getAttributes') ? $nativeReflectionClass->getAttributes($doctrineMappingClass) : []) !== []) {
return \true;
}
}
return \false;
}
}
PK �n]F��� � PropertyPresenceChecker.phpnu �[��� <?php
declare (strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Param;
use PhpParser\Node\Stmt\Class_;
use PhpParser\Node\Stmt\Property;
use PHPStan\Reflection\ClassReflection;
use PHPStan\Reflection\Php\PhpPropertyReflection;
use PHPStan\Reflection\ReflectionProvider;
use PHPStan\Type\Type;
use PHPStan\Type\TypeWithClassName;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\Php80\NodeAnalyzer\PromotedPropertyResolver;
use Rector\PhpParser\AstResolver;
use Rector\PostRector\ValueObject\PropertyMetadata;
/**
* Can be local property, parent property etc.
*/
final class PropertyPresenceChecker
{
/**
* @readonly
* @var \Rector\Php80\NodeAnalyzer\PromotedPropertyResolver
*/
private $promotedPropertyResolver;
/**
* @readonly
* @var \Rector\NodeNameResolver\NodeNameResolver
*/
private $nodeNameResolver;
/**
* @readonly
* @var \PHPStan\Reflection\ReflectionProvider
*/
private $reflectionProvider;
/**
* @readonly
* @var \Rector\PhpParser\AstResolver
*/
private $astResolver;
public function __construct(PromotedPropertyResolver $promotedPropertyResolver, NodeNameResolver $nodeNameResolver, ReflectionProvider $reflectionProvider, AstResolver $astResolver)
{
$this->promotedPropertyResolver = $promotedPropertyResolver;
$this->nodeNameResolver = $nodeNameResolver;
$this->reflectionProvider = $reflectionProvider;
$this->astResolver = $astResolver;
}
/**
* Includes parent classes and traits
*/
public function hasClassContextProperty(Class_ $class, PropertyMetadata $propertyMetadata) : bool
{
$propertyOrParam = $this->getClassContextProperty($class, $propertyMetadata);
return $propertyOrParam !== null;
}
/**
* @return \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|null
*/
public function getClassContextProperty(Class_ $class, PropertyMetadata $propertyMetadata)
{
$className = $this->nodeNameResolver->getName($class);
if ($className === null) {
return null;
}
$property = $class->getProperty($propertyMetadata->getName());
if ($property instanceof Property) {
return $property;
}
$property = $this->matchPropertyByParentNonPrivateProperties($className, $propertyMetadata);
if ($property instanceof Property || $property instanceof Param) {
return $property;
}
$promotedPropertyParams = $this->promotedPropertyResolver->resolveFromClass($class);
foreach ($promotedPropertyParams as $promotedPropertyParam) {
if ($this->nodeNameResolver->isName($promotedPropertyParam, $propertyMetadata->getName())) {
return $promotedPropertyParam;
}
}
return null;
}
/**
* @return PhpPropertyReflection[]
*/
private function getParentClassNonPrivatePropertyReflections(string $className) : array
{
if (!$this->reflectionProvider->hasClass($className)) {
return [];
}
$classReflection = $this->reflectionProvider->getClass($className);
$propertyReflections = [];
foreach ($classReflection->getParents() as $parentClassReflection) {
$propertyNames = $this->resolveNonPrivatePropertyNames($parentClassReflection);
foreach ($propertyNames as $propertyName) {
$propertyReflections[] = $parentClassReflection->getNativeProperty($propertyName);
}
}
return $propertyReflections;
}
/**
* @return \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|null
*/
private function matchPropertyByType(PropertyMetadata $propertyMetadata, PhpPropertyReflection $phpPropertyReflection)
{
if (!$propertyMetadata->getType() instanceof Type) {
return null;
}
if (!$propertyMetadata->getType() instanceof TypeWithClassName) {
return null;
}
if (!$phpPropertyReflection->getWritableType() instanceof TypeWithClassName) {
return null;
}
$propertyObjectTypeWithClassName = $propertyMetadata->getType();
if (!$propertyObjectTypeWithClassName->equals($phpPropertyReflection->getWritableType())) {
return null;
}
return $this->astResolver->resolvePropertyFromPropertyReflection($phpPropertyReflection);
}
/**
* @return \PhpParser\Node\Stmt\Property|\PhpParser\Node\Param|null
*/
private function matchPropertyByParentNonPrivateProperties(string $className, PropertyMetadata $propertyMetadata)
{
$availablePropertyReflections = $this->getParentClassNonPrivatePropertyReflections($className);
foreach ($availablePropertyReflections as $availablePropertyReflection) {
// 1. match type by priority
$property = $this->matchPropertyByType($propertyMetadata, $availablePropertyReflection);
if ($property instanceof Property || $property instanceof Param) {
return $property;
}
$nativePropertyReflection = $availablePropertyReflection->getNativeReflection();
// 2. match by name
if ($nativePropertyReflection->getName() === $propertyMetadata->getName()) {
return $this->astResolver->resolvePropertyFromPropertyReflection($availablePropertyReflection);
}
}
return null;
}
/**
* @return string[]
*/
private function resolveNonPrivatePropertyNames(ClassReflection $classReflection) : array
{
$propertyNames = [];
$nativeReflection = $classReflection->getNativeReflection();
foreach ($nativeReflection->getProperties() as $reflectionProperty) {
if ($reflectionProperty->isPrivate()) {
continue;
}
$propertyNames[] = $reflectionProperty->getName();
}
return $propertyNames;
}
}
PK �n]�'�� � ScopeAnalyzer.phpnu �[��� PK �n]fYįz z � ExprAnalyzer.phpnu �[��� PK �n]j�5? ? � CompactFuncCallAnalyzer.phpnu �[��� PK �n]�;�*� � 0 ClassAnalyzer.phpnu �[��� PK �n]�6��[ [ @ VariableAnalyzer.phpnu �[��� PK �n]XPS � TerminatedNodeAnalyzer.phpnu �[��� PK �n]ox� � .4 PropertyFetchAnalyzer.phpnu �[��� PK �n]˶�� � �Q MagicClassMethodAnalyzer.phpnu �[��� PK �n]�S� U ConstFetchAnalyzer.phpnu �[��� PK �n]�� �} } fY CallAnalyzer.phpnu �[��� PK �n]Ƨ?`� � #c ParamAnalyzer.phpnu �[��� PK �n]��{Ӣ � �x ArgsAnalyzer.phpnu �[��� PK �n]��/�� � �z BinaryOpAnalyzer.phpnu �[��� PK �n]1��j� � � PropertyAnalyzer.phpnu �[��� PK �n] �� VariadicAnalyzer.phpnu �[��� PK �n]��� � DoctrineEntityAnalyzer.phpnu �[��� PK �n]F��� � � PropertyPresenceChecker.phpnu �[��� PK � �