REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.74 KB
Close
//opt/cpanel/ea-wappspector/vendor/rector/rector/rules/CodeQuality/NodeManipulator/ExprBoolCaster.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\CodeQuality\NodeManipulator; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BinaryOp; use PhpParser\Node\Expr\BinaryOp\NotIdentical; use PhpParser\Node\Expr\BooleanNot; use PhpParser\Node\Expr\Cast\Bool_; use PHPStan\Type\Type; use PHPStan\Type\TypeCombinator; use PHPStan\Type\UnionType; use Rector\NodeTypeResolver\NodeTypeResolver; use Rector\NodeTypeResolver\PHPStan\Type\StaticTypeAnalyzer; use Rector\PhpParser\Node\NodeFactory; use Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper; final class ExprBoolCaster { /** * @readonly * @var \Rector\NodeTypeResolver\NodeTypeResolver */ private $nodeTypeResolver; /** * @readonly * @var \Rector\PHPStanStaticTypeMapper\Utils\TypeUnwrapper */ private $typeUnwrapper; /** * @readonly * @var \Rector\NodeTypeResolver\PHPStan\Type\StaticTypeAnalyzer */ private $staticTypeAnalyzer; /** * @readonly * @var \Rector\PhpParser\Node\NodeFactory */ private $nodeFactory; public function __construct(NodeTypeResolver $nodeTypeResolver, TypeUnwrapper $typeUnwrapper, StaticTypeAnalyzer $staticTypeAnalyzer, NodeFactory $nodeFactory) { $this->nodeTypeResolver = $nodeTypeResolver; $this->typeUnwrapper = $typeUnwrapper; $this->staticTypeAnalyzer = $staticTypeAnalyzer; $this->nodeFactory = $nodeFactory; } public function boolCastOrNullCompareIfNeeded(Expr $expr) : Expr { $exprStaticType = $this->nodeTypeResolver->getType($expr); if (!TypeCombinator::containsNull($exprStaticType)) { if (!$this->isBoolCastNeeded($expr, $exprStaticType)) { return $expr; } return new Bool_($expr); } // if we remove null type, still has to be trueable if ($exprStaticType instanceof UnionType) { $unionTypeWithoutNullType = $this->typeUnwrapper->removeNullTypeFromUnionType($exprStaticType); if ($this->staticTypeAnalyzer->isAlwaysTruableType($unionTypeWithoutNullType)) { return new NotIdentical($expr, $this->nodeFactory->createNull()); } } elseif ($this->staticTypeAnalyzer->isAlwaysTruableType($exprStaticType)) { return new NotIdentical($expr, $this->nodeFactory->createNull()); } if (!$this->isBoolCastNeeded($expr, $exprStaticType)) { return $expr; } return new Bool_($expr); } private function isBoolCastNeeded(Expr $expr, Type $exprType) : bool { if ($expr instanceof BooleanNot) { return \false; } if ($exprType->isBoolean()->yes()) { return \false; } return !$expr instanceof BinaryOp; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 1
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
ExprBoolCaster.php
2.74 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).