Completed
Pull Request — master (#1596)
by Thomas
02:56
created

CheckProperties::check()   C

Complexity

Conditions 21
Paths 32

Size

Total Lines 76
Code Lines 48

Duplication

Lines 45
Ratio 59.21 %

Code Coverage

Tests 48
CRAP Score 21

Importance

Changes 0
Metric Value
dl 45
loc 76
ccs 48
cts 48
cp 1
rs 5.2051
c 0
b 0
f 0
cc 21
eloc 48
nc 32
nop 2
crap 21

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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\Helper;
13
14
/**
15
 * Class DataCollection
16
 *
17
 * @category   Browscap
18
 *
19
 * @author     James Titcumb <[email protected]>
20
 */
21
class CheckProperties
22
{
23
    /**
24
     * @param string $key
25
     * @param array  $properties
26
     *
27
     * @throws \LogicException
28
     *
29
     * @return void
30
     */
31 19
    public function check($key, array $properties) : void
32
    {
33 19
        if (!array_key_exists('Version', $properties)) {
34 1
            throw new \LogicException('Version property not found for key "' . $key . '"');
35
        }
36
37 18
        if (!array_key_exists('Parent', $properties) && !in_array($key, ['DefaultProperties', '*'])) {
38 1
            throw new \LogicException('Parent property is missing for key "' . $key . '"');
39
        }
40
41 17
        if (!array_key_exists('Device_Type', $properties)) {
42 1
            throw new \LogicException('property "Device_Type" is missing for key "' . $key . '"');
43
        }
44
45 16
        if (!array_key_exists('isTablet', $properties)) {
46 1
            throw new \LogicException('property "isTablet" is missing for key "' . $key . '"');
47
        }
48
49 15
        if (!array_key_exists('isMobileDevice', $properties)) {
50 1
            throw new \LogicException('property "isMobileDevice" is missing for key "' . $key . '"');
51
        }
52
53 14
        switch ($properties['Device_Type']) {
54 14 View Code Duplication
            case 'Tablet':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
55 3
                if (true !== $properties['isTablet']) {
56 1
                    throw new \LogicException(
57 1
                        'the device of type "' . $properties['Device_Type'] . '" is NOT marked as Tablet for key "'
58 1
                        . $key . '"'
59
                    );
60
                }
61 2
                if (true !== $properties['isMobileDevice']) {
62 1
                    throw new \LogicException(
63 1
                        'the device of type "' . $properties['Device_Type']
64 1
                        . '" is NOT marked as Mobile Device for key "' . $key . '"'
65
                    );
66
                }
67
68 1
                break;
69 11
            case 'Mobile Phone':
70 8
            case 'Mobile Device':
71 8
            case 'Ebook Reader':
72 8
            case 'Console':
73 8 View Code Duplication
            case 'Digital Camera':
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
74 3
                if (true === $properties['isTablet']) {
75 1
                    throw new \LogicException(
76 1
                        'the device of type "' . $properties['Device_Type'] . '" is marked as Tablet for key "'
77 1
                        . $key . '"'
78
                    );
79
                }
80 2
                if (true !== $properties['isMobileDevice']) {
81 1
                    throw new \LogicException(
82 1
                        'the device of type "' . $properties['Device_Type']
83 1
                        . '" is NOT marked as Mobile Device for key "' . $key . '"'
84
                    );
85
                }
86
87 1
                break;
88 8
            case 'TV Device':
89 8
            case 'Desktop':
90 View Code Duplication
            default:
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
91 8
                if (true === $properties['isTablet']) {
92 1
                    throw new \LogicException(
93 1
                        'the device of type "' . $properties['Device_Type'] . '" is marked as Tablet for key "'
94 1
                        . $key . '"'
95
                    );
96
                }
97 7
                if (true === $properties['isMobileDevice']) {
98 1
                    throw new \LogicException(
99 1
                        'the device of type "' . $properties['Device_Type'] . '" is marked as Mobile Device for key "'
100 1
                        . $key . '"'
101
                    );
102
                }
103
104 6
                break;
105
        }
106 8
    }
107
}
108