MapCachePayloadToLoadedRoutesTrait   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 31
ccs 5
cts 5
cp 1
rs 10
wmc 1

1 Method

Rating   Name   Duplication   Size   Complexity  
A mapCachePayloadToLoadedRoutes() 0 24 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Jerowork\RouteAttributeProvider\RouteLoader\Cache;
6
7
use Generator;
8
use Jerowork\RouteAttributeProvider\RouteLoader\LoadedRoute;
9
use JsonException;
10
11
trait MapCachePayloadToLoadedRoutesTrait
12
{
13
    /**
14
     * @throws JsonException
15
     *
16
     * @return Generator<LoadedRoute>
17
     */
18 2
    public function mapCachePayloadToLoadedRoutes(string $payload) : Generator
19
    {
20
        /**
21
         * @var list<array{
22
         *      className: string,
23
         *      methodName: string,
24
         *      route: array{
25
         *       pattern: string,
26
         *       methods: string|list<string>,
27
         *       name: null|string,
28
         *       middleware: string|list<string>,
29
         *       host: null|string,
30
         *       schemes: string|list<string>,
31
         *       httpPort: null|int,
32
         *       httpsPort: null|int,
33
         *       options: array<string, mixed>
34
         *   }
35
         *  }> $loadedRoutesPayload
36
         */
37 2
        $loadedRoutesPayload = (array) json_decode($payload, true, flags: JSON_THROW_ON_ERROR);
38
39 2
        yield from array_map(
40 2
            static fn (array $payload) : LoadedRoute => LoadedRoute::fromPayload($payload),
41 2
            $loadedRoutesPayload,
42 2
        );
43
    }
44
}
45