IntRule::testConditions()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

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