opt
/
cpanel
/
ea-wappspector
/
vendor
/
rector
/
rector
/
rules
/
CodingStyle
/
Rector
/
Property
➕ New
📤 Upload
✎ Editing:
SplitGroupedPropertiesRector.php
← Back
<?php declare (strict_types=1); namespace Rector\CodingStyle\Rector\Property; use PhpParser\Node; use PhpParser\Node\Stmt\Property; use PhpParser\Node\Stmt\PropertyProperty; use Rector\Rector\AbstractRector; use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; /** * @see \Rector\Tests\CodingStyle\Rector\Property\SplitGroupedPropertiesRector\SplitGroupedPropertiesRectorTest */ final class SplitGroupedPropertiesRector extends AbstractRector { public function getRuleDefinition() : RuleDefinition { return new RuleDefinition('Separate grouped properties to own lines', [new CodeSample(<<<'CODE_SAMPLE' class SomeClass { /** * @var string */ public $isIt, $isIsThough; } CODE_SAMPLE , <<<'CODE_SAMPLE' class SomeClass { /** * @var string */ public $isIt; /** * @var string */ public $isIsThough; } CODE_SAMPLE )]); } /** * @return array<class-string<Node>> */ public function getNodeTypes() : array { return [Property::class]; } /** * @param Property $node * @return Property[]|null */ public function refactor(Node $node) : ?array { $allProperties = $node->props; if (\count($allProperties) === 1) { return null; } /** @var PropertyProperty $firstPropertyProperty */ $firstPropertyProperty = \array_shift($allProperties); $node->props = [$firstPropertyProperty]; $nextProperties = []; foreach ($allProperties as $allProperty) { $nextProperties[] = new Property($node->flags, [$allProperty], $node->getAttributes()); } return \array_merge([$node], $nextProperties); } }
💾 Save Changes
Cancel
📤 Upload File
×
Select File
Upload
Cancel
➕ Create New
×
Type
📄 File
📁 Folder
Name
Create
Cancel
✎ Rename Item
×
Current Name
New Name
Rename
Cancel
🔐 Change Permissions
×
Target File
Permission (e.g., 0755, 0644)
0755
0644
0777
Apply
Cancel