Issues (480)

src/Request/Exception/Exception.php (1 issue)

1
<?php
2
/**
3
 *
4
 */
5
6
namespace Mvc5\Request\Exception;
7
8
use Mvc5\Http\Error;
9
use Mvc5\Http\Error\ServerError;
10
use Mvc5\Http\Request;
11
12
use const Mvc5\{ CONTROLLER, ERROR, EXCEPTION, NAME };
13
14
trait Exception
15
{
16
    /**
17
     * @var callable|mixed
18
     */
19
    protected $controller;
20
21
    /**
22
     * @var Error
23
     */
24
    protected Error $error;
25
26
    /**
27
     * @var string
28
     */
29
    protected string $name;
30
31
    /**
32
     * @param string $name
33
     * @param callable|mixed $controller
34
     * @param Error|null $error
35
     */
36 1
    function __construct(string $name, $controller, Error $error = null)
37
    {
38 1
        $this->controller = $controller;
39 1
        $this->error = $error ?? new ServerError;
0 ignored issues
show
Documentation Bug introduced by
It seems like $error ?? new Mvc5\Http\Error\ServerError() of type Mvc5\Http\Error or Mvc5\Http\Error\ServerError is incompatible with the declared type Mvc5\ERROR of property $error.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
40 1
        $this->name = $name;
41 1
    }
42
43
    /**
44
     * @param Request $request
45
     * @param \Throwable $exception
46
     * @return Request
47
     */
48 1
    function __invoke(Request $request, \Throwable $exception) : Request
49
    {
50 1
        return $request->with([
51 1
            CONTROLLER => $this->controller,
52 1
            ERROR => $this->error,
53 1
            EXCEPTION => $exception,
54 1
            NAME => $this->name
55
        ]);
56
    }
57
}
58