IntegerTransformer   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 24
ccs 12
cts 12
cp 1
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A transform() 0 3 1
A validate() 0 17 3
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