• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

WhichBrowser / Parser-PHP / 8722164593

17 Apr 2024 12:47PM UTC coverage: 99.955% (-0.03%) from 99.985%
8722164593

push

github

NielsLeenheer
Add new Darwin versions for translating to macOS and iOS

6730 of 6733 relevant lines covered (99.96%)

1.12 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

99.23
/src/Analyser/Derive.php
1
<?php
2

3
namespace WhichBrowser\Analyser;
4

5
use WhichBrowser\Constants;
6
use WhichBrowser\Model\Family;
7
use WhichBrowser\Model\Using;
8
use WhichBrowser\Model\Version;
9

10
trait Derive
11
{
12
    private function &deriveInformation()
13
    {
14
        if (isset($this->data->device->flag)) {
1✔
15
            $this->deriveBasedOnDeviceFlag();
1✔
16
        }
17

18
        if (isset($this->data->os->name)) {
1✔
19
            $this->deriveBasedOnOperatingSystem();
1✔
20
        }
21

22
        if (isset($this->data->browser->name)) {
1✔
23
            $this->deriveOperaDevices();
1✔
24
        }
25

26
        if (isset($this->data->browser->name)) {
1✔
27
            $this->deriveFirefoxOS();
1✔
28
        }
29

30
        if (isset($this->data->browser->name)) {
1✔
31
            $this->deriveTrident();
1✔
32
            $this->deriveOperaRenderingEngine();
1✔
33
            $this->deriveOmniWebRenderingEngine();
1✔
34
            $this->deriveNetFrontRenderingEngine();
1✔
35
        }
36

37
        return $this;
1✔
38
    }
39

40

41

42

43
    private function &deriveDeviceSubType()
44
    {
45
        if ($this->data->device->type == 'mobile' && empty($this->data->device->subtype)) {
1✔
46
            $this->data->device->subtype = 'feature';
1✔
47

48
            if (in_array($this->data->os->getName(), [ 'Android', 'Bada', 'BlackBerry', 'BlackBerry OS', 'Firefox OS', 'iOS', 'iPhone OS', 'Kin OS', 'Maemo', 'MeeGo', 'Palm OS', 'Sailfish', 'Series60', 'Series80', 'Tizen', 'Ubuntu Touch', 'Windows Mobile', 'Windows Phone', 'webOS' ])) {
1✔
49
                $this->data->device->subtype = 'smart';
1✔
50
            }
51

52
            if (isset($this->data->os->name) && in_array($this->data->os->name, [ 'Windows Phone' ])) {
1✔
53
                $this->data->device->subtype = 'smart';
1✔
54
            }
55

56
            if (isset($this->data->os->family) && in_array($this->data->os->family->getName(), [ 'Android' ])) {
1✔
57
                $this->data->device->subtype = 'smart';
1✔
58
            }
59
        }
60

61
        return $this;
1✔
62
    }
63

64

65
    private function deriveOmniWebRenderingEngine()
66
    {
67
        if ($this->data->isBrowser('OmniWeb')) {
1✔
68
            $version = $this->data->browser->getVersion();
1✔
69

70
            if ($version < 5) {
1✔
71
                $this->data->engine->reset();
1✔
72
            }
73

74
            if ($version >= 5 && $version < 5.5 && !$this->data->isEngine('WebCore')) {
1✔
75
                $this->data->engine->reset([ 'name' => 'WebCore' ]);
1✔
76
            }
77

78
            if ($version >= 5.5 && !$this->data->isEngine('WebKit')) {
1✔
79
                $this->data->engine->reset([ 'name' => 'WebKit' ]);
1✔
80
            }
81
        }
82
    }
1✔
83

84

85
    private function deriveOperaRenderingEngine()
86
    {
87
        if ($this->data->isBrowser('Opera') || $this->data->isBrowser('Opera Mobile')) {
1✔
88
            $version = $this->data->browser->getVersion();
1✔
89

90
            if ($version >= 3.5 && $version < 7 && !$this->data->isEngine('Electra')) {
1✔
91
                $this->data->engine->reset([ 'name' => 'Electra' ]);
1✔
92
            }
93

94
            if ($version >= 7 && $version < 13 && !$this->data->isEngine('Presto')) {
1✔
95
                $this->data->engine->reset([ 'name' => 'Presto' ]);
1✔
96
            }
97
        }
98

99
        if ($this->data->isBrowser('Opera Mini') && !$this->data->isOs('iOS') && !$this->data->isEngine('Presto')) {
1✔
100
            $this->data->engine->reset([ 'name' => 'Presto' ]);
1✔
101
        }
102
    }
1✔
103

104

105
    private function deriveNetFrontRenderingEngine()
106
    {
107
        if ($this->data->isBrowser('NetFront') && !$this->data->isEngine('NetFront')) {
1✔
108
            $this->data->engine->reset([ 'name' => 'NetFront' ]);
1✔
109
        }
110
    }
1✔
111

112
    private function deriveTrident()
113
    {
114
        if ($this->data->isType('desktop') && $this->data->isBrowser('Internet Explorer') && !$this->data->engine->getName()) {
1✔
115
            if ($this->data->isBrowser('Internet Explorer', '>=', 4)) {
1✔
116
                $this->data->engine->set([ 'name' => 'Trident' ]);
1✔
117
            }
118
        }
119

120
        if ($this->data->isMobile() && $this->data->isBrowser('Mobile Internet Explorer') && !$this->data->engine->getName()) {
1✔
121
            if ($this->data->isBrowser('Mobile Internet Explorer', '=', 6)) {
1✔
122
                $this->data->engine->set([ 'name' => 'Trident' ]);
1✔
123
            }
124

125
            if ($this->data->isBrowser('Mobile Internet Explorer', '=', 7)) {
1✔
126
                $this->data->engine->set([ 'name' => 'Trident', 'version' => new Version([ 'value' => '3.1' ]) ]);
1✔
127
            }
128
        }
129
    }
1✔
130

131

132
    private function deriveFirefoxOS()
133
    {
134
        if (in_array($this->data->browser->name, [ 'Firefox Mobile', 'Servo Nightly Build' ]) && !isset($this->data->os->name)) {
1✔
135
            $this->data->os->name = 'Firefox OS';
1✔
136
        }
137

138
        if (isset($this->data->os->name) && $this->data->os->name == 'Firefox OS' && $this->data->engine->name == 'Gecko') {
1✔
139
            switch ($this->data->engine->getVersion()) {
1✔
140
                case '18.0':
1✔
141
                    $this->data->os->version = new Version([ 'value' => '1.0.1' ]);
1✔
142
                    break;
1✔
143
                case '18.1':
1✔
144
                    $this->data->os->version = new Version([ 'value' => '1.1' ]);
1✔
145
                    break;
1✔
146
                case '26.0':
1✔
147
                    $this->data->os->version = new Version([ 'value' => '1.2' ]);
1✔
148
                    break;
1✔
149
                case '28.0':
1✔
150
                    $this->data->os->version = new Version([ 'value' => '1.3' ]);
1✔
151
                    break;
1✔
152
                case '30.0':
1✔
153
                    $this->data->os->version = new Version([ 'value' => '1.4' ]);
1✔
154
                    break;
1✔
155
                case '32.0':
1✔
156
                    $this->data->os->version = new Version([ 'value' => '2.0' ]);
1✔
157
                    break;
1✔
158
                case '34.0':
1✔
159
                    $this->data->os->version = new Version([ 'value' => '2.1' ]);
1✔
160
                    break;
1✔
161
                case '37.0':
1✔
162
                    $this->data->os->version = new Version([ 'value' => '2.2' ]);
1✔
163
                    break;
1✔
164
                case '44.0':
1✔
165
                    $this->data->os->version = new Version([ 'value' => '2.5' ]);
1✔
166
                    break;
1✔
167
            }
168
        }
169
    }
1✔
170

171

172
    private function deriveOperaDevices()
173
    {
174
        if ($this->data->browser->name == 'Opera' && $this->data->device->type == Constants\DeviceType::TELEVISION) {
1✔
175
            $this->data->browser->name = 'Opera Devices';
1✔
176
            $this->data->browser->version = null;
1✔
177

178
            if ($this->data->engine->getName() == 'Presto') {
1✔
179
                $data = [
180
                    '2.12'  => '3.4',
1✔
181
                    '2.11'  => '3.3',
182
                    '2.10'  => '3.2',
183
                    '2.9'   => '3.1',
184
                    '2.8'   => '3.0',
185
                    '2.7'   => '2.9',
186
                    '2.6'   => '2.8',
187
                    '2.4'   => '10.3',
188
                    '2.3'   => '10',
189
                    '2.2'   => '9.7',
190
                    '2.1'   => '9.6'
191
                ];
192

193
                $key = implode('.', array_slice(explode('.', $this->data->engine->getVersion()), 0, 2));
1✔
194

195
                if (isset($data[$key])) {
1✔
196
                    $this->data->browser->version = new Version([ 'value' => $data[$key] ]);
1✔
197
                } else {
198
                    unset($this->data->browser->version);
1✔
199
                }
200
            }
201

202
            $this->data->os->reset();
1✔
203
        }
204
    }
1✔
205

206

207

208
    private function deriveBasedOnDeviceFlag()
209
    {
210
        $flag = $this->data->device->flag;
1✔
211

212
        if ($flag == Constants\Flag::NOKIAX) {
1✔
213
            $this->data->os->name = 'Nokia X Platform';
1✔
214
            $this->data->os->family = new Family([ 'name' => 'Android' ]);
1✔
215

216
            unset($this->data->os->version);
1✔
217
            unset($this->data->device->flag);
1✔
218
        }
219

220
        if ($flag == Constants\Flag::FIREOS) {
1✔
221
            $this->data->os->name = 'FireOS';
1✔
222
            $this->data->os->family = new Family([ 'name' => 'Android' ]);
1✔
223

224
            if (isset($this->data->os->version) && isset($this->data->os->version->value)) {
1✔
225
                switch ($this->data->os->version->value) {
1✔
226
                    case '2.3.3':
1✔
227
                    case '2.3.4':
1✔
228
                        $this->data->os->version = new Version([ 'value' => '1' ]);
1✔
229
                        break;
1✔
230
                    case '4.0.3':
1✔
231
                        $this->data->os->version = new Version([ 'value' => '2' ]);
1✔
232
                        break;
1✔
233
                    case '4.2.2':
1✔
234
                        $this->data->os->version = new Version([ 'value' => '3' ]);
1✔
235
                        break;
1✔
236
                    case '4.4.2':
1✔
237
                        $this->data->os->version = new Version([ 'value' => '4' ]);
1✔
238
                        break;
1✔
239
                    case '4.4.3':
1✔
240
                        $this->data->os->version = new Version([ 'value' => '4.5' ]);
1✔
241
                        break;
1✔
242
                    case '5.1.1':
1✔
243
                        $this->data->os->version = new Version([ 'value' => '5' ]);
1✔
244
                        break;
1✔
245
                    default:
246
                        unset($this->data->os->version);
1✔
247
                        break;
1✔
248
                }
249
            }
250

251
            if ($this->data->isBrowser('Chrome')) {
1✔
252
                $this->data->browser->reset();
1✔
253
                $this->data->browser->using = new Using([ 'name' => 'Amazon WebView' ]);
1✔
254
            }
255

256
            if ($this->data->browser->isUsing('Chromium WebView')) {
1✔
257
                $this->data->browser->using = new Using([ 'name' => 'Amazon WebView' ]);
1✔
258
            }
259

260
            unset($this->data->device->flag);
1✔
261
        }
262

263
        if ($flag == Constants\Flag::GOOGLETV) {
1✔
264
            $this->data->os->name = 'Google TV';
1✔
265
            $this->data->os->family = new Family([ 'name' => 'Android' ]);
1✔
266

267
            unset($this->data->os->version);
1✔
268
            unset($this->data->device->flag);
1✔
269
        }
270

271
        if ($flag == Constants\Flag::ANDROIDTV) {
1✔
272
            $this->data->os->name = 'Android TV';
1✔
273
            $this->data->os->family = new Family([ 'name' => 'Android' ]);
1✔
274
            unset($this->data->device->flag);
1✔
275
            unset($this->data->device->series);
1✔
276
        }
277

278
        if ($flag == Constants\Flag::ANDROIDWEAR) {
1✔
279
            $this->data->os->name = 'Android Wear';
1✔
280
            $this->data->os->family = new Family([ 'name' => 'Android' ]);
1✔
281
            unset($this->data->os->version);
1✔
282
            unset($this->data->device->flag);
1✔
283

284
            if ($this->data->browser->isUsing('Chrome Content Shell')) {
1✔
285
                $this->data->browser->name = 'Wear Internet Browser';
1✔
286
                $this->data->browser->using = null;
1✔
287
            }
288
        }
289

290
        if ($flag == Constants\Flag::GOOGLEGLASS) {
1✔
291
            $this->data->os->family = new Family([ 'name' => 'Android' ]);
1✔
292
            unset($this->data->os->name);
1✔
293
            unset($this->data->os->version);
1✔
294
            unset($this->data->device->flag);
1✔
295
        }
296

297
        if ($flag == Constants\Flag::UIQ) {
1✔
298
            unset($this->data->device->flag);
1✔
299

300
            if (!$this->data->isOs('UIQ')) {
1✔
301
                $this->data->os->name = 'UIQ';
1✔
302
                unset($this->data->os->version);
1✔
303
            }
304
        }
305

306
        if ($flag == Constants\Flag::S60) {
1✔
307
            unset($this->data->device->flag);
1✔
308

309
            if (!$this->data->isOs('Series60')) {
1✔
310
                $this->data->os->name = 'Series60';
1✔
311
                unset($this->data->os->version);
1✔
312
            }
313
        }
314

315
        if ($flag == Constants\Flag::MOAPS) {
1✔
316
            unset($this->data->device->flag);
1✔
317
            $this->data->os->name = 'MOAP(S)';
1✔
318
            unset($this->data->os->version);
1✔
319
        }
320
    }
1✔
321

322
    private function deriveBasedOnOperatingSystem()
323
    {
324
        /* Derive the default browser on Windows Mobile */
325

326
        if ($this->data->os->name == 'Windows Mobile' && $this->data->isBrowser('Internet Explorer')) {
1✔
327
            $this->data->browser->name = 'Mobile Internet Explorer';
1✔
328
        }
329

330
        /* Derive the default browser on Android */
331

332
        if ($this->data->os->name == 'Android' && !isset($this->data->browser->using) && !isset($this->data->browser->name) && $this->data->browser->stock) {
1✔
333
            $this->data->browser->name = 'Android Browser';
1✔
334
        }
335

336
        /* Derive the default browser on Google TV */
337

338
        if ($this->data->os->name == 'Google TV' && !isset($this->data->browser->name) && $this->data->browser->stock) {
1✔
339
            $this->data->browser->name = 'Chrome';
1✔
340
        }
341

342
        /* Derive the default browser on BlackBerry */
343

344
        if ($this->data->os->name == 'BlackBerry' && !isset($this->data->browser->name) && $this->data->browser->stock) {
1✔
345
            $this->data->browser->name = 'BlackBerry Browser';
1✔
346
            $this->data->browser->hidden = true;
1✔
347
        }
348

349
        if ($this->data->os->name == 'BlackBerry OS' && !isset($this->data->browser->name) && $this->data->browser->stock) {
1✔
350
            $this->data->browser->name = 'BlackBerry Browser';
1✔
351
            $this->data->browser->hidden = true;
1✔
352
        }
353

354
        if ($this->data->os->name == 'BlackBerry Tablet OS' && !isset($this->data->browser->name) && $this->data->browser->stock) {
1✔
355
            $this->data->browser->name = 'BlackBerry Browser';
1✔
356
            $this->data->browser->hidden = true;
1✔
357
        }
358

359
        /* Derive the default browser on Tizen */
360

361
        if ($this->data->os->name == 'Tizen' && !isset($this->data->browser->name) && $this->data->browser->stock && in_array($this->data->device->type, [ Constants\DeviceType::MOBILE, Constants\DeviceType::APPLIANCE ])) {
1✔
362
            $this->data->browser->name = 'Samsung Browser';
1✔
363
        }
364

365
        /* Derive the default browser on Aliyun OS */
366

367
        if ($this->data->os->name == 'Aliyun OS' && !isset($this->data->browser->using) && !isset($this->data->browser->name) && $this->data->browser->stock) {
1✔
368
            $this->data->browser->name = 'Aliyun Browser';
1✔
369
        }
370

371
        if ($this->data->os->name == 'Aliyun OS' && $this->data->browser->isUsing('Chrome Content Shell')) {
1✔
372
            $this->data->browser->name = 'Aliyun Browser';
1✔
373
            $this->data->browser->using = null;
1✔
374
            $this->data->browser->stock = true;
1✔
375
        }
376

377
        if ($this->data->os->name == 'Aliyun OS' && $this->data->browser->stock) {
1✔
378
            $this->data->browser->hidden = true;
1✔
379
        }
380

381
        /* Derive OS/2 nickname */
382

383
        if ($this->data->os->name == 'OS/2') {
1✔
384
            if (!empty($this->data->os->version)) {
1✔
385
                if ($this->data->os->version->is('>', '2')) {
1✔
386
                    $this->data->os->version->nickname = 'Warp';
1✔
387
                }
388
            }
389
        }
390

391
        /* Derive HP TouchPad based on webOS and tablet */
392

393
        if ($this->data->os->name == 'webOS' && $this->data->device->type == Constants\DeviceType::TABLET) {
1✔
394
            $this->data->device->manufacturer = 'HP';
1✔
395
            $this->data->device->model = 'TouchPad';
1✔
396
            $this->data->device->identified |= Constants\Id::MATCH_UA;
1✔
397
        }
398

399
        /* Derive Windows 10 Mobile edition */
400

401
        if ($this->data->os->name == 'Windows Phone') {
1✔
402
            if (!empty($this->data->os->version)) {
1✔
403
                if ($this->data->os->version->is('=', '10')) {
1✔
404
                    $this->data->os->alias = 'Windows';
1✔
405
                    $this->data->os->edition = 'Mobile';
1✔
406
                    $this->data->os->version->alias = '10';
1✔
407
                }
408
            }
409
        }
410

411
        /* Derive manufacturer and model based on MacOS or OS X */
412

413
        if ($this->data->os->name == 'OS X' || $this->data->os->name == 'Mac OS') {
1✔
414
            if (empty($this->data->device->model)) {
1✔
415
                $this->data->device->manufacturer = 'Apple';
1✔
416
                $this->data->device->model = 'Macintosh';
1✔
417
                $this->data->device->identified |= Constants\Id::INFER;
1✔
418
                $this->data->device->hidden = true;
1✔
419
            }
420
        }
421

422
        /* Derive manufacturer and model based on MacOS or OS X */
423

424
        if ($this->data->os->name == 'iOS') {
1✔
425
            if (empty($this->data->device->model)) {
1✔
426
                $this->data->device->manufacturer = 'Apple';
1✔
427
                $this->data->device->identified |= Constants\Id::INFER;
1✔
428
                $this->data->device->hidden = true;
1✔
429
            }
430
        }
431

432
        /* Derive iOS and OS X aliases */
433

434
        if ($this->data->os->name == 'iOS') {
1✔
435
            if (!empty($this->data->os->version)) {
1✔
436
                if ($this->data->os->version->is('<', '4')) {
1✔
437
                    $this->data->os->alias = 'iPhone OS';
1✔
438
                }
439
            }
440
        }
441

442
        if ($this->data->os->name == 'OS X') {
1✔
443
            if (!empty($this->data->os->version)) {
1✔
444
                if ($this->data->os->version->is('<', '10.7')) {
1✔
445
                    $this->data->os->alias = 'Mac OS X';
1✔
446
                }
447

448
                if ($this->data->os->version->is('>=', '10.12')) {
1✔
449
                    $this->data->os->alias = 'macOS';
1✔
450
                }
451

452
                if ($this->data->os->version->is('10.7')) {
1✔
453
                    $this->data->os->version->nickname = 'Lion';
1✔
454
                }
455

456
                if ($this->data->os->version->is('10.8')) {
1✔
457
                    $this->data->os->version->nickname = 'Mountain Lion';
1✔
458
                }
459

460
                if ($this->data->os->version->is('10.9')) {
1✔
461
                    $this->data->os->version->nickname = 'Mavericks';
1✔
462
                }
463

464
                if ($this->data->os->version->is('10.10')) {
1✔
465
                    $this->data->os->version->nickname = 'Yosemite';
1✔
466
                }
467

468
                if ($this->data->os->version->is('10.11')) {
1✔
469
                    $this->data->os->version->nickname = 'El Capitan';
1✔
470
                }
471

472
                if ($this->data->os->version->is('10.12')) {
1✔
473
                    $this->data->os->version->nickname = 'Sierra';
1✔
474
                }
475

476
                if ($this->data->os->version->is('10.13')) {
1✔
477
                    $this->data->os->version->nickname = 'High Sierra';
1✔
478
                }
479

480
                if ($this->data->os->version->is('10.14')) {
1✔
481
                    $this->data->os->version->nickname = 'Mojave';
1✔
482
                }
483

484
                if ($this->data->os->version->is('10.15')) {
1✔
485
                    $this->data->os->version->nickname = 'Catalina';
1✔
486
                }
487

488
                if ($this->data->os->version->is('11')) {
1✔
489
                    $this->data->os->version->nickname = 'Big Sur';
1✔
490
                }
491

492
                if ($this->data->os->version->is('12')) {
1✔
493
                    $this->data->os->version->nickname = 'Monterey';
1✔
494
                }
495

496
                if ($this->data->os->version->is('13')) {
1✔
497
                    $this->data->os->version->nickname = 'Ventura';
×
498
                }
499

500
                if ($this->data->os->version->is('14')) {
1✔
501
                    $this->data->os->version->nickname = 'Sonoma';
×
502
                }
503
            }
504
        }
505
    }
1✔
506
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc