Skip to content

Commit

Permalink
update: 修复构造函数误报
Browse files Browse the repository at this point in the history
  • Loading branch information
NHZEX committed Nov 2, 2023
1 parent 716c1b1 commit 097788a
Showing 1 changed file with 13 additions and 15 deletions.
28 changes: 13 additions & 15 deletions src/Visitor/AttributeRewriteVisitor.php
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -252,10 +254,6 @@ protected function migrationConstruct(Node\Stmt\ClassMethod $node): Node\Stmt\Cl
$this->handleCode->setModified();
}

if ($this->handleCode->isModified())
{
}

return $node;
}

Expand Down

0 comments on commit 097788a

Please sign in to comment.