diff --git a/src/Visitor/AttributeRewriteVisitor.php b/src/Visitor/AttributeRewriteVisitor.php index 1a89065..00a3f8a 100644 --- a/src/Visitor/AttributeRewriteVisitor.php +++ b/src/Visitor/AttributeRewriteVisitor.php @@ -204,18 +204,20 @@ protected function migrationConstruct(Node\Stmt\ClassMethod $node): Node\Stmt\Cl $newParams[] = $param; } - $codeBlock = $this->generator->getPrinter()->prettyPrint($node->getStmts()); + if (!empty($node->getStmts())) { + $codeBlock = $this->generator->getPrinter()->prettyPrint($node->getStmts()); - if ('parent::__construct(...\func_get_args());' === $codeBlock) - { - // 移除构造方法冗余代码 - $node->stmts = []; - $isModified = true; - } - else - { - // 方法存在代码块,请检查 - $this->logger->warning("Method {$this->namespace->name}\\{$this->currentClass->name}::{$node->name} has code block, please check"); + if ('parent::__construct(...\func_get_args());' === $codeBlock) + { + // 移除构造方法冗余代码 + $node->stmts = []; + $isModified = true; + } + else + { + // 方法存在代码块,请检查 + $this->logger->warning("Method {$this->namespace->name}\\{$this->currentClass->name}::{$node->name} has code block, please check"); + } } $classCommentDoc = Helper::arrayValueLast($this->currentClass->getComments()); @@ -252,10 +254,6 @@ protected function migrationConstruct(Node\Stmt\ClassMethod $node): Node\Stmt\Cl $this->handleCode->setModified(); } - if ($this->handleCode->isModified()) - { - } - return $node; }