Code Duplication    Length = 61-62 lines in 3 locations

src/xsDayTimeDuration.php 1 location

@@ 14-74 (lines=61) @@
11
 *  - If no time items (hour, minute, second) are present, the letter T must not appear.
12
 * @package AlgoWeb\xsdTypes
13
 */
14
class xsDayTimeDuration extends xsDurationextends
15
{
16
    /**
17
     * Construct
18
     *
19
     * @param string $value
20
     */
21
    public function __construct($value)
22
    {
23
        parent::__construct($value);
24
        $this->setWhiteSpaceFacet("collapse");
25
    }
26
27
    public function fixValue()
28
    {
29
        parent::fixValue();
30
        $v = new \DateInterval($this->value);
31
        $this->value = $this->format($v);
32
    }
33
34
//TODO: TechDebt.this needs to be more specific fo the type.
35
    protected function format(\DateInterval $tint)
36
    {
37
        $sReturn = 'P';
38
39
        if ($this->y) {
40
            $sReturn .= $tint->y . 'Y';
41
        }
42
43
        if ($this->m) {
44
            $sReturn .= $tint->m . 'M';
45
        }
46
47
        if ($this->d) {
48
            $sReturn .= $tint->d . 'D';
49
        }
50
51
        if ($tint->h || $tint->i || $tint->s) {
52
            $sReturn .= 'T';
53
54
            if ($this->h) {
55
                $sReturn .= $tint->h . 'H';
56
            }
57
58
            if ($this->i) {
59
                $sReturn .= $tint->i . 'M';
60
            }
61
62
            if ($this->s) {
63
                $sReturn .= $tint->s . 'S';
64
            }
65
        }
66
67
        return $sReturn;
68
    }
69
70
    protected function isOK()
71
    {
72
        $this->CheckMinMax(new \DateInterval($this->value));
73
    }
74
}
75

src/xsDuration.php 1 location

@@ 20-81 (lines=62) @@
17
 *  - If no time items (hour, minute, second) are present, the letter T must not appear.
18
 * @package AlgoWeb\xsdTypes
19
 */
20
class xsDuration extends xsAnySimpleType
21
{
22
    use MinMaxTrait;
23
24
    /**
25
     * Construct
26
     *
27
     * @param string $value
28
     */
29
    public function __construct($value)
30
    {
31
        parent::__construct($value);
32
        $this->setWhiteSpaceFacet("collapse");
33
    }
34
35
    public function fixValue()
36
    {
37
        parent::fixValue();
38
        $v = new \DateInterval($this->value);
39
        $this->value = $this->format($v);
40
    }
41
42
    protected function format(\DateInterval $tint)
43
    {
44
        $sReturn = 'P';
45
46
        if ($this->y) {
47
            $sReturn .= $tint->y . 'Y';
48
        }
49
50
        if ($this->m) {
51
            $sReturn .= $tint->m . 'M';
52
        }
53
54
        if ($this->d) {
55
            $sReturn .= $tint->d . 'D';
56
        }
57
58
        if ($tint->h || $tint->i || $tint->s) {
59
            $sReturn .= 'T';
60
61
            if ($this->h) {
62
                $sReturn .= $tint->h . 'H';
63
            }
64
65
            if ($this->i) {
66
                $sReturn .= $tint->i . 'M';
67
            }
68
69
            if ($this->s) {
70
                $sReturn .= $tint->s . 'S';
71
            }
72
        }
73
74
        return $sReturn;
75
    }
76
77
    protected function isOK()
78
    {
79
        $this->CheckMinMax(new \DateInterval($this->value));
80
    }
81
}
82

src/xsYearMonthDuration.php 1 location

@@ 19-79 (lines=61) @@
16
 * Schema 1.0 specification and is therefore not supported for use in XML Schema 1.0 schemas.
17
 * @package AlgoWeb\xsdTypes
18
 */
19
class xsYearMonthDuration extends xsDurationextends
20
{
21
    /**
22
     * Construct
23
     *
24
     * @param string $value
25
     */
26
    public function __construct($value)
27
    {
28
        parent::__construct($value);
29
        $this->setWhiteSpaceFacet("collapse");
30
    }
31
32
    public function fixValue()
33
    {
34
        parent::fixValue();
35
        $v = new \DateInterval($this->value);
36
        $this->value = $this->format($v);
37
    }
38
39
//TODO: TechDebt.this needs to be more specific fo the type.
40
    protected function format(\DateInterval $tint)
41
    {
42
        $sReturn = 'P';
43
44
        if ($this->y) {
45
            $sReturn .= $tint->y . 'Y';
46
        }
47
48
        if ($this->m) {
49
            $sReturn .= $tint->m . 'M';
50
        }
51
52
        if ($this->d) {
53
            $sReturn .= $tint->d . 'D';
54
        }
55
56
        if ($tint->h || $tint->i || $tint->s) {
57
            $sReturn .= 'T';
58
59
            if ($this->h) {
60
                $sReturn .= $tint->h . 'H';
61
            }
62
63
            if ($this->i) {
64
                $sReturn .= $tint->i . 'M';
65
            }
66
67
            if ($this->s) {
68
                $sReturn .= $tint->s . 'S';
69
            }
70
        }
71
72
        return $sReturn;
73
    }
74
75
    protected function isOK()
76
    {
77
        $this->CheckMinMax(new \DateInterval($this->value));
78
    }
79
}
80