IntRule   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A name() 0 3 1
A exceptionMessageOnTestFailure() 0 3 1
A testConditions() 0 3 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace WsdlToPhp\PackageGenerator\File\Validation;
6
7
final class IntRule extends AbstractRule
8
{
9 28
    public function name(): string
10
    {
11 28
        return 'int';
12
    }
13
14 34
    public function testConditions(string $parameterName, $value, bool $itemType = false): string
15
    {
16 34
        return sprintf(($itemType ? '' : '!is_null($%1$s) && ').'!(is_int($%1$s) || ctype_digit($%1$s))', $parameterName);
17
    }
18
19 28
    public function exceptionMessageOnTestFailure(string $parameterName, $value, bool $itemType = false): string
20
    {
21 28
        return sprintf('sprintf(\'Invalid value %%s, please provide an integer value, %%s given\', var_export($%1$s, true), gettype($%1$s))', $parameterName);
22
    }
23
}
24