fix(php): 修复PHP翻译器中的路径验证和错误消息问题

- 添加对空路径的验证并显示相应错误消息
- 修正路径判断逻辑使用严格比较操作符
- 在类解析中添加对枚举类型的处理
- 修复方法重写错误消息中类名的显示问题
pull/1/head
韩天峰 3 months ago
parent 8aa1745e1d
commit 68bd54c6c3
  1. 8
      src/Php/Translator.php

@ -1613,7 +1613,10 @@ CODE;
protected function getAbsolutePath(string $path, string $projectDir): string
{
$path = trim($path);
if ($path[0] != '/') {
if ($path === '') {
$this->error('Source path must not be empty');
}
if ($path[0] !== '/') {
$absPath = $projectDir . '/' . $path;
} else {
$absPath = $path;
@ -1948,6 +1951,7 @@ CODE;
switch ($type2) {
case 'Stmt_Class':
case 'Stmt_Trait':
case 'Stmt_Enum':
$code .= $this->parseClass($v2);
break;
case 'Stmt_Const':
@ -2496,7 +2500,7 @@ CODE;
_error:
$this->fatalError($v,
'Cannot override private method `' .
$classDef->getNamespacedName(false) . '::' . $this->method . '()`');
$extends . '::' . $this->method . '()`');
}
}
}

Loading…
Cancel
Save