xsNMTOKENS   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 50
Duplicated Lines 22 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 10
c 1
b 0
f 0
lcom 1
cbo 3
dl 11
loc 50
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A fixValue() 0 8 2
A FixValueForString() 0 12 4
A isOK() 11 11 3

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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