Numeric   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A castToString() 0 3 1
A isValidInput() 0 3 1
A castFromLine() 0 7 2
1
<?php
2
3
namespace Claudsonm\Pedi\Structure\Types;
4
5
use Claudsonm\Pedi\Exceptions\PediException;
6
use Claudsonm\Pedi\Structure\Field;
7
8
class Numeric implements Type
9
{
10
    /**
11
     * {@inheritdoc}
12
     */
13 66
    public function castFromLine(Field $field, $value)
14
    {
15 66
        if (! $this->isValidInput($value)) {
16 2
            throw PediException::invalidInput($field, $value);
17
        }
18
19 64
        return (int) $value;
20
    }
21
22
    /**
23
     * {@inheritdoc}
24
     */
25 18
    public function castToString(Field $field, $value): string
26
    {
27 18
        return str_pad($value, $field->getSize(), '0', STR_PAD_LEFT);
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33 67
    public function isValidInput($value): bool
34
    {
35 67
        return preg_match('/^[0-9]+$/', $value);
36
    }
37
}
38