I'm using Respect/Validation class and I have custom rule CustomRule()
which works fine:
use Respect\Validation\Validator as v;
// ...
'email' => v::CustomRule()->email()->setName('email');
But this causes PHPStan to throw an error:
Call to an undefined static method Respect\Validation\Validator::CustomRule().
But if I move it after a built-in rule (e.g., email()
), PHPStan works fine, no errors:
'email' => v::email()->CustomRule()->setName('email');
To be clear, both code works but PHPStan thinks the first code is invalid.
Any workaround so that PHPStan will accept it even if CustomRule()
was set first?
Update:
I've found that if I edit the doc block of Respect\Validation\Validator
class and append my custom rule to the list of its built-in rules, it works!
/**
* ...
* @method static Validator CustomRule()
*/
class Validator extends AllOf
...
Of course it's a bad idea to directly modify the doc block from the main class. That said, my question still remains the same. Or, maybe is there a way for PHPStan to honor my own doc block from my CustomRule
class?