?????????? ????????? - ??????????????? - /home/agenciai/public_html/cd38d8/Php71.tar
???????
ValueObject/TwoNodeMatch.php 0000644 00000001200 15126443671 0012016 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\ValueObject; use PhpParser\Node\Expr; final class TwoNodeMatch { /** * @readonly * @var \PhpParser\Node\Expr */ private $firstExpr; /** * @readonly * @var \PhpParser\Node\Expr */ private $secondExpr; public function __construct(Expr $firstExpr, Expr $secondExpr) { $this->firstExpr = $firstExpr; $this->secondExpr = $secondExpr; } public function getFirstExpr() : Expr { return $this->firstExpr; } public function getSecondExpr() : Expr { return $this->secondExpr; } } Rector/ClassConst/PublicConstantVisibilityRector.php 0000644 00000004011 15126443671 0016753 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\ClassConst; use PhpParser\Node; use PhpParser\Node\Stmt\ClassConst; use Rector\Configuration\Deprecation\Contract\DeprecatedInterface; use Rector\Privatization\NodeManipulator\VisibilityManipulator; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\ClassConst\PublicConstantVisibilityRector\PublicConstantVisibilityRectorTest * @deprecated Since 1.2.4, as adds blindly public to all constants, even local-only ones that should be private. Use scope-based solution instead, e.g. https://tomasvotruba.com/blog/how-to-add-visbility-to-338-class-constants-in-25-seconds */ final class PublicConstantVisibilityRector extends AbstractRector implements MinPhpVersionInterface, DeprecatedInterface { /** * @readonly * @var \Rector\Privatization\NodeManipulator\VisibilityManipulator */ private $visibilityManipulator; public function __construct(VisibilityManipulator $visibilityManipulator) { $this->visibilityManipulator = $visibilityManipulator; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Add explicit public constant visibility.', [new CodeSample(<<<'CODE_SAMPLE' class SomeClass { const HEY = 'you'; } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { public const HEY = 'you'; } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [ClassConst::class]; } /** * @param ClassConst $node */ public function refactor(Node $node) : ?Node { return $this->visibilityManipulator->publicize($node); } public function provideMinPhpVersion() : int { return PhpVersionFeature::CONSTANT_VISIBILITY; } } Rector/BooleanOr/IsIterableRector.php 0000644 00000004677 15126443671 0013624 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\BooleanOr; use PhpParser\Node; use PhpParser\Node\Expr\BinaryOp\BooleanOr; use PhpParser\Node\Name; use PHPStan\Reflection\ReflectionProvider; use Rector\Php\PhpVersionProvider; use Rector\Php71\IsArrayAndDualCheckToAble; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\BooleanOr\IsIterableRector\IsIterableRectorTest */ final class IsIterableRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\Php71\IsArrayAndDualCheckToAble */ private $isArrayAndDualCheckToAble; /** * @readonly * @var \PHPStan\Reflection\ReflectionProvider */ private $reflectionProvider; /** * @readonly * @var \Rector\Php\PhpVersionProvider */ private $phpVersionProvider; public function __construct(IsArrayAndDualCheckToAble $isArrayAndDualCheckToAble, ReflectionProvider $reflectionProvider, PhpVersionProvider $phpVersionProvider) { $this->isArrayAndDualCheckToAble = $isArrayAndDualCheckToAble; $this->reflectionProvider = $reflectionProvider; $this->phpVersionProvider = $phpVersionProvider; } public function provideMinPhpVersion() : int { return PhpVersionFeature::IS_ITERABLE; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Changes is_array + Traversable check to is_iterable', [new CodeSample('is_array($foo) || $foo instanceof Traversable;', 'is_iterable($foo);')]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [BooleanOr::class]; } /** * @param BooleanOr $node */ public function refactor(Node $node) : ?Node { if ($this->shouldSkip()) { return null; } return $this->isArrayAndDualCheckToAble->processBooleanOr($node, 'Traversable', 'is_iterable'); } private function shouldSkip() : bool { if ($this->reflectionProvider->hasFunction(new Name('is_iterable'), null)) { return \false; } return !$this->phpVersionProvider->isAtLeastPhpVersion(PhpVersionFeature::IS_ITERABLE); } } Rector/Assign/AssignArrayToStringRector.php 0000644 00000016620 15126443671 0015051 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\Assign; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\ArrayDimFetch; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\Closure; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar\String_; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Function_; use PhpParser\Node\Stmt\Namespace_; use PhpParser\Node\Stmt\Property; use PhpParser\NodeTraverser; use PHPStan\Type\UnionType; use Rector\PhpParser\Node\CustomNode\FileWithoutNamespace; use Rector\PhpParser\NodeFinder\PropertyFetchFinder; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\Assign\AssignArrayToStringRector\AssignArrayToStringRectorTest */ final class AssignArrayToStringRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\PhpParser\NodeFinder\PropertyFetchFinder */ private $propertyFetchFinder; public function __construct(PropertyFetchFinder $propertyFetchFinder) { $this->propertyFetchFinder = $propertyFetchFinder; } public function provideMinPhpVersion() : int { return PhpVersionFeature::NO_ASSIGN_ARRAY_TO_STRING; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('String cannot be turned into array by assignment anymore', [new CodeSample(<<<'CODE_SAMPLE' $string = ''; $string[] = 1; CODE_SAMPLE , <<<'CODE_SAMPLE' $string = []; $string[] = 1; CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Namespace_::class, FileWithoutNamespace::class, Class_::class, ClassMethod::class, Function_::class, Closure::class]; } /** * @param Namespace_|FileWithoutNamespace|Class_|ClassMethod|Function_|Closure $node */ public function refactor(Node $node) : ?Node { if ($node instanceof Class_) { return $this->refactorClass($node); } if ($node->stmts === null) { return null; } $hasChanged = \false; $this->traverseNodesWithCallable($node->stmts, function (Node $subNode) use(&$hasChanged, $node) : ?int { if ($subNode instanceof Class_ || $subNode instanceof Function_ || $subNode instanceof Closure) { return NodeTraverser::DONT_TRAVERSE_CURRENT_AND_CHILDREN; } if ($subNode instanceof Assign) { $assign = $this->refactorAssign($subNode, $node); if ($assign instanceof Assign) { $hasChanged = \true; return null; } } return null; }); if ($hasChanged) { return $node; } return null; } private function isEmptyString(Expr $expr) : bool { if (!$expr instanceof String_) { return \false; } return $expr->value === ''; } private function refactorClass(Class_ $class) : ?Class_ { $hasChanged = \false; foreach ($class->getProperties() as $property) { if (!$this->hasPropertyDefaultEmptyString($property)) { continue; } $arrayDimFetches = $this->propertyFetchFinder->findLocalPropertyArrayDimFetchesAssignsByName($class, $property); foreach ($arrayDimFetches as $arrayDimFetch) { if ($arrayDimFetch->dim instanceof Expr) { continue; } $property->props[0]->default = new Array_(); $hasChanged = \true; } } if ($hasChanged) { return $class; } return null; } private function hasPropertyDefaultEmptyString(Property $property) : bool { $defaultExpr = $property->props[0]->default; if (!$defaultExpr instanceof Expr) { return \false; } return $this->isEmptyString($defaultExpr); } /** * @return ArrayDimFetch[] * @param \PhpParser\Node\Stmt\Namespace_|\Rector\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node */ private function findSameNamedVariableAssigns(Variable $variable, $node) : array { if ($node->stmts === null) { return []; } $variableName = $this->nodeNameResolver->getName($variable); if ($variableName === null) { return []; } $assignedArrayDimFetches = []; $this->traverseNodesWithCallable($node->stmts, function (Node $node) use($variable, $variableName, &$assignedArrayDimFetches) { if (!$node instanceof Assign) { return null; } if ($this->isReAssignedAsArray($node, $variableName, $variable)) { $assignedArrayDimFetches = []; return NodeTraverser::STOP_TRAVERSAL; } if (!$node->var instanceof ArrayDimFetch) { return null; } $arrayDimFetch = $node->var; if (!$arrayDimFetch->var instanceof Variable) { return null; } if (!$this->isName($arrayDimFetch->var, $variableName)) { return null; } $assignedArrayDimFetches[] = $arrayDimFetch; }); return $assignedArrayDimFetches; } private function isReAssignedAsArray(Assign $assign, string $variableName, Variable $variable) : bool { if ($assign->var instanceof Variable && $this->isName($assign->var, $variableName) && $assign->var->getStartTokenPos() > $variable->getStartTokenPos()) { $exprType = $this->nodeTypeResolver->getNativeType($assign->expr); if ($exprType->isArray()->yes()) { return \true; } } return \false; } /** * @param \PhpParser\Node\Stmt\Namespace_|\Rector\PhpParser\Node\CustomNode\FileWithoutNamespace|\PhpParser\Node\Stmt\ClassMethod|\PhpParser\Node\Stmt\Function_|\PhpParser\Node\Expr\Closure $node */ private function refactorAssign(Assign $assign, $node) : ?Assign { if (!$assign->var instanceof Variable) { return null; } if (!$this->isEmptyString($assign->expr)) { return null; } $type = $this->nodeTypeResolver->getNativeType($assign->var); if ($type->isArray()->yes()) { return null; } if ($type instanceof UnionType) { return null; } $variableAssignArrayDimFetches = $this->findSameNamedVariableAssigns($assign->var, $node); $shouldRetype = \false; // detect if is part of variable assign? foreach ($variableAssignArrayDimFetches as $variableAssignArrayDimFetch) { if ($variableAssignArrayDimFetch->dim instanceof Expr) { continue; } $shouldRetype = \true; break; } if (!$shouldRetype) { return null; } $assign->expr = new Array_(); return $assign; } } Rector/TryCatch/MultiExceptionCatchRector.php 0000644 00000005452 15126443671 0015346 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\TryCatch; use PhpParser\Node; use PhpParser\Node\Stmt\TryCatch; use Rector\PhpParser\Printer\BetterStandardPrinter; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\TryCatch\MultiExceptionCatchRector\MultiExceptionCatchRectorTest */ final class MultiExceptionCatchRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\PhpParser\Printer\BetterStandardPrinter */ private $betterStandardPrinter; public function __construct(BetterStandardPrinter $betterStandardPrinter) { $this->betterStandardPrinter = $betterStandardPrinter; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Changes multi catch of same exception to single one | separated.', [new CodeSample(<<<'CODE_SAMPLE' try { // Some code... } catch (ExceptionType1 $exception) { $sameCode; } catch (ExceptionType2 $exception) { $sameCode; } CODE_SAMPLE , <<<'CODE_SAMPLE' try { // Some code... } catch (ExceptionType1 | ExceptionType2 $exception) { $sameCode; } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [TryCatch::class]; } /** * @param TryCatch $node */ public function refactor(Node $node) : ?Node { if (\count($node->catches) < 2) { return null; } $hasChanged = \false; foreach ($node->catches as $key => $catch) { if (!isset($node->catches[$key + 1])) { break; } $currentPrintedCatch = $this->betterStandardPrinter->print($catch->stmts); $nextPrintedCatch = $this->betterStandardPrinter->print($node->catches[$key + 1]->stmts); // already duplicated catch → remove it and join the type if ($currentPrintedCatch === $nextPrintedCatch) { // use current var as next var $node->catches[$key + 1]->var = $node->catches[$key]->var; // merge next types as current merge to next types $node->catches[$key + 1]->types = \array_merge($node->catches[$key]->types, $node->catches[$key + 1]->types); unset($node->catches[$key]); $hasChanged = \true; } } if ($hasChanged) { return $node; } return null; } public function provideMinPhpVersion() : int { return PhpVersionFeature::MULTI_EXCEPTION_CATCH; } } Rector/FuncCall/RemoveExtraParametersRector.php 0000644 00000012244 15126443671 0015662 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\FuncCall; use PhpParser\Node; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\MethodCall; use PhpParser\Node\Expr\StaticCall; use PhpParser\Node\Name; use PHPStan\Reflection\FunctionReflection; use PHPStan\Reflection\MethodReflection; use PHPStan\Reflection\Php\PhpMethodReflection; use PHPStan\Reflection\Type\UnionTypeMethodReflection; use Rector\Enum\ObjectReference; use Rector\NodeAnalyzer\VariadicAnalyzer; use Rector\Rector\AbstractRector; use Rector\Reflection\ReflectionResolver; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\FuncCall\RemoveExtraParametersRector\RemoveExtraParametersRectorTest */ final class RemoveExtraParametersRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\NodeAnalyzer\VariadicAnalyzer */ private $variadicAnalyzer; /** * @readonly * @var \Rector\Reflection\ReflectionResolver */ private $reflectionResolver; public function __construct(VariadicAnalyzer $variadicAnalyzer, ReflectionResolver $reflectionResolver) { $this->variadicAnalyzer = $variadicAnalyzer; $this->reflectionResolver = $reflectionResolver; } public function provideMinPhpVersion() : int { return PhpVersionFeature::NO_EXTRA_PARAMETERS; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Remove extra parameters', [new CodeSample('strlen("asdf", 1);', 'strlen("asdf");')]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [FuncCall::class, MethodCall::class, StaticCall::class]; } /** * @param FuncCall|MethodCall|StaticCall $node */ public function refactor(Node $node) : ?Node { if ($this->shouldSkip($node)) { return null; } // unreliable count of arguments $functionLikeReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($node); if ($functionLikeReflection instanceof UnionTypeMethodReflection) { return null; } if ($functionLikeReflection === null) { return null; } if ($functionLikeReflection instanceof PhpMethodReflection) { if ($functionLikeReflection->isAbstract()) { return null; } $classReflection = $functionLikeReflection->getDeclaringClass(); if ($classReflection->isInterface()) { return null; } } $maximumAllowedParameterCount = $this->resolveMaximumAllowedParameterCount($functionLikeReflection); if ($node->isFirstClassCallable()) { return null; } if ($this->shouldSkipFunctionReflection($functionLikeReflection)) { return null; } $numberOfArguments = \count($node->getRawArgs()); if ($numberOfArguments <= $maximumAllowedParameterCount) { return null; } for ($i = $maximumAllowedParameterCount; $i <= $numberOfArguments; ++$i) { unset($node->args[$i]); } return $node; } /** * @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $reflection */ private function shouldSkipFunctionReflection($reflection) : bool { if ($reflection instanceof FunctionReflection) { $fileName = (string) $reflection->getFileName(); if (\strpos($fileName, 'phpstan.phar') !== \false) { return \true; } } if ($reflection instanceof MethodReflection) { $classReflection = $reflection->getDeclaringClass(); $fileName = (string) $classReflection->getFileName(); if (\strpos($fileName, 'phpstan.phar') !== \false) { return \true; } } return \false; } /** * @param \PhpParser\Node\Expr\FuncCall|\PhpParser\Node\Expr\MethodCall|\PhpParser\Node\Expr\StaticCall $call */ private function shouldSkip($call) : bool { if ($call->args === []) { return \true; } if ($call instanceof StaticCall) { if (!$call->class instanceof Name) { return \true; } if ($this->isName($call->class, ObjectReference::PARENT)) { return \true; } } return $this->variadicAnalyzer->hasVariadicParameters($call); } /** * @param \PHPStan\Reflection\MethodReflection|\PHPStan\Reflection\FunctionReflection $functionLikeReflection */ private function resolveMaximumAllowedParameterCount($functionLikeReflection) : int { $parameterCounts = [0]; foreach ($functionLikeReflection->getVariants() as $parametersAcceptor) { $parameterCounts[] = \count($parametersAcceptor->getParameters()); } return \max($parameterCounts); } } Rector/List_/ListToArrayDestructRector.php 0000644 00000003744 15126443671 0014720 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\List_; use PhpParser\Node; use PhpParser\Node\Expr\Array_; use PhpParser\Node\Expr\Assign; use PhpParser\Node\Expr\List_; use PhpParser\Node\Stmt\Foreach_; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\List_\ListToArrayDestructRector\ListToArrayDestructRectorTest */ final class ListToArrayDestructRector extends AbstractRector implements MinPhpVersionInterface { public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change list() to array destruct', [new CodeSample(<<<'CODE_SAMPLE' class SomeClass { public function run() { list($id1, $name1) = $data; foreach ($data as list($id, $name)) { } } } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { public function run() { [$id1, $name1] = $data; foreach ($data as [$id, $name]) { } } } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Assign::class, Foreach_::class]; } /** * @param Assign|Foreach_ $node */ public function refactor(Node $node) : ?Node { if ($node instanceof Assign) { if (!$node->var instanceof List_) { return null; } $list = $node->var; $node->var = new Array_($list->items); return $node; } if (!$node->valueVar instanceof List_) { return null; } $list = $node->valueVar; $node->valueVar = new Array_($list->items); return $node; } public function provideMinPhpVersion() : int { return PhpVersionFeature::ARRAY_DESTRUCT; } } Rector/BinaryOp/BinaryOpBetweenNumberAndStringRector.php 0000644 00000007205 15126443671 0017452 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71\Rector\BinaryOp; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\BinaryOp\Coalesce; use PhpParser\Node\Expr\BinaryOp\Concat; use PhpParser\Node\Expr\Variable; use PhpParser\Node\Scalar; use PhpParser\Node\Scalar\DNumber; use PhpParser\Node\Scalar\LNumber; use PhpParser\Node\Scalar\MagicConst\Line; use PhpParser\Node\Scalar\String_; use PHPStan\Type\Constant\ConstantStringType; use Rector\NodeAnalyzer\ExprAnalyzer; use Rector\Rector\AbstractRector; use Rector\ValueObject\PhpVersionFeature; use Rector\VersionBonding\Contract\MinPhpVersionInterface; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\Php71\Rector\BinaryOp\BinaryOpBetweenNumberAndStringRector\BinaryOpBetweenNumberAndStringRectorTest */ final class BinaryOpBetweenNumberAndStringRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\NodeAnalyzer\ExprAnalyzer */ private $exprAnalyzer; public function __construct(ExprAnalyzer $exprAnalyzer) { $this->exprAnalyzer = $exprAnalyzer; } public function provideMinPhpVersion() : int { return PhpVersionFeature::BINARY_OP_NUMBER_STRING; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change binary operation between some number + string to PHP 7.1 compatible version', [new CodeSample(<<<'CODE_SAMPLE' class SomeClass { public function run() { $value = 5 + ''; $value = 5.0 + 'hi'; } } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { public function run() { $value = 5 + 0; $value = 5.0 + 0.0; } } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [BinaryOp::class]; } /** * @param BinaryOp $node */ public function refactor(Node $node) : ?Node { if ($node instanceof Concat) { return null; } if ($node instanceof Coalesce) { return null; } if ($this->exprAnalyzer->isNonTypedFromParam($node->left)) { return null; } if ($this->exprAnalyzer->isNonTypedFromParam($node->right)) { return null; } if ($this->isStringOrStaticNonNumericString($node->left) && $this->nodeTypeResolver->isNumberType($node->right)) { $node->left = $this->nodeTypeResolver->getNativeType($node->right)->isInteger()->yes() ? new LNumber(0) : new DNumber(0); return $node; } if ($this->isStringOrStaticNonNumericString($node->right) && $this->nodeTypeResolver->isNumberType($node->left)) { $node->right = $this->nodeTypeResolver->getNativeType($node->left)->isInteger()->yes() ? new LNumber(0) : new DNumber(0); return $node; } return null; } private function isStringOrStaticNonNumericString(Expr $expr) : bool { // replace only scalar values, not variables/constants/etc. if (!$expr instanceof Scalar && !$expr instanceof Variable) { return \false; } if ($expr instanceof Line) { return \false; } if ($expr instanceof String_) { return !\is_numeric($expr->value); } $exprStaticType = $this->getType($expr); if ($exprStaticType instanceof ConstantStringType) { return !\is_numeric($exprStaticType->getValue()); } return \false; } } IsArrayAndDualCheckToAble.php 0000644 00000004741 15126443671 0012124 0 ustar 00 <?php declare (strict_types=1); namespace Rector\Php71; use PhpParser\Node\Arg; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\BooleanOr; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Expr\Instanceof_; use PhpParser\Node\Name; use Rector\NodeManipulator\BinaryOpManipulator; use Rector\NodeNameResolver\NodeNameResolver; use Rector\Php71\ValueObject\TwoNodeMatch; use Rector\PhpParser\Comparing\NodeComparator; final class IsArrayAndDualCheckToAble { /** * @readonly * @var \Rector\NodeManipulator\BinaryOpManipulator */ private $binaryOpManipulator; /** * @readonly * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; /** * @readonly * @var \Rector\PhpParser\Comparing\NodeComparator */ private $nodeComparator; public function __construct(BinaryOpManipulator $binaryOpManipulator, NodeNameResolver $nodeNameResolver, NodeComparator $nodeComparator) { $this->binaryOpManipulator = $binaryOpManipulator; $this->nodeNameResolver = $nodeNameResolver; $this->nodeComparator = $nodeComparator; } public function processBooleanOr(BooleanOr $booleanOr, string $type, string $newMethodName) : ?FuncCall { $twoNodeMatch = $this->binaryOpManipulator->matchFirstAndSecondConditionNode($booleanOr, Instanceof_::class, FuncCall::class); if (!$twoNodeMatch instanceof TwoNodeMatch) { return null; } /** @var Instanceof_ $instanceofExpr */ $instanceofExpr = $twoNodeMatch->getFirstExpr(); /** @var FuncCall $funcCallExpr */ $funcCallExpr = $twoNodeMatch->getSecondExpr(); $instanceOfClass = $instanceofExpr->class; if ($instanceOfClass instanceof Expr) { return null; } if ((string) $instanceOfClass !== $type) { return null; } if (!$this->nodeNameResolver->isName($funcCallExpr, 'is_array')) { return null; } if ($funcCallExpr->isFirstClassCallable()) { return null; } if (!isset($funcCallExpr->getArgs()[0])) { return null; } $firstArg = $funcCallExpr->getArgs()[0]; $firstExprNode = $firstArg->value; if (!$this->nodeComparator->areNodesEqual($instanceofExpr->expr, $firstExprNode)) { return null; } // both use same Expr return new FuncCall(new Name($newMethodName), [new Arg($firstExprNode)]); } }
| ver. 1.6 |
Github
|
.
| PHP 8.2.30 | ??????????? ?????????: 0 |
proxy
|
phpinfo
|
???????????