Completed
Push — master ( 70f96e...85b25a )
by Andrey
02:36
created

InsertCollection   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 69
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 2
dl 69
loc 69
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getInsertedElements() 4 4 1
A getInsertedCollection() 4 4 1
A __construct() 6 6 1
A isCollection() 4 4 1
A getMode() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
9
use Nnx\FormComparator\Comparator\DiffElementBuilder;
10
use Zend\Form\Element\Collection;
11
12
/**
13
 * Class InsertCollection
14
 *
15
 * @package Nnx\FormComparator\Comparator\Diff
16
 */
17 View Code Duplication
class InsertCollection extends AbstractDiffElement implements InsertedElementInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * Добавленная коллекция
21
     *
22
     * @var Collection
23
     */
24
    private $insertedCollection;
25
26
    /**
27
     * Элементы добавленной коллекции
28
     *
29
     * @var InsertElement[]
30
     */
31
    private $insertedElements = [];
32
33
    /**
34
     * Возвращает элементы добавленной коллекции
35
     *
36
     * @return InsertElement[]
37
     */
38
    public function getInsertedElements()
39
    {
40
        return $this->insertedElements;
41
    }
42
    /**
43
     * Возвращает добавленную коллекцию (нет в форме которую сравнивают, но есть в форме с которой сравнивают)
44
     *
45
     * @return Collection
46
     */
47
    public function getInsertedCollection()
48
    {
49
        return $this->insertedCollection;
50
    }
51
52
    /**
53
     * InsertElement constructor.
54
     *
55
     * @param DiffElementBuilder $diffBuilder
56
     */
57
    public function __construct(DiffElementBuilder $diffBuilder)
58
    {
59
        $this->insertedCollection = $diffBuilder->getTargetElement();
60
61
        parent::__construct($diffBuilder);
62
    }
63
64
65
    /**
66
     * Определяет является ли diff для коллекции или для элемента формы
67
     *
68
     * @return bool
69
     */
70
    public function isCollection()
71
    {
72
        return true;
73
    }
74
75
76
    /**
77
     * Определяет какое действие было соверешенно с элементом (элемент был добавлен, изменен, удален)
78
     *
79
     * @return bool
80
     */
81
    public function getMode()
82
    {
83
        return self::INSERT;
84
    }
85
}
86