PhpStorm - 流畅的界面
PhpStorm - fluent interface
在 class 中使用流畅的界面并尝试从 class
的另一个函数中逐个调用此 class 的函数时
f.e.
mainFunction()
{
$this
->func1()
->func2()
->func3()
->func4()
->func5()
;
}
在调用第 4 个函数后,PhpStorm 无法将调用与函数定义连接起来,因此第 5 个函数定义获取信息
Unused private method func5 Direct usages of the private method are
not found.
并且调用获取信息
Method 'func5' not found in Referenced method is not found in
subject class.
是否为此设置了任何可配置的限制?
您 运行 发现了 PhpStorm 6 的一个已知错误,正式应该在版本
中修复
8.0.4 (139.1803): WI-17801 Fluent-style chaining type loss with return this/static
你可以 work-around 这个问题,如果你将类名指定为 return 类型:
class FooBar
{
// ...
private function func1(): FooBar
{
return $this;
}
// ...
}
或者,对于旧的 PHP 版本,
class FooBar
{
// ...
/**
* @return FooBar
*/
private function func1()
{
return $this;
}
// ...
}
在 class 中使用流畅的界面并尝试从 class
的另一个函数中逐个调用此 class 的函数时f.e.
mainFunction()
{
$this
->func1()
->func2()
->func3()
->func4()
->func5()
;
}
在调用第 4 个函数后,PhpStorm 无法将调用与函数定义连接起来,因此第 5 个函数定义获取信息
Unused private method func5 Direct usages of the private method are not found.
并且调用获取信息
Method 'func5' not found in Referenced method is not found in subject class.
是否为此设置了任何可配置的限制?
您 运行 发现了 PhpStorm 6 的一个已知错误,正式应该在版本
中修复
8.0.4 (139.1803): WI-17801 Fluent-style chaining type loss with return this/static
你可以 work-around 这个问题,如果你将类名指定为 return 类型:
class FooBar
{
// ...
private function func1(): FooBar
{
return $this;
}
// ...
}
或者,对于旧的 PHP 版本,
class FooBar
{
// ...
/**
* @return FooBar
*/
private function func1()
{
return $this;
}
// ...
}