Completed
Pull Request — master (#28)
by Christopher
03:55 queued 45s
created

xsNMTOKENS::fixValue()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 10
nc 4
nop 0
1
<?php
2
namespace AlgoWeb\xsdTypes;
3
4
use AlgoWeb\xsdTypes\Facets\LengthTrait;
5
6
/**
7
 * The type xsd:NMTOKENS represents a list of NMTOKEN values separated by whitespace.  There must be at least one
8
 * NMTOKEN in the list.
9
 *
10
 * @package AlgoWeb\xsdTypes
11
 */
12
class xsNMTOKENS extends xsAnySimpleType
13
{
14
    use LengthTrait;
15
16
    /**
17
     * Construct.
18
     *
19
     * @param array $value
20
     */
21
    public function __construct($value)
22
    {
23
        parent::__construct($value);
24
        $this->setWhiteSpaceFacet('collapse');
25
        $this->setMinLengthFacet(1);
26
    }
27
28
    protected function fixValue()
29
    {
30
        if (is_string($this->value)) {
31
            $parts = explode(' ', $this->value);
32
            $this->value = [];
33
            foreach ($parts as $part) {
34
                if (0 != strlen(trim($part))) {
35
                    $this->value[] = new xsNMTOKEN(trim($part));
36
                }
37
            }
38
        }
39
        assert(is_array($this->value), 'Somehow, xsNMTOKENs ended up not being an array.');
40
        foreach ($this->value as $v) {
41
            $v->fixValue($v);
42
        }
43
    }
44
45 View Code Duplication
    protected function isOK()
46
    {
47
        if (!is_array($this->value)) {
48
            throw new \InvalidArgumentException(
49
                'The provided value for ' . __CLASS__ . ' must be an array of type xsNMTOKEN.'
50
            );
51
        }
52
        foreach ($this->value as $v) {
53
            $v->isOKInternal();
54
        }
55
    }
56
}
57