Completed
Push — master ( 5d917b...4d3943 )
by Dominik
08:16 queued 03:19
created

Link   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 0
dl 0
loc 46
ccs 11
cts 11
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A jsonSerialize() 0 13 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Chubbyphp\Serialization\Link;
6
7
final class Link implements LinkInterface
8
{
9
    /**
10
     * @var string
11
     */
12
    private $href;
13
14
    /**
15
     * @var string
16
     */
17
    private $method;
18
19
    /**
20
     * @var array
21
     */
22
    private $attributes;
23
24
    /**
25
     * @param string     $href
26
     * @param string     $method
27
     * @param array|null $attributes
28
     */
29 2
    public function __construct($href, $method, array $attributes = null)
30
    {
31 2
        $this->href = $href;
32 2
        $this->method = $method;
33 2
        $this->attributes = $attributes;
0 ignored issues
show
Documentation Bug introduced by
It seems like $attributes can be null. However, the property $attributes is declared as array. Maybe change the type of the property to array|null or add a type check?

Our type inference engine has found an assignment of a scalar value (like a string, an integer or null) to a property which is an array.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property.

To type hint that a parameter can be either an array or null, you can set a type hint of array and a default value of null. The PHP interpreter will then accept both an array or null for that parameter.

function aContainsB(array $needle = null, array  $haystack) {
    if (!$needle) {
        return false;
    }

    return array_intersect($haystack, $needle) == $haystack;
}

The function can be called with either null or an array for the parameter $needle but will only accept an array as $haystack.

Loading history...
34 2
    }
35
36
    /**
37
     * @return array
38
     */
39 2
    public function jsonSerialize(): array
40
    {
41
        $data = [
42 2
            'href' => $this->href,
43 2
            'method' => $this->method,
44
        ];
45
46 2
        if (null !== $this->attributes) {
47 1
            $data['attributes'] = $this->attributes;
48
        }
49
50 2
        return $data;
51
    }
52
}
53