Completed
Push — master ( 9b8f8b...ad8621 )
by Mikaël
29:42
created

FloatRule   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A exceptionMessageOnTestFailure() 0 3 1
A name() 0 3 1
A testConditions() 0 3 2
1
<?php
2
3
namespace WsdlToPhp\PackageGenerator\File\Validation;
4
5
class FloatRule extends AbstractRule
6
{
7
8
    /**
9
     * @return string
10
     */
11 66
    public function name()
12
    {
13 66
        return 'float';
14
    }
15
16
    /**
17
     * @param string $parameterName
18
     * @param mixed $value
19
     * @param bool $itemType
20
     * @return string
21
     */
22 66
    public function testConditions($parameterName, $value, $itemType = false)
23
    {
24 66
        return sprintf(($itemType ? '' : '!is_null($%1$s) && ') . '!(is_float($%1$s) || is_numeric($%1$s))', $parameterName, $value);
25
    }
26
27
    /**
28
     * @param string $parameterName
29
     * @param mixed $value
30
     * @param bool $itemType
31
     * @return string
32
     */
33 66
    public function exceptionMessageOnTestFailure($parameterName, $value, $itemType = false)
34
    {
35 66
        return sprintf('sprintf(\'Invalid value %%s, please provide a float value, %%s given\', var_export($%1$s, true), gettype($%1$s))', $parameterName);
36
    }
37
}
38