|
9 | 9 | $overwrite = !empty($argv[1]) && $argv[1] === '--f'; |
10 | 10 | $data = array(); |
11 | 11 |
|
12 | | -foreach ($fixtureFiles AS $file) { |
| 12 | +foreach ($fixtureFiles as $file) { |
13 | 13 |
|
14 | | - if (basename($file, '.yml') != 'unknown' && !in_array(preg_replace('/-[0-9]+$/', '', str_replace('_', ' ', basename($file, '.yml'))),array_keys( \DeviceDetector\Parser\Device\AbstractDeviceParser::getAvailableDeviceTypes() ))) { |
| 14 | + if (basename($file, '.yml') != 'unknown' && !in_array(preg_replace('/-[0-9]+$/', '', str_replace('_', ' ', basename($file, '.yml'))), array_keys(\DeviceDetector\Parser\Device\AbstractDeviceParser::getAvailableDeviceTypes()))) { |
15 | 15 | continue; |
16 | 16 | } |
17 | 17 |
|
18 | 18 | $fileFixtures = Spyc::YAMLLoad(file_get_contents($file)); |
19 | 19 |
|
20 | | - foreach( $fileFixtures AS $fixture) { |
21 | | - |
| 20 | + foreach ($fileFixtures as $fixture) { |
22 | 21 | if (isset($fixture['client']['short_name']) && $fixture['client']['short_name'] === true) { |
23 | 22 | $fixture['client']['short_name'] = 'ON'; |
24 | 23 | } |
|
32 | 31 | } |
33 | 32 |
|
34 | 33 | $data[$fixture['device']['type']][] = $fixture; |
35 | | - |
36 | 34 | } |
37 | 35 | } |
38 | 36 |
|
39 | | -foreach( $data AS $deviceType => $fixtures) { |
40 | | - |
| 37 | +foreach ($data as $deviceType => $fixtures) { |
41 | 38 | $fixtures = array_values(array_map("unserialize", array_unique(array_map("serialize", $fixtures)))); |
42 | 39 |
|
43 | | - usort($fixtures, function($a, $b) { |
44 | | - |
| 40 | + usort($fixtures, function ($a, $b) { |
45 | 41 | if (empty($b)) { |
46 | 42 | return -1; |
47 | 43 | } |
48 | 44 |
|
49 | | - if( @$a['device']['brand'] == @$b['device']['brand'] ) { |
50 | | - |
51 | | - if( strtolower(@$a['device']['model']) == strtolower(@$b['device']['model']) ) { |
52 | | - |
| 45 | + if (@$a['device']['brand'] == @$b['device']['brand']) { |
| 46 | + if (strtolower(@$a['device']['model']) == strtolower(@$b['device']['model'])) { |
53 | 47 | if (@$a['os']['name'] == @$b['os']['name']) { |
54 | | - |
55 | 48 | if (@$a['os']['version'] == @$b['os']['version']) { |
56 | | - |
57 | 49 | if (@$a['client']['name'] == @$b['client']['name']) { |
58 | | - |
59 | 50 | if (@$a['client']['version'] == @$b['client']['version']) { |
60 | 51 | if ($a['user_agent'] == $b['user_agent']) { |
61 | 52 | return 0; |
|
65 | 56 | } |
66 | 57 |
|
67 | 58 | return strtolower(@$a['client']['version']) < strtolower(@$b['client']['version']) ? -1 : 1; |
68 | | - |
69 | 59 | } |
70 | 60 |
|
71 | 61 | return strtolower(@$a['client']['name']) < strtolower(@$b['client']['name']) ? -1 : 1; |
72 | | - |
73 | 62 | } |
74 | 63 |
|
75 | 64 | return strtolower(@$a['os']['version']) < strtolower(@$b['os']['version']) ? -1 : 1; |
76 | 65 | } |
77 | 66 |
|
78 | 67 | return strtolower(@$a['os']['name']) < strtolower(@$b['os']['name']) ? -1 : 1; |
79 | | - |
80 | 68 | } |
81 | 69 |
|
82 | 70 | return strtolower(@$a['device']['model']) < strtolower(@$b['device']['model']) ? -1 : 1; |
83 | | - |
84 | 71 | } |
85 | 72 |
|
86 | 73 | return @$a['device']['brand'] < @$b['device']['brand'] ? -1 : 1; |
87 | 74 | }); |
88 | 75 |
|
89 | 76 | $chunks = array_chunk($fixtures, 500); |
90 | 77 |
|
91 | | - foreach($chunks AS $nr => $chunk) { |
| 78 | + foreach ($chunks as $nr => $chunk) { |
92 | 79 | $content = Spyc::YAMLDump($chunk, false, 0); |
93 | 80 |
|
94 | 81 | $content = str_replace(": ON\n", ": 'ON'\n", $content); |
|
117 | 104 |
|
118 | 105 | $botFixtures = Spyc::YAMLLoad(file_get_contents(__DIR__ . '/../Tests/fixtures/bots.yml')); |
119 | 106 |
|
120 | | -foreach( $botFixtures AS &$fixture) { |
| 107 | +foreach ($botFixtures as &$fixture) { |
121 | 108 | if ($overwrite) { |
122 | 109 | $fixture = \DeviceDetector\DeviceDetector::getInfoFromUserAgent($fixture['user_agent']); |
123 | 110 | } |
124 | 111 | } |
125 | 112 |
|
126 | | -usort($botFixtures, function($a, $b) { |
127 | | - |
| 113 | +usort($botFixtures, function ($a, $b) { |
128 | 114 | if (empty($b)) { |
129 | 115 | return -1; |
130 | 116 | } |
|
143 | 129 | file_put_contents(__DIR__ . '/../Tests/fixtures/bots.yml', Spyc::YAMLDump($botFixtures, false, 0)); |
144 | 130 |
|
145 | 131 | echo "done.\n"; |
146 | | - |
0 commit comments