Test Failed
Pull Request — master (#28)
by Christopher
10:21 queued 36s
created

XMLDateInterval::handleChar()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
c 3
b 0
f 0
dl 0
loc 11
rs 9.4285
cc 3
eloc 8
nc 3
nop 2
1
<?php
2
3
namespace AlgoWeb\xsdTypes\AxillaryClasses;
4
5
class XMLDateInterval extends \DateInterval
6
{
7
    /**
8
     * formating string like ISO 8601 (PnYnMnDTnHnMnS).
9
     */
10
    const INTERVAL_ISO8601 = 'P%yY%mM%dDT%hH%iM%sS';
11
    private $pattern;
12
    private $patternLen;
13
14
    public function __construct($intervalSpec, $pattern = 'PnYnMnDTnHnMnS')
15
    {
16
        if ($intervalSpec[0] == '-') {
17
            $intervalSpec = substr($intervalSpec, 1);
0 ignored issues
show
Coding Style introduced by
Consider using a different name than the parameter $intervalSpec. This often makes code more readable.
Loading history...
18
            $this->invert = true;
0 ignored issues
show
Documentation Bug introduced by
The property $invert was declared of type integer, but true is of type boolean. Maybe add a type cast?

This check looks for assignments to scalar types that may be of the wrong type.

To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.

$answer = 42;

$correct = false;

$correct = (bool) $answer;
Loading history...
19
        }
20
        parent::__construct($intervalSpec);
21
        $this->pattern = trim($pattern);
22
23
        $this->patternLen = strlen($this->pattern);
24
    }
25
26
    /**
27
     * formating the interval like ISO 8601 (PnYnMnDTnHnMnS).
28
     *
29
     * @return string
0 ignored issues
show
Documentation introduced by
Should the return type not be string|null?

This check compares the return type specified in the @return annotation of a function or method doc comment with the types returned by the function and raises an issue if they mismatch.

Loading history...
30
     */
31
    public function __toString()
32
    {
33
        $sReturn = $this->handleSign();
34
        $tSeen = false;
35
        for ($i = 0; $i < $this->patternLen; $i++) {
36
            $sReturn .= $this->handleChar($i, $tSeen);
37
        }
38
        return $sReturn;
39
    }
40
41
    private function handleSign()
42
    {
43
        if ($this->invert === 1) {
44
            return '-';
45
        }
46
    }
47
48
    private function handleChar($i, &$tSeen)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
49
    {
50
        switch ($this->pattern[$i]) {
51
            case 'n':
52
                return $this->handleN($i, $tSeen);
53
            case 'T':
54
                return $this->handleT($tSeen);
55
            default:
56
                return $this->HandleOther($i);
57
        }
58
    }
59
60
    private function handleN($i, $tSeen)
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
61
    {
62
        $v = ($this->pattern[$i + 1] == 'M' && $tSeen) ? 'i' : strtolower($this->pattern[$i + 1]);
63
        return $this->$v;
64
    }
65
66
    private function handleT(&$tSeen)
67
    {
68
        $tSeen = true;
69
        return 'T';
70
    }
71
72
    private function HandleOther($i)
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...
73
    {
74
        return $this->pattern[$i];
75
    }
76
}
77