Passed
Pull Request — master (#15)
by Alexander
01:46
created

Route::__toString()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace alkemann\h2l;
4
5
use Closure;
6
7
/**
8
 * Class Route
9
 *
10
 * @package alkemann\h2l
11
 */
12
class Route
13
{
14
15
    /**
16
     * @var string
17
     */
18
    private $url;
19
    /**
20
     * @var Closure
21
     */
22
    private $callback;
23
    /**
24
     * @var array
25
     */
26
    private $parameters;
27
28
    /**
29
     * Route constructor.
30
     *
31
     * @param string $url
32
     * @param Closure|null $cb
33
     * @param array $parameters
34
     */
35
    public function __construct(string $url, ?Closure $cb = null, array $parameters = [])
36
    {
37
        $this->url = $url;
38
        $this->callback = $cb;
39
        $this->parameters = $parameters;
40
    }
41
42
    public function url(): string
43
    {
44
        return $this->url;
45
    }
46
47
    public function parameters(): array
48
    {
49
        return $this->parameters;
50
    }
51
52
    public function __invoke(Request $request): Response
53
    {
54
        return call_user_func_array($this->callback, [$request]);
0 ignored issues
show
Bug Best Practice introduced by
The expression return call_user_func_ar...lback, array($request)) returns the type mixed which includes types incompatible with the type-hinted return alkemann\h2l\Response.
Loading history...
55
    }
56
57
    public function __toString(): string
58
    {
59
        return $this->url;
60
    }
61
}
62