Passed
Push — feature/initial-implementation ( fae671...591f29 )
by Fike
02:37
created

Node::setValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace AmaTeam\ElasticSearch\API\Entity\Descriptor\Hierarchy;
4
5
use AmaTeam\ElasticSearch\API\Entity\DescriptorInterface;
6
7
class Node implements NodeInterface
8
{
9
    /**
10
     * @var DescriptorInterface
11
     */
12
    private $value;
13
    /**
14
     * @var DescriptorInterface[]
15
     */
16
    private $parents = [];
17
18
    /**
19
     * @param DescriptorInterface $value
20
     */
21
    public function __construct(DescriptorInterface $value = null)
22
    {
23
        $this->value = $value;
24
    }
25
26
    /**
27
     * @return DescriptorInterface
28
     */
29
    public function getValue(): DescriptorInterface
30
    {
31
        return $this->value;
32
    }
33
34
    /**
35
     * @param DescriptorInterface $value
36
     * @return $this
37
     */
38
    public function setValue(DescriptorInterface $value): Node
39
    {
40
        $this->value = $value;
41
        return $this;
42
    }
43
44
    /**
45
     * @return DescriptorInterface[]
46
     */
47
    public function getParents(): array
48
    {
49
        return $this->parents;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this->parents returns the type AmaTeam\ElasticSearch\AP...y\DescriptorInterface[] which is incompatible with the return type mandated by AmaTeam\ElasticSearch\AP...Interface::getParents() of AmaTeam\ElasticSearch\AP...erarchy\NodeInterface[].

In the issue above, the returned value is violating the contract defined by the mentioned interface.

Let's take a look at an example:

interface HasName {
    /** @return string */
    public function getName();
}

class Name {
    public $name;
}

class User implements HasName {
    /** @return string|Name */
    public function getName() {
        return new Name('foo'); // This is a violation of the ``HasName`` interface
                                // which only allows a string value to be returned.
    }
}
Loading history...
50
    }
51
52
    /**
53
     * @param DescriptorInterface[] $parents
54
     * @return $this
55
     */
56
    public function setParents(array $parents): Node
57
    {
58
        $this->parents = $parents;
59
        return $this;
60
    }
61
}
62