IntegerTransformer::validate()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 9
nc 3
nop 3
dl 0
loc 17
ccs 10
cts 10
cp 1
crap 3
rs 9.9666
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Darkilliant\ImportBundle\Transformer;
6
7
use Darkilliant\ImportBundle\Exception\TransformationException;
8
9
class IntegerTransformer extends AbstractTransformer
10
{
11 1
    public function transform($value, string $name = '', array $options = [])
12
    {
13 1
        return intval($value);
14
    }
15
16 2
    public function validate($value, string $name = '', array $options = []): bool
17
    {
18 2
        if (is_int($value)) {
19 1
            return true;
20
        }
21
22 2
        if (false === ctype_digit($value)) {
23 1
            throw new TransformationException(
24 1
                sprintf(
25 1
                    'invalid %s is not an integer (actual: %s)',
26 1
                    $name,
27 1
                    $value
28
                )
29
            );
30
        }
31
32 1
        return true;
33
    }
34
}
35