xsAnySimpleType   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 62
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 3
dl 0
loc 62
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __toString() 0 15 4
A fixValue() 0 4 1
A isOKInternal() 0 6 1
isOK() 0 1 ?
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