opt
/
cpanel
/
ea-wappspector
/
vendor
/
rector
/
rector
/
vendor
/
rector
/
rector-doctrine
/
src
/
NodeManipulator
➕ New
📤 Upload
✎ Editing:
ConstructorManipulator.php
← Back
<?php declare (strict_types=1); namespace Rector\Doctrine\NodeManipulator; use PhpParser\Node\Stmt\Class_; use PhpParser\Node\Stmt\ClassMethod; use PhpParser\Node\Stmt\Expression; use Rector\NodeManipulator\ClassInsertManipulator; use Rector\NodeTypeResolver\Node\AttributeKey; use Rector\PhpParser\Node\NodeFactory; use Rector\ValueObject\MethodName; final class ConstructorManipulator { /** * @readonly * @var \Rector\PhpParser\Node\NodeFactory */ private $nodeFactory; /** * @readonly * @var \Rector\NodeManipulator\ClassInsertManipulator */ private $classInsertManipulator; public function __construct(NodeFactory $nodeFactory, ClassInsertManipulator $classInsertManipulator) { $this->nodeFactory = $nodeFactory; $this->classInsertManipulator = $classInsertManipulator; } public function addStmtToConstructor(Class_ $class, Expression $newExpression) : void { $constructClassMethod = $class->getMethod(MethodName::CONSTRUCT); if ($constructClassMethod instanceof ClassMethod) { $constructClassMethod->stmts[] = $newExpression; } else { $constructClassMethod = $this->nodeFactory->createPublicMethod(MethodName::CONSTRUCT); $constructClassMethod->stmts[] = $newExpression; $this->classInsertManipulator->addAsFirstMethod($class, $constructClassMethod); $class->setAttribute(AttributeKey::ORIGINAL_NODE, null); } } }
💾 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