/opt/cpanel/ea-wappspector/vendor/rector/rector/src/NodeAnalyzer
Edit: /opt/cpanel/ea-wappspector/vendor/rector/rector/src/NodeAnalyzer/ExprAnalyzer.php (3706B)
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);
}
}