php-http/mock-client

Type hinting incoherence for exceptions

soullivaneuh opened this issue · 4 comments

Q A
Bug? no
New Feature? no
Version v1.0.1

On the exceptions property:

/**
* @var Exception[]
*/
private $exceptions = [];

The type hinting corresponds to Http\Client\Exception

But on the adder:

/**
* Adds an exception that will be thrown.
*
* @param \Exception $exception
*/
public function addException(\Exception $exception)
{
$this->exceptions[] = $exception;
}

It corresponds to \Exception.

AFAIK, it makes no sense. Which one should be choose?

I may add a PR after getting #21 merged.

Using Http\Client\Exception is the correct one since clients MUST NOT throw exceptions that does not implement this interface.

dbu commented

lets change the typehint on the private field, to not lie. but lets also add a comment that according to the spec this must be a http exception. changing the add method would be a bc break, and if people use custom plugins they might deliberately violate the contract, so it seems to me there are use cases for it. want to do a PR @soullivaneuh ?

@dbu In this case, why not trigger a deprecation error if the passed parameter is something else than a Http\Client\Exception instance and move the typing on a next major?

dbu commented

deprecation warning is a good idea, yes.