Passed
Push — master ( b55be9...f6f22e )
by Christopher
01:29
created

integer::isValid()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Barnso
5
 * Date: 28/06/2017
6
 * Time: 5:04 PM
7
 */
8
9
namespace AlgoWeb\xsdTypes;
10
11
/**
12
 * xsd:integer — Signed integers of arbitrary length
13
 * @package AlgoWeb\xsdTypes
14
 */
15
class integer extends decimal
16
{
17
    public function __construct($value)
18
    {
19
        $this->fractionDigits = 0;
0 ignored issues
show
Documentation introduced by
The property $fractionDigits is declared private in AlgoWeb\xsdTypes\SimpleTypeBase. Since you implemented __set(), maybe consider adding a @property or @property-write annotation. This makes it easier for IDEs to provide auto-completion.

Since your code implements the magic setter _set, this function will be called for any write 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.");
        }
    }

}

Since the property has write access only, you can use the @property-write 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...
Documentation Bug introduced by
The property $fractionDigits was declared of type string, but 0 is of type integer. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
20
        parent::__construct($value);
21
    }
22
    protected function isValid($v)
23
    {
24
        return is_intege($v);
25
    }
26
}