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

xsString   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 30
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 30
loc 30
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A fixValue() 4 4 1
A isOK() 9 9 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:string represents a character string that may contain any Unicode character allowed by XML.  Certain
8
 * characters, namely the "less than" symbol (<) and the ampersand (&), must be escaped (using the entities
9
 * &lt; and &amp;, respectively) when used in strings in XML instances.
10
 *
11
 * The xsd:string type has a whiteSpace facet of preserve, which means that all whitespace characters
12
 * (spaces, tabs, carriage returns, and line feeds) are preserved by the processor.
13
 * This is in contrast to two types derived from it: normalizedString, and token.
14
 *
15
 * Valid values              Comment
16
 * "This is a string!"
17
 * "Édition française."
18
 * "12.5
19
 *                          :an empty string is valid
20
 * "PB&amp;J"               :when parsed, it will become "PB&J"
21
 * "This
22
 * is on two lines."
23
 * Invalid values           Comment
24
 * "AT&T"                        ampersand must be escaped
25
 * "3 < 4"                    the "less than" symbol must be escaped
26
 * But most of that should be handled by JSM
27
 *
28
 * @package AlgoWeb\xsdTypes
29
 */
30 View Code Duplication
class xsString extends xsAnySimpleType
31
{
32
    use LengthTrait;
33
34
    /**
35
     * Construct.
36
     *
37
     * @param string $value
38
     */
39
    public function __construct($value)
40
    {
41
        parent::__construct($value);
42
        $this->setWhiteSpaceFacet('preserve');
43
    }
44
45
    protected function fixValue()
46
    {
47
        parent::fixValue();
48
    }
49
50
    protected function isOK()
51
    {
52
        $this->checkLength($this->value);
53
        if (is_array($this->value) || is_object($this->value)) {
54
            throw new \InvalidArgumentException(
55
                'The provided value for ' . __CLASS__ . ' must not be an array or an object.'
56
            );
57
        }
58
    }
59
}
60