LinkRetrieval   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 19
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 19
rs 10
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A linksOf() 0 17 3
1
<?php declare(strict_types=1);
2
3
namespace Stratadox\RestResource;
4
5
use function array_map;
6
use function count;
7
8
trait LinkRetrieval
9
{
10
    private function linksOf(RestResource $resource, string $baseUri): array
11
    {
12
        if (!count($resource->links())) {
13
            return [];
14
        }
15
        return [
16
            'links' => array_map(
17
                static function (Link $link) use ($baseUri): array {
18
                    return [
19
                        'href' => $baseUri . $link->path(),
20
                        'rel' => (string) $link->type(),
21
                        'type' => $link->type()->isReadOperation() ?
22
                            'GET' :
23
                            'POST',
24
                    ];
25
                },
26
                $resource->links()->items()
27
            )
28
        ];
29
    }
30
}
31