Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
| AbstractBoundRule | |
100.00% |
18 / 18 |
|
100.00% |
2 / 2 |
10 | |
100.00% |
1 / 1 |
| testConditions | |
100.00% |
17 / 17 |
|
100.00% |
1 / 1 |
7 | |||
| exceptionMessageOnTestFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace WsdlToPhp\PackageGenerator\File\Validation; |
| 6 | |
| 7 | /** |
| 8 | * Gathers [min|max][In|Ex]clusive rules. |
| 9 | */ |
| 10 | abstract class AbstractBoundRule extends AbstractMinMaxRule |
| 11 | { |
| 12 | final public function testConditions(string $parameterName, $value, bool $itemType = false): string |
| 13 | { |
| 14 | $method = ''; |
| 15 | $checkValueDomain = ''; |
| 16 | if (is_numeric($value)) { |
| 17 | $test = '$%1$s %3$s %2$s'; |
| 18 | } else { |
| 19 | if (false === mb_strpos($value, '-')) { |
| 20 | $method = 'add'; |
| 21 | } else { |
| 22 | $method = 'sub'; |
| 23 | $value = mb_substr($value, 1); |
| 24 | } |
| 25 | |
| 26 | switch ($this->symbol()) { |
| 27 | case self::SYMBOL_MAX_EXCLUSIVE: |
| 28 | case self::SYMBOL_MAX_INCLUSIVE: |
| 29 | $checkValueDomain = '==='; |
| 30 | |
| 31 | break; |
| 32 | |
| 33 | default: |
| 34 | $checkValueDomain = '!=='; |
| 35 | |
| 36 | break; |
| 37 | } |
| 38 | $test = 'false %5$s mb_strpos((string) $%1$s, \'-\') && ($time = (string) time()) && \DateTime::createFromFormat(\'U\', $time)->%4$s(new \DateInterval(preg_replace(\'/(.*)(\.[0-9]*S)/\', \'$1S\', str_replace(\'-\', \'\', $%1$s)))) %3$s \DateTime::createFromFormat(\'U\', $time)->%4$s(new \DateInterval(preg_replace(\'/(.*)(\.[0-9]*S)/\', \'$1S\', \'%2$s\')))'; |
| 39 | } |
| 40 | |
| 41 | return sprintf(($itemType ? '' : '!is_null($%1$s) && ').$test, $parameterName, $value, $this->symbol(), $method, $checkValueDomain); |
| 42 | } |
| 43 | |
| 44 | final public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string |
| 45 | { |
| 46 | 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(), is_array($value) ? implode(',', array_unique($value)) : $value, $parameterName); |
| 47 | } |
| 48 | } |