LoadedRoute   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 9
c 4
b 0
f 0
dl 0
loc 58
ccs 15
cts 15
cp 1
rs 10
wmc 6

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A getMethodName() 0 3 1
A fromPayload() 0 3 1
A getClassName() 0 3 1
A getRoute() 0 3 1
A jsonSerialize() 0 6 1
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