Passed
Push — master ( db02fd...873e90 )
by Christopher
02:22 queued 48s
created

WhiteSpaceTrait   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fixWhitespace() 0 13 4
A setWhiteSpaceFacet() 0 7 2
1
<?php
2
/**
3
 * Created by PhpStorm.
4
 * User: Barnso
5
 * Date: 30/06/2017
6
 * Time: 9:43 PM
7
 */
8
9
namespace AlgoWeb\xsdTypes\Facets;
10
11
trait WhiteSpaceTrait
12
{
13
    /**
14
     * @Exclude
15
     * @var string Specifies how white space (line feeds, tabs, spaces, and carriage returns) is handled
16
     */
17
    private $whiteSpace = "preserve";
18
19
    protected function fixWhitespace($val)
20
    {
21
        switch ($this->whiteSpace) {
22
            case "preserve":
23
                return $val;
24
            case "replace":
25
                return preg_replace('/\s/', ' ', $val);
26
            case "collapse":
27
                return preg_replace('/\s+/', ' ', $val);
28
            default:
29
                throw new \InvalidArgumentException(__CLASS__ . " Called Fix whitespace with invalid handle operation");
30
        }
31
    }
32
33
    protected function setWhiteSpaceFacet($value)
34
    {
35
        if (!in_array($value, ["preserve", "replace", "collapse"])) {
36
            throw new \InvalidArgumentException("Invalid white space handleing method " . __CLASS__);
37
        }
38
        $this->whiteSpace = $value;
39
    }
40
}
41