Interval   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 94.44%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 21
c 1
b 0
f 0
dl 0
loc 37
ccs 17
cts 18
cp 0.9444
rs 10
wmc 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 25 10
1
<?php
2
3
namespace CommerceGuys\AuthNet\DataTypes;
4
5
class Interval extends BaseDataType
6
{
7
    protected $propertyMap = [
8
        'length',
9
        'unit',
10
    ];
11
12
    /**
13
     * Allows child classes to validate incoming values.
14
     *
15
     * @param array $values
16
     */
17 6
    protected function validate(array $values)
18
    {
19 6
        if (!isset($values['length'])) {
20 1
            throw new \InvalidArgumentException('Interval must have a length.');
21
        }
22 5
        if (!isset($values['unit'])) {
23 1
            throw new \InvalidArgumentException('Interval must have a unit.');
24
        }
25 4
        if (!array_intersect(['days', 'months'], (array) $values['unit'])) {
26 1
            throw new \InvalidArgumentException('Interval unit must be days or months.');
27
        }
28 3
        switch ($values['unit']) {
29 3
            case 'days':
30 1
                if ($values['length'] < 7 || $values['length'] > 365) {
31 1
                    $message = 'Interval length for days must be between 7 and 365, inclusive.';
32 1
                    throw new \InvalidArgumentException($message);
33
                }
34
                break;
35
36 2
            case 'months':
37 2
                if ($values['length'] < 1 || $values['length'] > 12) {
38 1
                    $message = 'Interval length for months must be between 1 and 12, inclusive.';
39 1
                    throw new \InvalidArgumentException($message);
40
                }
41 1
                break;
42 1
        }
43 1
    }
44
}
45