Completed
Push — master ( a51be7...c74983 )
by Antony
02:19
created

KnockoutPasswordField   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 10 and the first side effect is on line 2.

The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.

The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.

To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.

Loading history...
2
require_once('Common.php');
3
4
/**
5
 * KnockoutPasswordField
6
 *
7
 * Creates a {@link PasswordField} with an additional data-bind attribute that links to a Knockout obervable
8
 * @uses 'password' as the default observable
9
 */
10
class KnockoutPasswordField extends PasswordField
0 ignored issues
show
Coding Style Compatibility introduced by
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.

You can fix this by adding a namespace to your class:

namespace YourVendor;

class YourClass { }

When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.

Loading history...
11
{
12
    use \Knockout\Common;
13
14
    /**
15
     * bindingType
16
     *
17
     * KnockoutPasswordField needs either 'value' or 'textInput' as a key for the 'data-bind' HTML attribute
18
     *
19
     * @var string data-bind attribute key
20
     * @example  data-bind="input: name, valueUpdate: 'input'" - the binding type is: input.
21
     */
22
    protected $bindingType = "textInput";
23
24
    /**
25
     * casting of variables for security purposes
26
     *
27
     * @see http://docs.silverstripe.org/en/3.1/developer_guides/security/secure_coding/
28
     */
29
    protected $casting = array(
30
        "Observable" => "Varchar",
31
        "BindingType" => "Varchar",
32
        "OtherBindings" => "Varchar",
33
        "HasFocus" => "Boolean"
34
    );
35
36
    /**
37
     * Constructor
38
     *
39
     * @param string $name
40
     * @param null|string $title
41
     * @param string $value
42
     */
43
    public function __construct($name, $title = null, $value = '')
44
    {
45
        parent::__construct($name, $title, $value);
46
        $this->addExtraClass('password');
47
        $this->setTemplate('KnockoutTextField');
48
        $this->observable = 'password';
49
        $this->setAttribute('spellcheck', false);
0 ignored issues
show
Documentation introduced by
false is of type boolean, but the function expects a string.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
50
    }
51
}
52