From f6cb3278cb0e480346be7bda11f9f4594ae7ad7c Mon Sep 17 00:00:00 2001 From: tianfenghan Date: Fri, 3 Apr 2026 19:48:59 +0800 Subject: [PATCH] =?UTF-8?q?refactor(Php):=20=E4=BC=98=E5=8C=96=20get=5Fcla?= =?UTF-8?q?ss=20=E5=87=BD=E6=95=B0=E8=B0=83=E7=94=A8=E5=A4=84=E7=90=86?= =?UTF-8?q?=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 将 get_class 函数的处理逻辑提取到独立的 genGetClass 方法中 - 保留原有的类型检查和字面量字符串生成功能 - 简化主方法中的条件判断结构 - 提高代码可读性和维护性 --- src/Php/FuncCallOptimizer.php | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/Php/FuncCallOptimizer.php b/src/Php/FuncCallOptimizer.php index b3787be2..6e4d4710 100644 --- a/src/Php/FuncCallOptimizer.php +++ b/src/Php/FuncCallOptimizer.php @@ -116,10 +116,7 @@ trait FuncCallOptimizer } } if ($name === 'get_class') { - $object = $expr->args[0]->value; - if ($this->isVarExpr($object) and $this->isTypedObject($object->name)) { - return $this->genCharPtr($this->getObjectType($object->name)); - } + return $this->genGetClass($expr); } return false; } @@ -150,5 +147,12 @@ trait FuncCallOptimizer return 'php::fn::function_exists(' . $this->parseIdentifier($funcName) . ')'; } - + protected function genGetClass(Node\Expr\FuncCall $expr): string + { + $object = $expr->args[0]->value; + if ($this->isVarExpr($object) and $this->isTypedObject($object->name)) { + return $this->getLiteralString($this->getObjectType($object->name)); + } + return 'php::fn::get_class(' . $this->parseIdentifier($object) . ')'; + } }