Completed
Push — master ( 0d8a7c...91d2ee )
by Cheren
07:16
created

FormHelper::switcher()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 25
rs 8.8571
cc 3
eloc 15
nc 4
nop 2
1
<?php
2
/**
3
 * CakeCMS Backend
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   Backend
10
 * @license   MIT
11
 * @copyright MIT License http://www.opensource.org/licenses/mit-license.php
12
 * @link      https://github.com/CakeCMS/Backend".
13
 * @author    Sergey Kalistratov <[email protected]>
14
 */
15
16
namespace Backend\View\Helper;
17
18
use Cake\View\Helper;
19
use Backend\View\Helper\Traits\PrepareHelpers;
20
use Core\View\Helper\FormHelper as CoreFormHelper;
21
22
/**
23
 * Class FormHelper
24
 *
25
 * @package Backend\View\Helper
26
 */
27
class FormHelper extends CoreFormHelper
28
{
29
30
    use PrepareHelpers;
31
32
    /**
33
    * List of helpers used by this helper.
34
    *
35
    * @var array
36
    */
37
    public $helpers = [
38
        'Url'  => ['className' => 'Core.Url'],
39
        'Html' => ['className' => 'Backend.Html'],
40
    ];
41
42
    /**
43
     * Constructor hook method.
44
     *
45
     * @param array $config
46
     */
47
    public function initialize(array $config)
48
    {
49
        $this->_configWrite('prepareBtnClass', function (FormHelper $form, $options, $button) {
50
            return $this->_prepareBtn($form, $options, $button);
51
        });
52
53
        $this->_configWrite('widgets', [
54
            'checkbox' => 'Backend\View\Widget\CheckboxWidget'
55
        ]);
56
57
        $this->_configWrite('templates', 'Backend.templates/form');
58
        
59
        parent::initialize($config);
60
    }
61
62
    /**
63
     * Form switcher.
64
     *
65
     * @param string $fieldName
66
     * @param array $options
67
     * @return string
68
     */
69
    public function switcher($fieldName, array $options = [])
70
    {
71
        $input = parent::checkbox($fieldName, $options);
0 ignored issues
show
Comprehensibility Bug introduced by
It seems like you call parent on a different method (checkbox() instead of switcher()). Are you sure this is correct? If so, you might want to change this to $this->checkbox().

This check looks for a call to a parent method whose name is different than the method from which it is called.

Consider the following code:

class Daddy
{
    protected function getFirstName()
    {
        return "Eidur";
    }

    protected function getSurName()
    {
        return "Gudjohnsen";
    }
}

class Son
{
    public function getFirstName()
    {
        return parent::getSurname();
    }
}

The getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
72
73
        $options += [
74
            'before' => __d('backend', 'Off'),
75
            'after'  => __d('backend', 'On')
76
        ];
77
78
        $title = (isset($options['title'])) ? $options['title'] : $fieldName;
79
80
        if (!empty($title)) {
81
            $title = $this->Html->div('switch-title', $title);
82
        }
83
84
        $content = $this->formatTemplate(__FUNCTION__, [
85
            'input'  => $input,
86
            'lever'  => '<span class="lever"></span>',
87
            'before' => $options['before'],
88
            'after'  => $options['after'],
89
            'title'  => $title,
90
        ]);
91
92
        return $content;
93
    }
94
}
95