Completed
Push — master ( 3d345a...4bdd65 )
by Askupa
01:39
created

Component_switch::get_template_path()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
rs 10
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
    public function default_model() 
17
    {
18
        return array(
19
            'name'          => '',
20
            'id'            => '',
21
            'disabled'      => false,
22
            'required'      => false,
23
            'readonly'      => false,
24
            'default'       => null,
25
            'filter'        => array( $this, 'filter' )
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
}