Passed
Push — main ( a6206c...f35a3d )
by Jeroen
10:10
created

LoadedRoute::jsonSerialize()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 4
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 6
ccs 4
cts 4
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 11
    public function __construct(
14
        private string $className,
0 ignored issues
show
Unused Code introduced by
The parameter $className is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

14
        /** @scrutinizer ignore-unused */ private string $className,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
15
        private string $methodName,
0 ignored issues
show
Unused Code introduced by
The parameter $methodName is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

15
        /** @scrutinizer ignore-unused */ private string $methodName,

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
16
        private Route $route
0 ignored issues
show
Unused Code introduced by
The parameter $route is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

16
        /** @scrutinizer ignore-unused */ private Route $route

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
17
    ) {
18 11
    }
19
    // phpcs:enable
20
21
    /**
22
     * @param array<string,mixed> $payload
23
     */
24 3
    public static function fromPayload(array $payload): self
25
    {
26 3
        return new self($payload['className'], $payload['methodName'], Route::fromPayload($payload['route']));
27
    }
28
29 6
    public function getClassName(): string
30
    {
31 6
        return $this->className;
0 ignored issues
show
Bug Best Practice introduced by
The property className does not exist on Jerowork\RouteAttributeP...RouteLoader\LoadedRoute. Did you maybe forget to declare it?
Loading history...
32
    }
33
34 6
    public function getMethodName(): string
35
    {
36 6
        return $this->methodName;
0 ignored issues
show
Bug Best Practice introduced by
The property methodName does not exist on Jerowork\RouteAttributeP...RouteLoader\LoadedRoute. Did you maybe forget to declare it?
Loading history...
37
    }
38
39 6
    public function getRoute(): Route
40
    {
41 6
        return $this->route;
0 ignored issues
show
Bug Best Practice introduced by
The property route does not exist on Jerowork\RouteAttributeP...RouteLoader\LoadedRoute. Did you maybe forget to declare it?
Loading history...
42
    }
43
44
    /**
45
     * @return array<string,mixed>
46
     */
47 4
    public function jsonSerialize(): array
48
    {
49
        return [
50 4
            'className'  => $this->className,
0 ignored issues
show
Bug Best Practice introduced by
The property className does not exist on Jerowork\RouteAttributeP...RouteLoader\LoadedRoute. Did you maybe forget to declare it?
Loading history...
51 4
            'methodName' => $this->methodName,
0 ignored issues
show
Bug Best Practice introduced by
The property methodName does not exist on Jerowork\RouteAttributeP...RouteLoader\LoadedRoute. Did you maybe forget to declare it?
Loading history...
52 4
            'route'      => $this->route->jsonSerialize(),
0 ignored issues
show
Bug Best Practice introduced by
The property route does not exist on Jerowork\RouteAttributeP...RouteLoader\LoadedRoute. Did you maybe forget to declare it?
Loading history...
53
        ];
54
    }
55
}
56