REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.36 KB
Close
//opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Strict/Rector/Ternary/BooleanInTernaryOperatorRuleFixerRector.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Strict\Rector\Ternary; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\Ternary; use PHPStan\Analyser\Scope; use Rector\Strict\NodeFactory\ExactCompareFactory; use Rector\Strict\Rector\AbstractFalsyScalarRuleFixerRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\ConfiguredCodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * Fixer Rector for PHPStan rule: * https://github.com/phpstan/phpstan-strict-rules/blob/master/src/Rules/BooleansInConditions/BooleanInTernaryOperatorRule.php * * @see \Rector\Tests\Strict\Rector\Ternary\BooleanInTernaryOperatorRuleFixerRector\BooleanInTernaryOperatorRuleFixerRectorTest */ final class BooleanInTernaryOperatorRuleFixerRector extends AbstractFalsyScalarRuleFixerRector { /** * @readonly * @var \Rector\Strict\NodeFactory\ExactCompareFactory */ private $exactCompareFactory; public function __construct(ExactCompareFactory $exactCompareFactory) { $this->exactCompareFactory = $exactCompareFactory; } public function getRuleDefinition() : RuleDefinition { $errorMessage = \sprintf('Fixer for PHPStan reports by strict type rule - "%s"', 'PHPStan\\Rules\\BooleansInConditions\\BooleanInTernaryOperatorRule'); return new RuleDefinition($errorMessage, [new ConfiguredCodeSample(<<<'CODE_SAMPLE' final class ArrayCompare { public function run(array $data) { return $data ? 1 : 2; } } CODE_SAMPLE , <<<'CODE_SAMPLE' final class ArrayCompare { public function run(array $data) { return $data !== [] ? 1 : 2; } } CODE_SAMPLE , [self::TREAT_AS_NON_EMPTY => \false])]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Ternary::class]; } /** * @param Ternary $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Ternary { // skip short ternary if (!$node->if instanceof Expr) { return null; } $exprType = $scope->getNativeType($node->cond); $expr = $this->exactCompareFactory->createNotIdenticalFalsyCompare($exprType, $node->cond, $this->treatAsNonEmpty); if (!$expr instanceof Expr) { return null; } $node->cond = $expr; return $node; } }
Save
Close
Exit & Reset
Text mode: syntax highlighting auto-detects file type.
Directory Contents
Dirs: 0 × Files: 2
Delete Selected
Select All
Select None
Sort:
Name
Size
Modified
Enable drag-to-move
Name
Size
Perms
Modified
Actions
BooleanInTernaryOperatorRuleFixerRector.php
2.36 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
DisallowedShortTernaryRuleFixerRector.php
3.51 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).