Completed
Push — master ( c833c1...b511be )
by Song
03:16
created

CheckboxButton   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 46
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 46
loc 46
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addScript() 21 21 1
A render() 13 13 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
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Admin;
6
7 View Code Duplication
class CheckboxButton extends Checkbox
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...
8
{
9
    /**
10
     * @var string
11
     */
12
    protected $cascadeEvent = 'change';
13
14
    protected function addScript()
15
    {
16
        $script = <<<SCRIPT
17
$('.checkbox-group-toggle label').click(function(e) {
18
    e.stopPropagation();
19
    e.preventDefault();
20
21
    if ($(this).hasClass('active')) {
22
        $(this).removeClass('active');
23
        $(this).find('input').prop('checked', false);
24
    } else {
25
        $(this).addClass('active');
26
        $(this).find('input').prop('checked', true);
27
    }
28
29
    $(this).find('input').trigger('change');
30
});
31
SCRIPT;
32
33
        Admin::script($script);
34
    }
35
36
    /**
37
     * {@inheritdoc}
38
     */
39
    public function render()
40
    {
41
        $this->addScript();
42
43
        $this->addCascadeScript();
44
45
        $this->addVariables([
46
            'options' => $this->options,
47
            'checked' => $this->checked,
48
        ]);
49
50
        return parent::fieldRender();
0 ignored issues
show
Bug Compatibility introduced by
The expression parent::fieldRender(); of type string|Illuminate\View\V...\Contracts\View\Factory adds the type Illuminate\Contracts\View\Factory to the return on line 50 which is incompatible with the return type declared by the interface Illuminate\Contracts\Support\Renderable::render of type string.
Loading history...
Comprehensibility Bug introduced by
It seems like you call parent on a different method (fieldRender() instead of render()). Are you sure this is correct? If so, you might want to change this to $this->fieldRender().

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...
51
    }
52
}
53