Test Failed
Push — master ( 5a9473...a9c3a3 )
by Dominik
02:12
created

CallbackLinkNormalizer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 45
ccs 13
cts 13
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 21 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Normalizer;
6
7
use Psr\Link\LinkInterface;
8
use Psr\Http\Message\ServerRequestInterface as Request;
9
10
final class CallbackLinkNormalizer implements LinkNormalizerInterface
11
{
12
    /**
13
     * @var callable
14
     */
15
    private $callback;
16
17
    /**
18
     * @param callable $callback
19
     */
20 2
    public function __construct(callable $callback)
21
    {
22 2
        $this->callback = $callback;
23 2
    }
24
25
    /**
26
     * @param string                     $path
27
     * @param Request                    $request
28
     * @param object                     $object
29
     * @param NormalizerContextInterface $context
30
     *
31
     * @return array|null
32
     */
33 2
    public function normalizeLink(string $path, Request $request, $object, NormalizerContextInterface $context)
34
    {
35 2
        $callback = $this->callback;
36
37 2
        $link = $callback($path, $request, $object, $context);
38
39 2
        if (null === $link) {
40 1
            return null;
41
        }
42
43 1
        if (!$link instanceof LinkInterface) {
0 ignored issues
show
Unused Code introduced by
This if statement is empty and can be removed.

This check looks for the bodies of if statements that have no statements or where all statements have been commented out. This may be the result of changes for debugging or the code may simply be obsolete.

These if bodies can be removed. If you have an empty if but statements in the else branch, consider inverting the condition.

if (rand(1, 6) > 3) {
//print "Check failed";
} else {
    print "Check succeeded";
}

could be turned into

if (rand(1, 6) <= 3) {
    print "Check succeeded";
}

This is much more concise to read.

Loading history...
44
            // todo: exception
45
        }
46
47
        return [
48 1
            'href' => $link->getHref(),
49 1
            'templated' => $link->isTemplated(),
50 1
            'rel' => $link->getRels(),
51 1
            'attributes' => $link->getAttributes(),
52
        ];
53
    }
54
}
55