refactor(Php): 优化 get_class 函数调用处理逻辑

- 将 get_class 函数的处理逻辑提取到独立的 genGetClass 方法中
- 保留原有的类型检查和字面量字符串生成功能
- 简化主方法中的条件判断结构
- 提高代码可读性和维护性
pull/1/head
韩天峰 5 months ago
parent 26a0439f42
commit f6cb3278cb
  1. 14
      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) . ')';
}
}

Loading…
Cancel
Save