Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ProblemDetailsMiddleware::attachListener does also allow object&callable #43

Open
boesing opened this issue Sep 13, 2023 · 1 comment
Open
Labels
Bug Something isn't working

Comments

@boesing
Copy link
Member

boesing commented Sep 13, 2023

Bug Report

Q A
Version(s) 1.11.0

Summary

ProblemDetailsMiddleware::attachListener does also allow object&callable

Current behavior

Argument 1 of Mezzio\ProblemDetails\ProblemDetailsMiddleware::attachListener expects callable(Throwable, Psr\Http\Message\RequestInterface, Psr\Http\Message\ResponseInterface):void, but parent type Application\ProblemDetails\NonProblemResponseListener provided

How to reproduce

use Mezzio\ProblemDetails\Exception\ProblemDetailsExceptionInterface;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Throwable;

final class Foo
{
   public function __invoke(Throwable $error, ServerRequestInterface $request, ResponseInterface $response): void
   {}
}

/** @var Mezzio\ProblemDetails\ProblemDetailsMiddleware $middleware */
$middleware = null;
$middleware->attachListener(new Foo());

Expected behavior

No psalm error.

@boesing boesing added the Bug Something isn't working label Sep 13, 2023
@boesing
Copy link
Member Author

boesing commented Sep 13, 2023

With one of the more frequent versions of psalm I've added support for object&callable.

I'd recommend moving the callable type to a @psalm-type which allows you to re-use it like:

/** @psalm-type ListenerCallableType = callable(Throwable, RequestInterface, ResponseInterface):void */
class Middleware
{
    /**
     * @param ListenerCallableType|(object&ListenerCallableType) $listener
     */
    public function attachListener(callable $listener): void

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant