Completed
Pull Request — master (#1596)
by Thomas
03:22
created

DivisionData   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 13
lcom 0
cbo 0
dl 0
loc 53
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
C validate() 0 42 13
1
<?php
2
/**
3
 * This file is part of the browscap package.
4
 *
5
 * Copyright (c) 1998-2017, Browser Capabilities Project
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
declare(strict_types = 1);
12
namespace Browscap\Data\Validator;
13
14
/**
15
 * Class DivisionData
16
 *
17
 * @category   Browscap
18
 *
19
 * @author     Thomas Müller <[email protected]>
20
 */
21
class DivisionData
22
{
23
    /**
24
     * @param array  $divisionData
25
     * @param string $fileName
26
     *
27
     * @throws \LogicException
28
     *
29
     * @return void
30
     */
31 12
    public static function validate(array $divisionData, string $fileName) : void
32
    {
33 12
        if (!array_key_exists('division', $divisionData)) {
34 1
            throw new \LogicException('required attibute "division" is missing in File ' . $fileName);
35
        }
36
37 11
        if (!is_string($divisionData['division'])) {
38 1
            throw new \LogicException('required attibute "division" has to be a string in File ' . $fileName);
39
        }
40
41 10
        if (!array_key_exists('sortIndex', $divisionData)) {
42 1
            throw new \LogicException('required attibute "sortIndex" is missing in File ' . $fileName);
43
        }
44
45 9
        if (!is_int($divisionData['sortIndex']) || 0 > $divisionData['sortIndex']) {
46 2
            throw new \LogicException('required attibute "sortIndex" has to be a positive integer in File ' . $fileName);
47
        }
48
49 7
        if (!array_key_exists('lite', $divisionData)) {
50 1
            throw new \LogicException('required attibute "lite" is missing in File ' . $fileName);
51
        }
52
53 6
        if (!is_bool($divisionData['lite'])) {
54 1
            throw new \LogicException('required attibute "lite" has to be an boolean in File ' . $fileName);
55
        }
56
57 5
        if (!array_key_exists('standard', $divisionData)) {
58 1
            throw new \LogicException('required attibute "standard" is missing in File ' . $fileName);
59
        }
60
61 4
        if (!is_bool($divisionData['standard'])) {
62 1
            throw new \LogicException('required attibute "standard" has to be an boolean in File ' . $fileName);
63
        }
64
65 3
        if (!isset($divisionData['userAgents'])) {
66 1
            throw new \LogicException('required attibute "userAgents" is missing in File ' . $fileName);
67
        }
68
69 2
        if (!is_array($divisionData['userAgents']) || empty($divisionData['userAgents'])) {
70 1
            throw new \LogicException('required attibute "userAgents" should be an non-empty array in File ' . $fileName);
71
        }
72 1
    }
73
}
74