These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | |||
3 | namespace Nip\Inflector\Traits; |
||
4 | |||
5 | use Nip\Inflector\Inflector; |
||
6 | |||
7 | /** |
||
8 | * Trait MagicMethodsTrait |
||
9 | * @package Nip\Inflector\Traits |
||
10 | */ |
||
11 | trait MagicMethodsTrait |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * @param $name |
||
16 | * @param $arguments |
||
17 | * @return string |
||
18 | */ |
||
19 | 19 | public function __call($name, $arguments) |
|
20 | { |
||
21 | 19 | if ($this->hasInflection($name)) { |
|
0 ignored issues
–
show
|
|||
22 | 19 | return $this->doInflection($name, $arguments[0]); |
|
0 ignored issues
–
show
The method
doInflection does not exist on object<Nip\Inflector\Traits\MagicMethodsTrait> ? Since you implemented __call , maybe consider adding a @method annotation.
If you implement This is often the case, when class ParentClass {
private $data = array();
public function __call($method, array $args) {
if (0 === strpos($method, 'get')) {
return $this->data[strtolower(substr($method, 3))];
}
throw new \LogicException(sprintf('Unsupported method: %s', $method));
}
}
/**
* If this class knows which fields exist, you can specify the methods here:
*
* @method string getName()
*/
class SomeClass extends ParentClass { }
Loading history...
|
|||
23 | } |
||
24 | throw new \BadFunctionCallException("invalid inflection {$name}"); |
||
25 | } |
||
26 | |||
27 | /** |
||
28 | * @param $name |
||
29 | * @param $arguments |
||
30 | * @return mixed |
||
31 | */ |
||
32 | public static function __callStatic($name, $arguments) |
||
33 | { |
||
34 | return (new Inflector())->doInflection($name, $arguments[0]); |
||
35 | } |
||
36 | } |
||
37 |
If you implement
__call
and you know which methods are available, you can improve IDE auto-completion and static analysis by adding a @method annotation to the class.This is often the case, when
__call
is implemented by a parent class and only the child class knows which methods exist: