xsHexBinary   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 5 5 1
A isOK() 12 12 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
3
namespace AlgoWeb\xsdTypes;
4
5
use AlgoWeb\xsdTypes\Facets\LengthTrait;
6
7
/**
8
 * The xsd:hexBinary type represents binary data as a sequence of binary octets.  It uses hexadecimal encoding, where
9
 * each binary octet is a two-character hexadecimal number.  Lowercase and uppercase letters A through F are permitted.
10
 * For example, 0FB8 and 0fb8 are two equal xsd:hexBinary representations consisting of two octets.
11
 * @package AlgoWeb\xsdTypes
12
 */
13 View Code Duplication
class xsHexBinary extends xsAnySimpleType
14
{
15
    use LengthTrait;
16
17
    /**
18
     * Construct.
19
     *
20
     * @param string $value
21
     */
22
    public function __construct($value)
23
    {
24
        parent::__construct($value);
25
        $this->setWhiteSpaceFacet('collapse');
26
    }
27
28
    protected function isOK()
29
    {
30
        $this->checkLength($this->value);
31
        $lengthOfValue = strlen($this->value);
32
        if ($lengthOfValue % 2 != 0) {
33
            throw new \InvalidArgumentException('the value ' . $this->value . 'is not valid; characters must appear' .
34
                'in pairs');
35
        }
36
        if (!ctype_xdigit($this->value)) {
37
            throw new \InvalidArgumentException('the value ' . $this->value . 'contains invalid characters');
38
        }
39
    }
40
}
41