Passed
Push — develop ( 09b79f...252fb3 )
by Mikaël
01:52
created

AbstractBoundRule::exceptionMessageOnTestFailure()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
cc 2
eloc 1
nc 1
nop 3
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 2
rs 10
c 0
b 0
f 0
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