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': |
|
|
|
|
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': |
|
|
|
|
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: |
|
|
|
|
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
|
|
|
|
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.