Passed
Pull Request — master (#28)
by Christopher
02:48
created

xsNCName   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A isOK() 0 8 2
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