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

mimmi20 / browser-detector / 26619626009

29 May 2026 05:20AM UTC coverage: 96.478% (-0.01%) from 96.488%
26619626009

push

github

web-flow
Merge pull request #1058 from mimmi20/dependabot/composer/development-dependencies-f926ab8d74

composer (master)(deps-dev): bump the development-dependencies group with 7 updates

15285 of 15843 relevant lines covered (96.48%)

157.91 hits per line

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

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

3
/**
4
 * This file is part of the browser-detector package.
5
 *
6
 * Copyright (c) 2012-2026, 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 UaLoader\Exception\NotFoundException;
21
use UaLoader\PlatformLoaderInterface;
22
use UaResult\Bits\Bits;
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(
×
36
        private readonly LoggerInterface $logger,
37
        private readonly CompanyLoaderInterface $companyLoader,
38
        VersionBuilderInterface $versionBuilder,
39
    ) {
40
        $this->versionBuilder = $versionBuilder;
×
41
    }
42

43
    /** @throws void */
44
    #[Override]
45
    public function load(string $key, string $useragent = ''): OsInterface
×
46
    {
47
        try {
48
            $os = \BrowserDetector\Data\Os::fromName($key);
×
49
        } catch (UnexpectedValueException) {
×
50
            $os = \BrowserDetector\Data\Os::unknown;
×
51
        }
52

53
        return $this->loadFromOs($os, $useragent);
×
54
    }
55

56
    /** @throws void */
57
    #[Override]
58
    public function loadFromOs(\UaData\OsInterface $os, string $useragent = ''): OsInterface
×
59
    {
60
        $name          = $os->getName();
×
61
        $marketingName = $os->getMarketingName();
×
62
        $manufacturer  = new Company(type: 'unknown', name: null, brandname: null);
×
63
        $version       = $this->getVersion((object) $os->getVersion(), $useragent);
×
64

65
        if ($os->getManufacturer()->getBrandname() !== null) {
×
66
            try {
67
                $manufacturer = $this->companyLoader->load($os->getManufacturer()->getBrandname());
×
68
            } catch (NotFoundException $e) {
×
69
                $this->logger->info($e);
×
70
            }
71
        }
72

73
        try {
74
            $versionWithoutMicro = $version->getVersion(VersionInterface::IGNORE_MICRO);
×
75

76
            if ($versionWithoutMicro !== null) {
×
77
                if ($name === 'Mac OS X' && version_compare($versionWithoutMicro, '10.12', '>=')) {
×
78
                    $name          = 'macOS';
×
79
                    $marketingName = 'macOS';
×
80
                } elseif (
81
                    $name === 'iOS'
×
82
                    && version_compare($versionWithoutMicro, '4.0', '<')
×
83
                    && version_compare($versionWithoutMicro, '0.0', '>')
×
84
                ) {
85
                    $name          = 'iPhone OS';
×
86
                    $marketingName = 'iPhone OS';
×
87
                }
88
            }
89
        } catch (UnexpectedValueException $e) {
×
90
            $this->logger->info($e);
×
91
        }
92

93
        return new Os(
×
94
            name: $name,
×
95
            marketingName: $marketingName,
×
96
            manufacturer: $manufacturer,
×
97
            version: $version,
×
98
            bits: Bits::unknown,
×
99
        );
×
100
    }
101
}
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