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

RadioButton::addScript()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 0
dl 11
loc 11
rs 9.9
c 0
b 0
f 0
1
<?php
2
3
namespace Encore\Admin\Form\Field;
4
5
use Encore\Admin\Admin;
6
7 View Code Duplication
class RadioButton extends Radio
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
    /**
15
     *
16
     */
17
    protected function addScript()
18
    {
19
        $script = <<<SCRIPT
20
$('.radio-group-toggle label').click(function() {
21
    $(this).parent().children().removeClass('active');
22
    $(this).addClass('active');
23
});
24
SCRIPT;
25
26
        Admin::script($script);
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function render()
33
    {
34
        $this->addScript();
35
36
        $this->addCascadeScript();
37
38
        $this->addVariables([
39
            'options' => $this->options,
40
            'checked' => $this->checked,
41
        ]);
42
43
        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 43 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...
44
    }
45
}
46