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); } } }