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;
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([
0 ignored issues
show
Bug Best Practice introduced by
The expression return $request->with(ar...5\NAME => $this->name)) returns the type Mvc5\Config\Model which includes types incompatible with the type-hinted return Mvc5\Http\Request.
Loading history...
51 1
            CONTROLLER => $this->controller,
52 1
            ERROR => $this->error,
53 1
            EXCEPTION => $exception,
54 1
            NAME => $this->name
55
        ]);
56
    }
57
}
58