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

mimmi20 / browser-detector / 12915563542

22 Jan 2025 07:24PM UTC coverage: 89.212% (-10.8%) from 100.0%
12915563542

push

github

web-flow
Merge pull request #872 from mimmi20/updates

rewrite Headers

2983 of 3466 new or added lines in 72 files covered. (86.06%)

9 existing lines in 2 files now uncovered.

4234 of 4746 relevant lines covered (89.21%)

11.89 hits per line

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

94.59
/src/Loader/PlatformLoader.php
1
<?php
2

3
/**
4
 * This file is part of the browser-detector package.
5
 *
6
 * Copyright (c) 2012-2025, Thomas Mueller <mimmi20@live.de>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11

12
declare(strict_types = 1);
13

14
namespace BrowserDetector\Loader;
15

16
use BrowserDetector\Version\VersionBuilderInterface;
17
use BrowserDetector\Version\VersionInterface;
18
use Override;
19
use Psr\Log\LoggerInterface;
20
use RuntimeException;
21
use UaLoader\Exception\NotFoundException;
22
use UaLoader\PlatformLoaderInterface;
23
use UaResult\Company\Company;
24
use UaResult\Os\Os;
25
use UaResult\Os\OsInterface;
26
use UnexpectedValueException;
27

28
use function version_compare;
29

30
final class PlatformLoader implements PlatformLoaderInterface
31
{
32
    use VersionFactoryTrait;
33

34
    /** @throws void */
35
    public function __construct(
23✔
36
        private readonly LoggerInterface $logger,
37
        private readonly Data\Os $initData,
38
        private readonly CompanyLoaderInterface $companyLoader,
39
        VersionBuilderInterface $versionBuilder,
40
    ) {
41
        $this->versionBuilder = $versionBuilder;
23✔
42
    }
43

44
    /** @throws NotFoundException */
45
    #[Override]
23✔
46
    public function load(string $key, string $useragent = ''): OsInterface
47
    {
48
        try {
49
            $this->initData->init();
23✔
NEW
50
        } catch (RuntimeException $e) {
×
NEW
51
            throw new NotFoundException('the platform with key "' . $key . '" was not found', 0, $e);
×
52
        }
53

54
        $platformData = $this->initData->getItem($key);
23✔
55

56
        if ($platformData === null) {
23✔
57
            throw new NotFoundException('the platform with key "' . $key . '" was not found');
2✔
58
        }
59

60
        return $this->fromArray($platformData, $useragent);
21✔
61
    }
62

63
    /** @throws void */
64
    private function fromArray(InitData\Os $data, string $useragent): OsInterface
21✔
65
    {
66
        $name          = $data->getName();
21✔
67
        $marketingName = $data->getMarketingName();
21✔
68
        $manufacturer  = new Company(type: 'unknown', name: null, brandname: null);
21✔
69

70
        if ($data->getManufacturer() !== null) {
21✔
71
            try {
72
                $manufacturer = $this->companyLoader->load($data->getManufacturer());
21✔
73
            } catch (NotFoundException $e) {
1✔
74
                $this->logger->info($e);
1✔
75
            }
76
        }
77

78
        $version = $this->getVersion($data->getVersion(), $useragent);
21✔
79

80
        try {
81
            $versionWithoutMicro = $version->getVersion(VersionInterface::IGNORE_MICRO);
21✔
82

83
            if ($versionWithoutMicro !== null) {
20✔
84
                if ($name === 'Mac OS X' && version_compare($versionWithoutMicro, '10.12', '>=')) {
11✔
85
                    $name          = 'macOS';
1✔
86
                    $marketingName = 'macOS';
1✔
87
                } elseif (
88
                    $name === 'iOS'
10✔
89
                    && version_compare($versionWithoutMicro, '4.0', '<')
10✔
90
                    && version_compare($versionWithoutMicro, '0.0', '>')
10✔
91
                ) {
92
                    $name          = 'iPhone OS';
1✔
93
                    $marketingName = 'iPhone OS';
20✔
94
                }
95
            }
96
        } catch (UnexpectedValueException $e) {
1✔
97
            $this->logger->info($e);
1✔
98
        }
99

100
        return new Os(
21✔
101
            name: $name,
21✔
102
            marketingName: $marketingName,
21✔
103
            manufacturer: $manufacturer,
21✔
104
            version: $version,
21✔
105
        );
21✔
106
    }
107
}
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