REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.33 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Strict/Rector/BooleanNot/BooleanInBooleanNotRuleFixerRector.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Strict\Rector\BooleanNot; use PhpParser\Node; use PhpParser\Node\Expr; use PhpParser\Node\Expr\BooleanNot; 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/0705fefc7c9168529fd130e341428f5f10f4f01d/src/Rules/BooleansInConditions/BooleanInBooleanNotRule.php * * @see \Rector\Tests\Strict\Rector\BooleanNot\BooleanInBooleanNotRuleFixerRector\BooleanInBooleanNotRuleFixerRectorTest */ final class BooleanInBooleanNotRuleFixerRector 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\\BooleanInBooleanNotRule'); return new RuleDefinition($errorMessage, [new ConfiguredCodeSample(<<<'CODE_SAMPLE' class SomeClass { public function run(string|null $name) { if (! $name) { return 'no name'; } return 'name'; } } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { public function run(string|null $name) { if ($name === null) { return 'no name'; } return 'name'; } } CODE_SAMPLE , [self::TREAT_AS_NON_EMPTY => \true])]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [BooleanNot::class]; } /** * @param BooleanNot $node */ public function refactorWithScope(Node $node, Scope $scope) : ?Expr { $exprType = $scope->getNativeType($node->expr); if ($exprType->isBoolean()->yes()) { return null; } return $this->exactCompareFactory->createIdenticalFalsyCompare($exprType, $node->expr, $this->treatAsNonEmpty); } }
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
BooleanInBooleanNotRuleFixerRector.php
2.33 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).