Passed
Pull Request — master (#31)
by
unknown
03:02
created

Interval   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 61.11%

Importance

Changes 0
Metric Value
wmc 10
lcom 0
cbo 1
dl 0
loc 38
ccs 11
cts 18
cp 0.6111
rs 10
c 0
b 0
f 0

1 Method

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