Problem with Consistence.Exceptions.ExceptionDeclaration
lookyman opened this issue · comments
use Throwable;
class InvalidResponseException extends Exception
{
public function __construct(Validator $validator, ?Throwable $previous = null)
{
// ...
}
This reports Exception is not chainable. It must have optional \Throwable as last constructor argument and has "Throwable".
Is this the whole class? As in there is no namespace? (I see no PHP open tag and Exception
is not used while Throwable
is, so it seems pretty suspicious to me).
Nope, of course it's not a whole class 😊 It's just an excerpt to show the issue. The problem seems to be here.
This problem is not fixed in https://github.com/consistence-community/coding-standard/pull/3/files - condition accepts only FCQN.
Use
if (
!in_array($lastArgument->getTypeHint(), ['\Throwable', '?\Throwable', 'Throwable', '?Throwable'], true)
&& !StringHelper::endsWith($lastArgument->getTypeHint(), 'Exception')
&& !StringHelper::endsWith($lastArgument->getTypeHint(), 'Error')
)
instead of line 119 where was added: $lastArgument->getTypeHint() !== '?\Throwable'