Passed
Pull Request — master (#22)
by Christopher
01:59
created

xsDuration::fixValue()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
1
<?php
2
3
namespace AlgoWeb\xsdTypes;
4
5
/**
6
 * The type xsd:duration represents a duration of time expressed as a number of years, months, days, hours, minutes,
7
 * and seconds. The format of xsd:duration is PnYnMnDTnHnMnS, where P is a literal value that starts the expression,
8
 * nY is the number of years followed by a literal Y, nM is the number of months followed by a literal M, nD is the
9
 * number of days followed by a literal D, T is a literal value that separates the date and time, nH is the number of
10
 * hours followed by a literal H, nM is the number of minutes followed by a literal M, and nS is the number of seconds
11
 * followed by a literal S. The following rules apply to xsd:duration values:.
12
 *
13
 * - Any of these numbers and corresponding designators may be absent if they are equal to 0, but at least one number and designator must appear.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 145 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
14
 *  - The numbers may be any unsigned integer, with the exception of the number of seconds, which may be an unsigned decimal number.
0 ignored issues
show
Coding Style introduced by
This line exceeds maximum limit of 120 characters; contains 132 characters

Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.

Loading history...
15
 *  - If a decimal point appears in the number of seconds, there must be at least one digit after the decimal point.
16
 *  - A minus sign may appear before the P to specify a negative duration.
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");
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal collapse does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
33
    }
34
35
    public function fixValue()
36
    {
37
        parent::fixValue();
38
        $v = new \DateInterval($this->value);
1 ignored issue
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 11 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
39
        $this->value = $this->format($v);
40
    }
41
42
    protected function format(\DateInterval $tint, $pattern = "PnYnMnDTnHnMnS")
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal PnYnMnDTnHnMnS does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
43
    {
44
        $sReturn = "";
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
45
        for ($i = 0; $i < strlen($pattern); $i++) {
46
            if ($pattern[$i] == "n") {
0 ignored issues
show
Coding Style Comprehensibility introduced by
The string literal n does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
47
                $sReturn .= $tint->strtolower($pattern[$i + 1]);
48
                continue;
49
            }
50
            $sReturn .= $pattern[$i];
51
        }
52
        return $sReturn;
53
    }
54
55
    protected function isOK()
56
    {
57
        $this->CheckMinMax(new \DateInterval($this->value));
58
    }
59
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
60