AbstractUnit::getParent()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Maketok\DataMigration\Unit;
4
5
abstract class AbstractUnit implements UnitInterface
6
{
7
    /**
8
     * @var string
9
     */
10
    protected $code;
11
    /**
12
     * @var UnitInterface
13
     */
14
    protected $parent;
15
    /**
16
     * @var UnitInterface[]
17
     */
18
    protected $siblings = [];
19
20
    /**
21
     * @param string $code
22
     */
23 56
    public function __construct($code)
24
    {
25 56
        $this->code = $code;
26 56
    }
27
28
    /**
29
     * @return string
30
     */
31 56
    public function getCode()
32
    {
33 56
        return $this->code;
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39 44
    public function getParent()
40
    {
41 44
        return $this->parent;
42
    }
43
44
    /**
45
     * {@inheritdoc}
46
     */
47 32
    public function setParent(UnitInterface $parent)
48
    {
49 32
        $this->parent = $parent;
50 32
    }
51
52
    /**
53
     * {@inheritdoc}
54
     * @var bool $addSiblingBack
55
     */
56 20
    public function addSibling(UnitInterface $sibling, $addBack = true, $addSiblingBack = true)
57
    {
58 20
        if ($addSiblingBack) {
59
            /** @var AbstractUnit $oldSib */
60 20
            foreach ($this->siblings as $oldSib) {
61 2
                $oldSib->addSibling($sibling, true, false);
0 ignored issues
show
Unused Code introduced by
The call to UnitInterface::addSibling() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
62 20
            }
63 20
        }
64 20
        $this->siblings[$sibling->getCode()] = $sibling;
65 20
        if ($addBack) {
66 20
            $sibling->addSibling($this, false, false);
0 ignored issues
show
Unused Code introduced by
The call to UnitInterface::addSibling() has too many arguments starting with false.

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress.

In this case you can add the @ignore PhpDoc annotation to the duplicate definition and it will be ignored.

Loading history...
67 20
        }
68 20
    }
69
70
    /**
71
     * @return UnitInterface[]
72
     */
73 45
    public function getSiblings()
74
    {
75 45
        return $this->siblings;
76
    }
77
}
78