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

FloatRule::name()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

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