Completed
Push — feature/issue-165 ( 83f642...d66719 )
by Mikaël
23:02 queued 18s
created

TotalDigitsRule   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 30
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A exceptionMessageOnTestFailure() 0 3 1
A name() 0 3 1
A testConditions() 0 3 1
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File\Validation;
4
5
class TotalDigitsRule extends AbstractRule
6
{
7
    /**
8
     * @return string
9
     */
10 48
    public function name()
11
    {
12 48
        return 'totalDigits';
13
    }
14
15
    /**
16
     * @param string $parameterName
17
     * @param mixed $value
18
     * @param bool $itemType
19
     * @return string
20
     */
21 48
    public function testConditions($parameterName, $value, $itemType = false)
22
    {
23 48
        return sprintf('is_float($%1$s) && strlen(str_replace(array(\' \', \'.\', \',\', \'-\', \'+\'), \'\', $%1$s)) !== %2$d', $parameterName, $value);
24
    }
25
26
    /**
27
     * @param string $parameterName
28
     * @param mixed $value
29
     * @param bool $itemType
30
     * @return string
31
     */
32 48
    public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
33
    {
34 48
        return sprintf('sprintf(\'Invalid value %%s, the value must at most contain %1$d digits, "%%d" given\', var_export($%2$s, true), strlen(substr($%2$s, strpos($%2$s, \'.\'))))', $value, $parameterName);
35
    }
36
}
37