Completed
Push — master ( 885df8...d7de07 )
by Cheren
02:38
created

FormHelper::switcher()   B

Complexity

Conditions 3
Paths 4

Size

Total Lines 25
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
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 Core\View\Helper\FormHelper as CoreFormHelper;
19
20
/**
21
 * Class FormHelper
22
 *
23
 * @package Backend\View\Helper
24
 */
25
class FormHelper extends CoreFormHelper
26
{
27
28
    /**
29
    * List of helpers used by this helper.
30
    *
31
    * @var array
32
    */
33
    public $helpers = [
34
        'Url'  => ['className' => 'Core.Url'],
35
        'Html' => ['className' => 'Backend.Html'],
36
    ];
37
38
    /**
39
     * Form switcher.
40
     *
41
     * @param string $fieldName
42
     * @param array $options
43
     * @return string
44
     */
45
    public function switcher($fieldName, array $options = [])
46
    {
47
        $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...
48
49
        $options += [
50
            'before' => __d('backend', 'Off'),
51
            'after'  => __d('backend', 'On')
52
        ];
53
54
        $title = (isset($options['title'])) ? $options['title'] : $fieldName;
55
56
        if (!empty($title)) {
57
            $title = $this->Html->div('switch-title', $title);
58
        }
59
60
        $content = $this->formatTemplate(__FUNCTION__, [
61
            'input'  => $input,
62
            'lever'  => '<span class="lever"></span>',
63
            'before' => $options['before'],
64
            'after'  => $options['after'],
65
            'title'  => $title,
66
        ]);
67
68
        return $content;
69
    }
70
}
71