REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 3.88 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/DeadCode/NodeManipulator/CountManipulator.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\DeadCode\NodeManipulator; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp\Greater; use PhpParser\Node\Expr\BinaryOp\GreaterOrEqual; use PhpParser\Node\Expr\BinaryOp\Smaller; use PhpParser\Node\Expr\BinaryOp\SmallerOrEqual; use PhpParser\Node\Expr\FuncCall; use PhpParser\Node\Scalar\LNumber; use PHPStan\Type\NeverType; use Rector\NodeNameResolver\NodeNameResolver; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\PhpParser\Comparing\NodeComparator; final class CountManipulator { /** * @readonly * @var \Rector\NodeNameResolver\NodeNameResolver */ private $nodeNameResolver; /** * @readonly * @var \Rector\PhpParser\Comparing\NodeComparator */ private $nodeComparator; /** * @readonly * @var \Rector\NodeTypeResolver\NodeTypeResolver */ private $nodeTypeResolver; public function __construct(NodeNameResolver $nodeNameResolver, NodeComparator $nodeComparator, NodeTypeResolver $nodeTypeResolver) { $this->nodeNameResolver = $nodeNameResolver; $this->nodeComparator = $nodeComparator; $this->nodeTypeResolver = $nodeTypeResolver; } public function isCounterHigherThanOne(Expr $firstExpr, Expr $secondExpr) : bool { // e.g. count($values) > 0 if ($firstExpr instanceof Greater) { return $this->isGreater($firstExpr, $secondExpr); } // e.g. count($values) >= 1 if ($firstExpr instanceof GreaterOrEqual) { return $this->isGreaterOrEqual($firstExpr, $secondExpr); } // e.g. 0 < count($values) if ($firstExpr instanceof Smaller) { return $this->isSmaller($firstExpr, $secondExpr); } // e.g. 1 <= count($values) if ($firstExpr instanceof SmallerOrEqual) { return $this->isSmallerOrEqual($firstExpr, $secondExpr); } return \false; } private function isGreater(Greater $greater, Expr $expr) : bool { if (!$this->isNumber($greater->right, 0)) { return \false; } return $this->isCountWithExpression($greater->left, $expr); } private function isGreaterOrEqual(GreaterOrEqual $greaterOrEqual, Expr $expr) : bool { if (!$this->isNumber($greaterOrEqual->right, 1)) { return \false; } return $this->isCountWithExpression($greaterOrEqual->left, $expr); } private function isSmaller(Smaller $smaller, Expr $expr) : bool { if (!$this->isNumber($smaller->left, 0)) { return \false; } return $this->isCountWithExpression($smaller->right, $expr); } private function isSmallerOrEqual(SmallerOrEqual $smallerOrEqual, Expr $expr) : bool { if (!$this->isNumber($smallerOrEqual->left, 1)) { return \false; } return $this->isCountWithExpression($smallerOrEqual->right, $expr); } private function isNumber(Expr $expr, int $value) : bool { if (!$expr instanceof LNumber) { return \false; } return $expr->value === $value; } private function isCountWithExpression(Expr $node, Expr $expr) : bool { if (!$node instanceof FuncCall) { return \false; } if (!$this->nodeNameResolver->isName($node, 'count')) { return \false; } if ($node->isFirstClassCallable()) { return \false; } if (!isset($node->getArgs()[0])) { return \false; } $countedExpr = $node->getArgs()[0]->value; if ($this->nodeComparator->areNodesEqual($countedExpr, $expr)) { $exprType = $this->nodeTypeResolver->getNativeType($expr); if (!$exprType->isArray()->yes()) { return $exprType instanceof NeverType; } return \true; } return \false; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 5
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
ClassMethodParamRemover.php
1.35 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
ControllerClassMethodManipulator.php
1.71 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
CountManipulator.php
3.88 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
LivingCodeManipulator.php
4.35 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
VariadicFunctionLikeDetector.php
1.62 KB
lrw-r--r--
2024-11-08 13:59:10
Edit
Download
Rename
Chmod
Change Date
Delete
OK
Cancel
recursive
OK
Cancel
recursive
OK
Cancel
Zip Selected
If ZipArchive is unavailable, a
.tar
will be created (no compression).