Test Failed
Pull Request — master (#28)
by Christopher
02:37
created

xsQName::checkColen()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 0
1
<?php
2
3
namespace AlgoWeb\xsdTypes;
4
5
use AlgoWeb\xsdTypes\Facets\LengthTrait;
6
7
/**
8
 * type xsd:QName represents an XML namespace-qualified name.  A xsd:QName value consists
9
 * of a prefix and a local part, separated by a colon, both of which are NCName values.  The prefix and colon are
10
 * optional, but if they are not present, it is assumed that either the name is namespace-qualified by other means
11
 * (e.g., by a default namespace declaration), or the name is not in a namespace.
12
 * @package AlgoWeb\xsdTypesThe
13
 */
14
class xsQName extends xsAnySimpleType
15
{
16
    use LengthTrait;
17
18
    /**
19
     * Construct.
20
     *
21
     * @param string $value
22
     */
23
    public function __construct($value)
24
    {
25
        parent::__construct($value);
26
        $this->setWhiteSpaceFacet('collapse');
27
    }
28
29
    protected function isOK()
30
    {
31
        $this->checkLength($this->value);
32
        if (':' == $this->value[0]) {
33
            throw new \InvalidArgumentException('QName cannot start with colon');
34
        }
35
36
    }
37
38
    private function checkColen()
0 ignored issues
show
Unused Code introduced by
This method is not used, and could be removed.
Loading history...
39
    {
40
        $bitz = explode(':', $this->value);
41
        if (2 < count($bitz)) {
42
            throw new \InvalidArgumentException('QName cannot contain two or more colons');
43
        }
44
        $this->checkParts($bitz);
45
    }
46
47
    private function checkParts($bitz)
48
    {
49
50
        foreach ($bitz as $bit) {
51
            $ncName = new xsNCName($bit);
52
            $ncNameStr = $ncName->__toString();
53
            if ($ncName != $ncNameStr) {
54
                throw new \InvalidArgumentException($bit . ' is not a valid NCName so can not be part ofa QName');
55
            }
56
        }
57
    }
58
}
59