xsNMTOKENS::FixValueForString()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 12
rs 9.2
cc 4
eloc 7
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
        $this->FixValueForString();
31
        assert(is_array($this->value), 'Somehow, xsNMTOKENs ended up not being an array.');
32
        foreach ($this->value as $v) {
33
            $v->fixValue($v);
34
        }
35
    }
36
37
    private function FixValueForString()
0 ignored issues
show
Coding Style introduced by
This method is not in camel caps format.

This check looks for method names that are not written in camelCase.

In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes databaseConnectionSeeker.

Loading history...
38
    {
39
        if (is_string($this->value)) {
40
            $parts = explode(' ', $this->value);
41
            $this->value = [];
42
            foreach ($parts as $part) {
43
                if (0 != strlen(trim($part))) {
44
                    $this->value[] = new xsNMTOKEN(trim($part));
45
                }
46
            }
47
        }
48
    }
49
50 View Code Duplication
    protected function isOK()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
    {
52
        if (!is_array($this->value)) {
53
            throw new \InvalidArgumentException(
54
                'The provided value for ' . __CLASS__ . ' must be an array of type xsNMTOKEN.'
55
            );
56
        }
57
        foreach ($this->value as $v) {
58
            $v->isOKInternal();
59
        }
60
    }
61
}
62