xsDouble   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 38
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 1
cbo 2
dl 38
loc 38
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fixValue() 17 17 3
A __construct() 5 5 1
A isOK() 4 4 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
3
namespace AlgoWeb\xsdTypes;
4
5
use AlgoWeb\xsdTypes\Facets\MinMaxTrait;
6
7
/**
8
 * The type xsd:double represents an IEEE double-precision 64-bit floating-point number.  The format of xsd:double
9
 * values is a mantissa (a number which conforms to the type decimal) followed, optionally, by the character "E"
10
 * or "e" followed by an exponent.  The exponent must be an integer.  For example, 3E2 represents 3 times 10 to the
11
 * 2nd power, or 300.  The exponent must be an integer.
12
 *
13
 * In addition, the following values are valid: INF (infinity), -INF (negative infinity), and NaN (Not a Number).
14
 * INF is considered to be greater than all other values, while -INF is less than all other values.  The value NaN
15
 * cannot be compared to any other values, although it equals itself.
16
 * @package AlgoWeb\xsdTypes
17
 */
18 View Code Duplication
class xsDouble extends xsAnySimpleType
19
{
20
    use MinMaxTrait;
21
22
    /**
23
     * Construct.
24
     *
25
     * @param float $value
26
     */
27
    public function __construct($value)
28
    {
29
        parent::__construct($value);
30
        $this->setWhiteSpaceFacet('collapse');
31
    }
32
33
    protected function fixValue()
34
    {
35
        parent::fixValue();
36
        switch (strtolower($this->value)) {
37
            case 'inf':
38
                $this->value = INF;
39
                return;
40
            case '-inf':
41
                $this->value = -INF;
42
                return;
43
            default:
44
                $this->value = filter_var($this->value, FILTER_VALIDATE_FLOAT, ['options' => [
45
                    'default' => 'NaN', // value to return if the filter fails
46
                    'decimal' => '.'
47
                ]]);
48
        }
49
    }
50
51
    protected function isOK()
52
    {
53
        $this->CheckMinMax($this->value);
54
    }
55
}
56