Skip to content

Commit

Permalink
修复 static 类型的解析处理 (#590)
Browse files Browse the repository at this point in the history
* 修复 static 类型的解析处理

* 修复

* 修复并增加测试
  • Loading branch information
Yurunsoft committed Oct 17, 2023
1 parent 5d2eeb9 commit 3c293a9
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Bean/ReflectionUtil.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static function getTypeComments(?\ReflectionType $type, ?string $classNam
$typeStr = '\\' . $className;
}
}
else
elseif ('static' !== $typeStr)
{
$typeStr = '\\' . $typeStr;
}
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function getTypeCode(?\ReflectionType $type, ?string $className =
$typeStr = '\\' . $className;
}
}
else
elseif ('static' !== $typeStr)
{
$typeStr = '\\' . $typeStr;
}
Expand Down
22 changes: 22 additions & 0 deletions tests/unit/Component/Tests/BeanTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ public function testGetTypeComments(): void
CODE);
$rf = new \ReflectionFunction($f);
$this->assertEquals('string|int', ReflectionUtil::getTypeComments($rf->getReturnType()));

$c = Imi::eval(<<<'CODE'
return new class() {
public function test(): static
{
return $this;
}
};
CODE);
$rf = new \ReflectionMethod($c, 'test');
$this->assertEquals('static', ReflectionUtil::getTypeComments($rf->getReturnType()));
}

// @phpstan-ignore-next-line
Expand Down Expand Up @@ -157,6 +168,17 @@ public function testGetTypeCode(): void
CODE);
$rf = new \ReflectionFunction($f);
$this->assertEquals('string|int', ReflectionUtil::getTypeCode($rf->getReturnType()));

$c = Imi::eval(<<<'CODE'
return new class() {
public function test(): static
{
return $this;
}
};
CODE);
$rf = new \ReflectionMethod($c, 'test');
$this->assertEquals('static', ReflectionUtil::getTypeCode($rf->getReturnType()));
}

// @phpstan-ignore-next-line
Expand Down

0 comments on commit 3c293a9

Please sign in to comment.