From 67d01b579b139289ec7c2fc692f88bd0a26fd174 Mon Sep 17 00:00:00 2001 From: augushong Date: Sat, 19 Nov 2022 18:07:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=B3=A8=E9=87=8A=E5=8E=BB?= =?UTF-8?q?=E9=99=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../tools/phpparser/NodeVisitorTools.php | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/app/common/tools/phpparser/NodeVisitorTools.php b/app/common/tools/phpparser/NodeVisitorTools.php index 7535b79..699387b 100644 --- a/app/common/tools/phpparser/NodeVisitorTools.php +++ b/app/common/tools/phpparser/NodeVisitorTools.php @@ -3,6 +3,7 @@ namespace app\common\tools\phpparser; use PhpParser\Comment; +use PhpParser\Comment\Doc; use PhpParser\Node; use PhpParser\Node\Expr\ClassConstFetch; use PhpParser\Node\Expr\Instanceof_; @@ -53,22 +54,19 @@ class NodeVisitorTools extends NodeVisitorAbstract public function leaveNode(Node $node) { - if ($node instanceof Node) { - if (isset($node->attributes['comments'])) { - - $comments = $node->attributes['comments']; - $new_comments = []; - foreach ($comments as $comment_item) { - if ($comment_item instanceof Comment) { - } else { - $new_comments[] = $comment_item; - } - } - - $node->attributes['comments'] = $new_comments; + $comments = $node->getComments(); + if (!empty($comments)) { + $new_comments = []; + foreach ($comments as $comment_item) { + if ($comment_item instanceof Doc) { + $new_comments[] = $comment_item; + } } + + $node->setAttribute('comments', $new_comments); } + if ($node instanceof Use_) { foreach ($node->uses as &$use_item) {