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

mimmi20 / browser-detector / 12945342151

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

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

92.59
/src/Loader/BrowserLoader.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\Loader\Data\ClientData;
17
use BrowserDetector\Loader\InitData\Client as DataClient;
18
use BrowserDetector\Version\VersionBuilderInterface;
19
use Override;
20
use Psr\Log\LoggerInterface;
21
use RuntimeException;
22
use UaBrowserType\Type;
23
use UaLoader\BrowserLoaderInterface;
24
use UaLoader\Data\ClientDataInterface;
25
use UaLoader\Exception\NotFoundException;
26
use UaResult\Browser\Browser;
27
use UaResult\Company\Company;
28

29
final class BrowserLoader implements BrowserLoaderInterface
30
{
31
    use VersionFactoryTrait;
32

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

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

53
        $browserData = $this->initData->getItem($key);
3✔
54

55
        if ($browserData === null) {
3✔
56
            throw new NotFoundException('the browser with key "' . $key . '" was not found');
2✔
57
        }
58

59
        return new ClientData(
1✔
60
            client: $this->fromArray($browserData, $useragent),
1✔
61
            engine: $browserData->getEngine(),
1✔
62
        );
1✔
63
    }
64

65
    /** @throws void */
66
    private function fromArray(DataClient $data, string $useragent = ''): Browser
1✔
67
    {
68
        $manufacturer = new Company(type: 'unknown', name: null, brandname: null);
1✔
69

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

78
        return new Browser(
1✔
79
            name: $data->getName(),
1✔
80
            manufacturer: $manufacturer,
1✔
81
            version: $this->getVersion($data->getVersion(), $useragent),
1✔
82
            type: Type::fromName($data->getType()),
1✔
83
            bits: null,
1✔
84
            modus: null,
1✔
85
        );
1✔
86
    }
87
}
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