Passed
Pull Request — master (#15)
by
unknown
02:36
created

LinkNormalizer   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 1
dl 0
loc 34
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A normalizeLink() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Normalizer;
6
7
use Chubbyphp\Serialization\SerializerLogicException;
8
use Psr\Link\LinkInterface;
9
10
final class LinkNormalizer implements LinkNormalizerInterface
11
{
12
    /**
13
     * @var LinkInterface
14
     */
15
    private $link;
16
17
    /**
18
     * @param LinkInterface $link
19
     */
20 1
    public function __construct(LinkInterface $link)
21
    {
22 1
        $this->link = $link;
23 1
    }
24
25
    /**
26
     * @param string                     $path
27
     * @param object|mixed               $object
28
     * @param NormalizerContextInterface $context
29
     *
30
     * @return array|null
31
     *
32
     * @throws SerializerLogicException
33
     */
34 1
    public function normalizeLink(string $path, $object, NormalizerContextInterface $context)
35
    {
36
        return [
37 1
            'href' => $this->link->getHref(),
38 1
            'templated' => $this->link->isTemplated(),
39 1
            'rel' => $this->link->getRels(),
40 1
            'attributes' => $this->link->getAttributes(),
41
        ];
42
    }
43
}
44