LoadedRoute::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
c 3
b 0
f 0
nc 1
nop 3
dl 0
loc 5
ccs 1
cts 1
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\RouteAttributeProvider\RouteLoader;
6
7
use Jerowork\RouteAttributeProvider\Api\Route;
8
use JsonSerializable;
9
10
final class LoadedRoute implements JsonSerializable
11
{
12
    // phpcs:disable
13 9
    public function __construct(
14
        private string $className,
15
        private string $methodName,
16
        private Route $route,
17
    ) {
18 9
    }
19
20
    // phpcs:enable
21
22
    /**
23
     * @param array{
24
     *     className: string,
25
     *     methodName: string,
26
     *     route: array{
27
     *      pattern: string,
28
     *      methods: string|list<string>,
29
     *      name: null|string,
30
     *      middleware: string|list<string>,
31
     *      host: null|string,
32
     *      schemes: string|list<string>,
33
     *      httpPort: null|int,
34
     *      httpsPort: null|int,
35
     *      options: array<string, mixed>
36
     *  }
37
     * } $payload
38
     */
39 3
    public static function fromPayload(array $payload) : self
40
    {
41 3
        return new self($payload['className'], $payload['methodName'], Route::fromPayload($payload['route']));
42
    }
43
44 4
    public function getClassName() : string
45
    {
46 4
        return $this->className;
47
    }
48
49 4
    public function getMethodName() : string
50
    {
51 4
        return $this->methodName;
52
    }
53
54 4
    public function getRoute() : Route
55
    {
56 4
        return $this->route;
57
    }
58
59
    /**
60
     * @return array<string,mixed>
61
     */
62 4
    public function jsonSerialize() : array
63
    {
64 4
        return [
65 4
            'className'  => $this->className,
66 4
            'methodName' => $this->methodName,
67 4
            'route'      => $this->route->jsonSerialize(),
68 4
        ];
69
    }
70
}
71