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

xsNCName::isOK()   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
namespace AlgoWeb\xsdTypes;
3
4
/**
5
 * The type xsd:NCName represents an XML non-colonized name, which is simply a name that does not contain colons.
6
 * An xsd:NCName value must start with either a letter or underscore (_) and may contain only letters, digits,
7
 * underscores (_), hyphens (-), and periods (.).  This is equivalent to the Name type, except that colons are not
8
 * permitted.
9
 *
10
 * @package AlgoWeb\xsdTypes
11
 */
12
class xsNCName extends xsName
13
{
14
    /**
15
     * Construct.
16
     *
17
     * @param string $value
18
     */
19
    public function __construct($value)
20
    {
21
        parent::__construct($value);
22
        $this->setPatternFacet('(\i-[:]\c-[:])[^:-:]*');
23
    }
24
25
    protected function isOK()
26
    {
27
        parent::isOK();
28
        if (in_array($this->value[0], ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '.', '-'])) {
29
            throw new \InvalidArgumentException('NCName cannot begin with a number, dot or minus character although' .
30
                ' they can appear later in an NCName.');
31
        }
32
    }
33
}
34