Completed
Push — master ( ead358...de8c68 )
by Askupa
01:58
created

Component_number::validation()   B

Complexity

Conditions 5
Paths 3

Size

Total Lines 16
Code Lines 8

Duplication

Lines 10
Ratio 62.5 %

Importance

Changes 0
Metric Value
cc 5
eloc 8
c 0
b 0
f 0
nc 3
nop 2
dl 10
loc 16
rs 8.8571
1
<?php
2
3
namespace Amarkal\UI;
4
5
/**
6
 * Implements a number UI component.
7
 */
8
class Component_number
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
           ValidatableComponentInterface
0 ignored issues
show
Coding Style introduced by
Expected 4 spaces before interface name; 11 found
Loading history...
14
{
15
    public function default_model() 
16
    {
17
        return array(
18
            'name'          => '',
19
            'id'            => '',
20
            'disabled'      => false,
21
            'size'          => null,
22
            'min'           => null,
23
            'max'           => null,
24
            'step'          => null,
25
            'required'      => false,
26
            'readonly'      => false,
27
            'default'       => null,
28
            'filter'        => array( $this, 'filter' ),
29
            'validation'    => array( $this, 'validation' )
30
        );
31
    }
32
    
33
    public function filter($v)
34
    {
35
        return floatval($v);
36
    }
37
    
38
    public function validation($v,&$e)
39
    {
40 View Code Duplication
        if(null !== $this->max && $v > $this->max) 
0 ignored issues
show
Documentation introduced by
The property max does not exist on object<Amarkal\UI\Component_number>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
41
        {
42
            $e = "must be less than {$this->max}";
0 ignored issues
show
Documentation introduced by
The property max does not exist on object<Amarkal\UI\Component_number>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
43
            return false;
44
        }
45
46 View Code Duplication
        if(null !== $this->min && $v < $this->min) 
0 ignored issues
show
Documentation introduced by
The property min does not exist on object<Amarkal\UI\Component_number>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
Duplication introduced by
This code seems to be duplicated across 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...
47
        {
48
            $e = "must be greater than {$this->min}";
0 ignored issues
show
Documentation introduced by
The property min does not exist on object<Amarkal\UI\Component_number>. Since you implemented __get, maybe consider adding a @property annotation.

Since your code implements the magic getter _get, this function will be called for any read access on an undefined variable. You can add the @property annotation to your class or interface to document the existence of this variable.

<?php

/**
 * @property int $x
 * @property int $y
 * @property string $text
 */
class MyLabel
{
    private $properties;

    private $allowedProperties = array('x', 'y', 'text');

    public function __get($name)
    {
        if (isset($properties[$name]) && in_array($name, $this->allowedProperties)) {
            return $properties[$name];
        } else {
            return null;
        }
    }

    public function __set($name, $value)
    {
        if (in_array($name, $this->allowedProperties)) {
            $properties[$name] = $value;
        } else {
            throw new \LogicException("Property $name is not defined.");
        }
    }

}

If the property has read access only, you can use the @property-read annotation instead.

Of course, you may also just have mistyped another name, in which case you should fix the error.

See also the PhpDoc documentation for @property.

Loading history...
49
            return false;
50
        }
51
52
        return true;
53
    }
54
    
55
    public function required_arguments()
56
    {
57
        return array('name');
58
    }
59
    
60
    public function get_template_path() 
61
    {
62
        return __DIR__.'/template.phtml';
63
    }
64
}