Action   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 85
Duplicated Lines 20 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 4
dl 17
loc 85
rs 10
c 0
b 0
f 0

6 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 17 17 4
A getActions() 0 4 1
A setActions() 0 5 1
A addAction() 0 10 3
A getUrlHelper() 0 4 1
A setUrlHelper() 0 5 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
 * @author Deller [email protected]
4
 */
5
6
namespace Nnx\DataGrid\Column;
7
8
use Nnx\DataGrid\Column\Action\ActionInterface;
9
use Zend\View\Helper\Url;
10
11
/**
12
 * Class Action
13
 * @package Nnx\DataGrid\Column
14
 */
15
class Action extends AbstractColumn implements ActionAwareInterface
16
{
17
    /**
18
     * @var array
19
     */
20
    protected $actions = [];
21
22
    /**
23
     * @var Url
24
     */
25
    protected $urlHelper;
26
27
28 View Code Duplication
    public function __construct(array $options = [])
0 ignored issues
show
Duplication introduced by
This method 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...
29
    {
30
        parent::__construct($options);
31
        if (array_key_exists('actions', $options)) {
32
            if (!is_array($options['actions'])) {
33
                throw new Exception\InvalidArgumentException(
34
                    'Действия для колонки действий должны приходить в виде массива'
35
                );
36
            }
37
            $this->setActions($options['actions']);
38
            unset($options['actions']);
39
        }
40
        if (array_key_exists('urlHelper', $options)) {
41
            $this->setUrlHelper($options['urlHelper']);
42
        }
43
        $this->setOptions($options);
44
    }
45
46
    /**
47
     * Возвращает набор действий в колонке
48
     * @return array|ActionInterface[]
49
     */
50
    public function getActions()
51
    {
52
        return $this->actions;
53
    }
54
55
    /**
56
     * Устанавливает набор действий в колонку
57
     * @param array $actions
58
     * @return $this
59
     */
60
    public function setActions($actions)
61
    {
62
        $this->actions = $actions;
63
        return $this;
64
    }
65
66
    /**
67
     * Добавляет действие в колонку
68
     * @param ActionInterface|array $action
69
     * @return $this
70
     */
71
    public function addAction($action)
72
    {
73
        if (!$action instanceof ActionInterface && is_array($action)) {
74
            $actionFactory = new Action\Factory();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
75
            $action['urlHelper'] = $this->getUrlHelper();
76
            $action = $actionFactory->create($action);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 14 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
77
        }
78
        $this->actions[$action->getName()] = $action;
79
        return $this;
80
    }
81
82
    /**
83
     * @return Url
84
     */
85
    public function getUrlHelper()
86
    {
87
        return $this->urlHelper;
88
    }
89
90
    /**
91
     * @param Url $urlHelper
92
     * @return $this
93
     */
94
    public function setUrlHelper($urlHelper)
95
    {
96
        $this->urlHelper = $urlHelper;
97
        return $this;
98
    }
99
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
100