Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
TotalDigitsRule | |
100.00% |
3 / 3 |
|
100.00% |
3 / 3 |
4 | |
100.00% |
1 / 1 |
name | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
testConditions | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
2 | |||
exceptionMessageOnTestFailure | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | declare(strict_types=1); |
4 | |
5 | namespace WsdlToPhp\PackageGenerator\File\Validation; |
6 | |
7 | /** |
8 | * @see https://www.w3.org/TR/xmlschema-2/#rf-totalDigits |
9 | * Validation Rule: totalDigits Valid |
10 | * A value in a ·value space· is facet-valid with respect to ·totalDigits· if: |
11 | * - 1 that value is expressible as i × 10^-n where i and n are integers such that |i| < 10^{value} and 0 <= n <= {value}. |
12 | */ |
13 | final class TotalDigitsRule extends AbstractRule |
14 | { |
15 | public function name(): string |
16 | { |
17 | return 'totalDigits'; |
18 | } |
19 | |
20 | public function testConditions(string $parameterName, $value, bool $itemType = false): string |
21 | { |
22 | return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'mb_strlen(preg_replace(\'/(\D)/\', \'\', (string) $%1$s)) > %2$d', $parameterName, $value); |
23 | } |
24 | |
25 | public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string |
26 | { |
27 | return sprintf('sprintf(\'Invalid value %%s, the value must use at most %1$d digits, "%%d" given\', var_export($%2$s, true), mb_strlen(preg_replace(\'/(\D)/\', \'\', (string) $%2$s)))', $value, $parameterName); |
28 | } |
29 | } |