Component_switch   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 46
Duplicated Lines 26.09 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 46
rs 10
wmc 5
lcom 0
cbo 1

4 Methods

Rating   Name   Duplication   Size   Complexity  
A required_arguments() 0 4 1
A get_template_path() 0 4 1
A filter() 0 5 2
A default_model() 12 12 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 Amarkal\UI;
4
5
/**
6
 * Implements a Switch UI component.
7
 */
8
class Component_switch
9
extends AbstractComponent
0 ignored issues
show
Coding Style introduced by
The extends keyword must be on the same line as the class name
Loading history...
10
implements ValueComponentInterface, 
0 ignored issues
show
Coding Style introduced by
The implements keyword must be on the same line as the class name
Loading history...
Coding Style introduced by
The first item in a multi-line implements list must be on the line following the implements keyword
Loading history...
11
           DisableableComponentInterface,
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 11 found
Loading history...
12
           FilterableComponentInterface
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 11 found
Loading history...
13
{
14
    public $component_type = 'switch';
15
    
16 View Code Duplication
    public function default_model() 
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...
17
    {
18
        return array(
19
            'name'          => '',
20
            'id'            => '',
21
            'disabled'      => false,
22
            'readonly'      => false,
23
            'default'       => 'off',
24
            'filter'        => array( $this, 'filter' ),
25
            'show'          => null
26
        );
27
    }
28
    
29
    public function required_arguments()
30
    {
31
        return array('name');
32
    }
33
    
34
    public function get_template_path() 
35
    {
36
        return __DIR__.'/template.phtml';
37
    }
38
39
    /**
40
     * This filter is needed when the form is submitted without $.amarkalUIForm, 
41
     * since the value of the checkbox becomes NULL when it is unchecked. When using 
42
     * $.amarkalUIForm to submit the form, the component's getValue/setValue will
43
     * handle this.
44
     *
45
     * @param [string] $v
0 ignored issues
show
Documentation introduced by
The doc-type [string] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
46
     * @return void
47
     */
48
    public function filter($v)
49
    {
50
        if($v !== 'on') return 'off';
51
        return 'on';
52
    }
53
}