Passed
Push — master ( dfaf98...d5c55b )
by Christopher
02:17
created

decimal::isValid()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 6
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 6
loc 6
rs 9.4285
c 1
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Doc
5
 * Date: 6/1/2017
6
 * Time: 1:53 AM
7
 */
8
9
namespace AlgoWeb\xsdTypes;
10
11
/**
12
 * xsd:decimal is the datatype that represents the set of all decimal numbers with arbitrary lengths.
13
 * Its lexical space allows any number of insignificant leading and trailing zeros (after the decimal point).
14
 * @package AlgoWeb\xsdTypes
15
 */
16 View Code Duplication
class decimal extends SimpleTypeBase
1 ignored issue
show
Duplication introduced by
This class 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
    public function __construct($value)
19
    {
20
        $this->whiteSpace = "replace";
0 ignored issues
show
Documentation introduced by
The property $whiteSpace 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...
21
        parent::__construct($value);
22
    }
23
24
    protected function isValid($v)
25
    {
26
        if (!is_numeric($v)) {
27
            throw new \InvalidArgumentException("failed to provide numeric value " . __CLASS__);
28
        }
29
    }
30
}
31