Test Failed
Pull Request — main (#5)
by
unknown
01:49
created

LoadedRoute::fromPayload()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
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 1
    public function __construct(
14
        private string $className,
15
        private string $methodName,
16
        private Route $route
17
    ) {
18
    }
19
20
    // phpcs:enable
21
22
    /**
23
     * @param array<string,mixed> $payload
24
     */
25
    public static function fromPayload(array $payload) : self
26
    {
27
        return new self($payload['className'], $payload['methodName'], Route::fromPayload($payload['route']));
28
    }
29
30 1
    public function getClassName() : string
31
    {
32 1
        return $this->className;
33
    }
34
35 1
    public function getMethodName() : string
36
    {
37 1
        return $this->methodName;
38
    }
39
40 1
    public function getRoute() : Route
41
    {
42 1
        return $this->route;
43
    }
44
45
    /**
46
     * @return array<string,mixed>
47
     */
48
    public function jsonSerialize() : array
49
    {
50
        return [
51
            'className'  => $this->className,
52
            'methodName' => $this->methodName,
53
            'route'      => $this->route->jsonSerialize(),
54
        ];
55
    }
56
}
57