REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.07 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Php74/Rector/Ternary/ParenthesizeNestedTernaryRector.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Php74\Rector\Ternary; use PhpParser\Node; use PhpParser\Node\Expr\Ternary; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Php74\Tokenizer\ParenthesizedNestedTernaryAnalyzer; 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\Php74\Rector\Ternary\ParenthesizeNestedTernaryRector\ParenthesizeNestedTernaryRectorTest */ final class ParenthesizeNestedTernaryRector extends AbstractRector implements MinPhpVersionInterface { /** * @readonly * @var \Rector\Php74\Tokenizer\ParenthesizedNestedTernaryAnalyzer */ private $parenthesizedNestedTernaryAnalyzer; public function __construct(ParenthesizedNestedTernaryAnalyzer $parenthesizedNestedTernaryAnalyzer) { $this->parenthesizedNestedTernaryAnalyzer = $parenthesizedNestedTernaryAnalyzer; } public function provideMinPhpVersion() : int { return PhpVersionFeature::DEPRECATE_NESTED_TERNARY; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Add parentheses to nested ternary', [new CodeSample(<<<'CODE_SAMPLE' $value = $a ? $b : $a ?: null; CODE_SAMPLE , <<<'CODE_SAMPLE' $value = ($a ? $b : $a) ?: null; CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Ternary::class]; } /** * @param Ternary $node */ public function refactor(Node $node) : ?Node { if ($node->cond instanceof Ternary || $node->else instanceof Ternary) { if ($this->parenthesizedNestedTernaryAnalyzer->isParenthesized($this->file, $node)) { return null; } // re-print with brackets $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); return $node; } return null; } }
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
ParenthesizeNestedTernaryRector.php
2.07 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).