xsAnySimpleType::isOKInternal()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 6
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
namespace AlgoWeb\xsdTypes;
3
4
use AlgoWeb\xsdTypes\Facets\EnumerationTrait;
5
use AlgoWeb\xsdTypes\Facets\PatternTrait;
6
use AlgoWeb\xsdTypes\Facets\WhiteSpaceTrait;
7
8
/**
9
 * The type xsd:anySimpleType is the base type from which all other built-in types are derived.
10
 * Any value (including an empty value) is allowed for xsd:anySimpleType.
11
 * Handles facets enumeration, length, maxLength, minLength, pattern.
12
 *
13
 * @package AlgoWeb\xsdTypes
14
 */
15
abstract class xsAnySimpleType
16
{
17
    use WhiteSpaceTrait, PatternTrait, EnumerationTrait;
18
    /**
19
     * @Exclude
20
     * @var bool indicates if value has been fixed
21
     */
22
    protected $fixed = false;
23
24
    /**
25
     * @property mixed $value
26
     */
27
    protected $value = null;
28
29
    /**
30
     * Construct.
31
     *
32
     * @param mixed $value
33
     */
34
    public function __construct($value)
35
    {
36
        $this->value = $value;
37
    }
38
39
    public function __toString()
40
    {
41
        try {
42
            if (!$this->fixed) {
43
                $this->fixValue();
44
                $this->isOKInternal();
45
            }
46
        } catch (\Exception $e) {
47
            $this->value = '';
48
        }
49
        if (is_array($this->value)) {
50
            return implode(' ', $this->value);
51
        }
52
        return (string)$this->value;
53
    }
54
55
    /**
56
     * makes changes to the value to compensate for rounding conditions or white space handling.
57
     */
58
    protected function fixValue()
59
    {
60
        $this->value = $this->fixWhitespace($this->value);
61
    }
62
63
    protected function isOKInternal()
64
    {
65
        $this->checkEnumeration($this->value);
66
        $this->checkPattern($this->value);
67
        $this->isOK();
68
    }
69
70
    /**
71
     * preforms subclass specific checks to make sure the contained value is OK.
72
     *
73
     * @return null
74
     */
75
    abstract protected function isOK();
76
}
77