Completed
Push — master ( a2bcf9...af9b3a )
by Cheren
02:14
created

ToolbarHelper   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 89
Duplicated Lines 22.47 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 1
dl 20
loc 89
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A setToolbar() 0 4 1
A link() 10 10 1
A add() 10 10 1
A delete() 0 6 2
A save() 0 11 2

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
 * CakeCMS Core
4
 *
5
 * This file is part of the of the simple cms based on CakePHP 3.
6
 * For the full copyright and license information, please view the LICENSE
7
 * file that was distributed with this source code.
8
 *
9
 * @package   Core
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Core".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Core\Toolbar;
17
18
use Core\Utility\Toolbar;
19
20
/**
21
 * Class ToolbarHelper
22
 *
23
 * @package Core\Toolbar
24
 */
25
class ToolbarHelper
26
{
27
28
    const ACTION_SAVE = 'save';
29
    const ACTION_DELETE = 'delete';
30
31
    /**
32
     * Toolbar instance name.
33
     *
34
     * @var string
35
     */
36
    protected static $_toolbar = Toolbar::DEFAULT_NAME;
37
38
    /**
39
     * Setup toolbar instance name.
40
     *
41
     * @param $name
42
     */
43
    public static function setToolbar($name)
44
    {
45
        self::$_toolbar = $name;
46
    }
47
48
    /**
49
     * Create link output.
50
     *
51
     * @param string $title
52
     * @param string $url
53
     * @param array $options
54
     */
55 View Code Duplication
    public static function link($title, $url, 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...
56
    {
57
        $toolbar = Toolbar::getInstance(self::$_toolbar);
58
        $options += [
59
            'icon' => 'link',
60
            'button' => 'grey lighten-3'
61
        ];
62
63
        $toolbar->appendButton('Core.link', $title, $url, $options);
64
    }
65
66
    /**
67
     * Create add link.
68
     *
69
     * @param string|null $title
70
     * @param array|string $url
71
     * @param string $icon
72
     * @param array $options
73
     */
74 View Code Duplication
    public static function add($title = null, $url = ['action' => 'add'], $icon = 'plus', 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...
75
    {
76
        $toolbar = Toolbar::getInstance(self::$_toolbar);
77
        $options += [
78
            'icon' => $icon,
79
            'button' => 'green lighten-2'
80
        ];
81
82
        $toolbar->appendButton('Core.link', $title, $url, $options);
83
    }
84
85
    /**
86
     * Delete for process form.
87
     *
88
     * @param string|null $title
89
     */
90
    public static function delete($title = null)
91
    {
92
        $toolbar = Toolbar::getInstance(self::$_toolbar);
93
        $title   = (empty($title)) ? __d('core', 'Delete') : $title;
94
        $toolbar->appendButton('Core.action', $title, self::ACTION_DELETE, []);
95
    }
96
97
    /**
98
     * Save form button.
99
     *
100
     * @param null $title
101
     */
102
    public static function save($title = null)
103
    {
104
        $toolbar = Toolbar::getInstance(self::$_toolbar);
105
        $title   = (empty($title)) ? __d('core', 'Save') : $title;
106
107
        $toolbar->appendButton('Core.action', $title, self::ACTION_SAVE, [
108
            'button' => 'green lighten-2',
109
            'icon'   => 'check',
110
            'class'  => 'jsFormAdd'
111
        ]);
112
    }
113
}
114