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

LoadedRoute   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 53.85%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 44
ccs 7
cts 13
cp 0.5385
rs 10
wmc 6

6 Methods

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