Passed
Push — develop ( a16e5d...09b79f )
by Mikaël
24:38
created

AbstractBoundRule   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 28
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A exceptionMessageOnTestFailure() 0 3 2
A testConditions() 0 8 3
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File\Validation;
4
5
/**
6
 * Class AbstractBoundRule
7
 * Gathers [min|max][In|Ex]clusive rules
8
 * @package WsdlToPhp\PackageGenerator\File\Validation
9
 */
10
abstract class AbstractBoundRule extends AbstractMinMaxRule
11
{
12
13
    /**
14
     * @param string $parameterName
15
     * @param mixed $value
16
     * @param bool $itemType
17
     * @return string
18
     */
19 132
    final public function testConditions($parameterName, $value, $itemType = false)
20
    {
21 132
        if (is_numeric($value)) {
22 60
            $test = '$%1$s %3$s %2$s';
23 30
        } else {
24 72
            $test = '($time = (string) time()) && \DateTime::createFromFormat(\'U\', $time)->add(new \DateInterval(preg_replace(\'/(.*)(\.[0-9]*S)/\', \'$1S\', $%1$s))) %3$s \DateTime::createFromFormat(\'U\', $time)->add(new \DateInterval(preg_replace(\'/(.*)(\.[0-9]*S)/\', \'$1S\', \'%2$s\')))';
25
        }
26 132
        return sprintf(($itemType ? '' : '!is_null($%1$s) && ') . $test, $parameterName, $value, $this->symbol());
27
    }
28
29
    /**
30
     * @param string $parameterName
31
     * @param mixed $value
32
     * @param bool $itemType
33
     * @return string
34
     */
35 132
    final public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
36
    {
37 132
        return sprintf('sprintf(\'Invalid value %%s, the value must be %s %s %s\', var_export($%4$s, true))', is_numeric($value) ? 'numerically' : 'chronologically', $this->comparisonString(), $value, $parameterName);
38
    }
39
}
40