Passed
Push — master ( 43888e...80ce50 )
by Christopher
02:32 queued 30s
created

xsNMTOKENS::fixValue()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 13
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

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