UpdateCollection::getDiff()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @link    https://github.com/nnx-framework/form-comparator
4
 * @author  Malofeykin Andrey  <[email protected]>
5
 */
6
namespace Nnx\FormComparator\Comparator\Diff;
7
8
use Nnx\FormComparator\Comparator\DiffElementBuilder;
9
use Zend\Form\Element\Collection;
10
11
/**
12
 * Class UpdateCollection
13
 *
14
 * @package Nnx\FormComparator\Comparator\Diff
15
 */
16
class UpdateCollection extends AbstractDiffElement implements UpdatedElementInterface
17
{
18
    /**
19
     * Коллекция которую сравнивают
20
     *
21
     * @var Collection
22
     */
23
    private $sourceCollection;
24
25
    /**
26
     * Коллекция с которой сравнивают
27
     *
28
     * @var Collection
29
     */
30
    private $targetCollection;
31
32
    /**
33
     * Расхождение между элементами коллекций
34
     *
35
     * @var AbstractCollectionElement[]
36
     */
37
    private $diff = [];
38
39
    /**
40
     * UpdateCollection constructor.
41
     *
42
     * @param DiffElementBuilder $diffBuilder
43
     */
44
    public function __construct(DiffElementBuilder $diffBuilder)
45
    {
46
        $this->sourceCollection = $diffBuilder->getSourceElement();
47
        $this->targetCollection = $diffBuilder->getTargetElement();
48
        $this->diff = $diffBuilder->getCollectionElementsDiff();
49
50
        parent::__construct($diffBuilder);
51
    }
52
53
    /**
54
     * Коллекция которую сравнивают
55
     *
56
     * @return Collection
57
     */
58
    public function getSourceCollection()
59
    {
60
        return $this->sourceCollection;
61
    }
62
63
    /**
64
     * Коллекция с которой сравнивают
65
     *
66
     * @return Collection
67
     */
68
    public function getTargetCollection()
69
    {
70
        return $this->targetCollection;
71
    }
72
73
    /**
74
     * Расхождение между элементами коллекций
75
     *
76
     * @return AbstractCollectionElement[]
77
     */
78
    public function getDiff()
79
    {
80
        return $this->diff;
81
    }
82
83
84
    /**
85
     * Определяет является ли diff для коллекции или для элемента формы
86
     *
87
     * @return bool
88
     */
89
    public function isCollection()
90
    {
91
        return true;
92
    }
93
94
95
    /**
96
     * Определяет какое действие было соверешенно с элементом (элемент был добавлен, изменен, удален)
97
     *
98
     * @return bool
99
     */
100
    public function getMode()
101
    {
102
        return self::UPDATE;
103
    }
104
}
105