Code Duplication    Length = 37-38 lines in 2 locations

src/xsDouble.php 1 location

@@ 18-55 (lines=38) @@
15
 * cannot be compared to any other values, although it equals itself.
16
 * @package AlgoWeb\xsdTypes
17
 */
18
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

src/xsFloat.php 1 location

@@ 18-54 (lines=37) @@
15
 * The value NaN cannot be compared to any other values, although it equals itself.
16
 * @package AlgoWeb\xsdTypes
17
 */
18
class xsFloat 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
    protected function isOK()
51
    {
52
        $this->CheckMinMax($this->value);
53
    }
54
}
55