REDROOM
PHP 8.2.31
Path:
Logout
Edit File
Size: 2.20 KB
Close
/opt/cpanel/ea-wappspector/vendor/rector/rector/rules/Php74/Rector/ArrayDimFetch/CurlyToSquareBracketArrayStringRector.php
Text
Base64
<?php declare (strict_types=1); namespace Rector\Php74\Rector\ArrayDimFetch; use PhpParser\Node; use PhpParser\Node\Expr\ArrayDimFetch; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\Rector\AbstractRector; use Rector\ValueObject\Application\File; 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\ArrayDimFetch\CurlyToSquareBracketArrayStringRector\CurlyToSquareBracketArrayStringRectorTest */ final class CurlyToSquareBracketArrayStringRector extends AbstractRector implements MinPhpVersionInterface { public function provideMinPhpVersion() : int { return PhpVersionFeature::DEPRECATE_CURLY_BRACKET_ARRAY_STRING; } public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Change curly based array and string to square bracket', [new CodeSample(<<<'CODE_SAMPLE' $string = 'test'; echo $string{0}; $array = ['test']; echo $array{0}; CODE_SAMPLE , <<<'CODE_SAMPLE' $string = 'test'; echo $string[0]; $array = ['test']; echo $array[0]; CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [ArrayDimFetch::class]; } /** * @param ArrayDimFetch $node */ public function refactor(Node $node) : ?Node { if (!$this->isFollowedByCurlyBracket($this->file, $node)) { return null; } // re-draw the ArrayDimFetch to use [] bracket $node->setAttribute(AttributeKey::ORIGINAL_NODE, null); return $node; } private function isFollowedByCurlyBracket(File $file, ArrayDimFetch $arrayDimFetch) : bool { $oldTokens = $file->getOldTokens(); $endTokenPost = $arrayDimFetch->getEndTokenPos(); if (isset($oldTokens[$endTokenPost]) && $oldTokens[$endTokenPost] === '}') { $startTokenPost = $arrayDimFetch->getStartTokenPos(); return !(isset($oldTokens[$startTokenPost][1]) && $oldTokens[$startTokenPost][1] === '${'); } return \false; } }
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
CurlyToSquareBracketArrayStringRector.php
2.20 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).