?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/NodeAnalyzer.tar
???????
ClosureArrowFunctionAnalyzer.php 0000644 00000007132 15126256721 0013132 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php74\NodeAnalyzer; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\ClosureUse; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Stmt\Return_; use Rector\PhpParser\Comparing\NodeComparator; use Rector\PhpParser\Node\BetterNodeFinder; use Rector\Util\ArrayChecker; final class ClosureArrowFunctionAnalyzer { /** * @readonly * @var \Rector\PhpParser\Node\BetterNodeFinder */ private $betterNodeFinder; /** * @readonly * @var \Rector\PhpParser\Comparing\NodeComparator */ private $nodeComparator; /** * @readonly * @var \Rector\Util\ArrayChecker */ private $arrayChecker; public function __construct(BetterNodeFinder $betterNodeFinder, NodeComparator $nodeComparator, ArrayChecker $arrayChecker) { $this->betterNodeFinder = $betterNodeFinder; $this->nodeComparator = $nodeComparator; $this->arrayChecker = $arrayChecker; } public function matchArrowFunctionExpr(Closure $closure) : ?Expr { if (\count($closure->stmts) !== 1) { return null; } $onlyStmt = $closure->stmts[0]; if (!$onlyStmt instanceof Return_) { return null; } /** @var Return_ $return */ $return = $onlyStmt; if (!$return->expr instanceof Expr) { return null; } if ($this->shouldSkipForUsedReferencedValue($closure)) { return null; } return $return->expr; } private function shouldSkipForUsedReferencedValue(Closure $closure) : bool { $referencedValues = $this->resolveReferencedUseVariablesFromClosure($closure); if ($referencedValues === []) { return \false; } $isFoundInStmt = (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped($closure, function (Node $node) use($referencedValues) : bool { foreach ($referencedValues as $referencedValue) { if ($this->nodeComparator->areNodesEqual($node, $referencedValue)) { return \true; } } return \false; }); if ($isFoundInStmt) { return \true; } return $this->isFoundInInnerUses($closure, $referencedValues); } /** * @param Variable[] $referencedValues */ private function isFoundInInnerUses(Closure $node, array $referencedValues) : bool { return (bool) $this->betterNodeFinder->findFirstInFunctionLikeScoped($node, function (Node $subNode) use($referencedValues) : bool { if (!$subNode instanceof Closure) { return \false; } foreach ($referencedValues as $referencedValue) { $isFoundInInnerUses = $this->arrayChecker->doesExist($subNode->uses, function (ClosureUse $closureUse) use($referencedValue) : bool { return $closureUse->byRef && $this->nodeComparator->areNodesEqual($closureUse->var, $referencedValue); }); if ($isFoundInInnerUses) { return \true; } } return \false; }); } /** * @return Variable[] */ private function resolveReferencedUseVariablesFromClosure(Closure $closure) : array { $referencedValues = []; /** @var ClosureUse $use */ foreach ($closure->uses as $use) { if ($use->byRef) { $referencedValues[] = $use->var; } } return $referencedValues; } } ComplexNewAnalyzer.php 0000644 00000003775 15127623223 0011063 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php81\NodeAnalyzer; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayItem; use PhpParser\Node\Expr\New_; use PhpParser\Node\Name\FullyQualified; use Rector\NodeAnalyzer\ExprAnalyzer; final class ComplexNewAnalyzer { /** * @readonly * @var \Rector\NodeAnalyzer\ExprAnalyzer */ private $exprAnalyzer; public function __construct(ExprAnalyzer $exprAnalyzer) { $this->exprAnalyzer = $exprAnalyzer; } public function isDynamic(New_ $new) : bool { if (!$new->class instanceof FullyQualified) { return \true; } if ($new->isFirstClassCallable()) { return \false; } $args = $new->getArgs(); foreach ($args as $arg) { $value = $arg->value; if ($this->isAllowedNew($value)) { continue; } // new inside array is allowed for New in initializer if ($value instanceof Array_ && $this->isAllowedArray($value)) { continue; } if (!$this->exprAnalyzer->isDynamicExpr($value)) { continue; } return \true; } return \false; } private function isAllowedNew(Expr $expr) : bool { if ($expr instanceof New_) { return !$this->isDynamic($expr); } return \false; } private function isAllowedArray(Array_ $array) : bool { if (!$this->exprAnalyzer->isDynamicArray($array)) { return \true; } $arrayItems = $array->items; foreach ($arrayItems as $arrayItem) { if (!$arrayItem instanceof ArrayItem) { continue; } if (!$arrayItem->value instanceof New_) { return \false; } if ($this->isDynamic($arrayItem->value)) { return \false; } } return \true; } } CoalesePropertyAssignMatcher.php 0000644 00000004063 15127623223 0013054 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php81\NodeAnalyzer; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\New_; use PhpParser\Node\Expr\PropertyFetch; use PhpParser\Node\Stmt; use PhpParser\Node\Stmt\Expression; use Rector\NodeNameResolver\NodeNameResolver; final class CoalesePropertyAssignMatcher { /** * @readonly * @var \Rector\Php81\NodeAnalyzer\ComplexNewAnalyzer */ private $complexNewAnalyzer; /** * @readonly * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; public function __construct(\Rector\Php81\NodeAnalyzer\ComplexNewAnalyzer $complexNewAnalyzer, NodeNameResolver $nodeNameResolver) { $this->complexNewAnalyzer = $complexNewAnalyzer; $this->nodeNameResolver = $nodeNameResolver; } /** * Matches * * $this->value = $param ?? 'default'; */ public function matchCoalesceAssignsToLocalPropertyNamed(Stmt $stmt, string $propertyName) : ?Coalesce { if (!$stmt instanceof Expression) { return null; } if (!$stmt->expr instanceof Assign) { return null; } $assign = $stmt->expr; if (!$assign->expr instanceof Coalesce) { return null; } $coalesce = $assign->expr; if (!$coalesce->right instanceof New_) { return null; } if ($this->complexNewAnalyzer->isDynamic($coalesce->right)) { return null; } if (!$this->isLocalPropertyFetchNamed($assign->var, $propertyName)) { return null; } return $assign->expr; } private function isLocalPropertyFetchNamed(Expr $expr, string $propertyName) : bool { if (!$expr instanceof PropertyFetch) { return \false; } if (!$this->nodeNameResolver->isName($expr->var, 'this')) { return \false; } return $this->nodeNameResolver->isName($expr->name, $propertyName); } }
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0 |
proxy
|
phpinfo
|
???????????