• 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

18.92
/src/Loader/DeviceLoader.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\DeviceData;
17
use Override;
18
use Psr\Log\LoggerInterface;
19
use RuntimeException;
20
use UaDeviceType\Type;
21
use UaLoader\Data\DeviceDataInterface;
22
use UaLoader\DeviceLoaderInterface;
23
use UaLoader\Exception\NotFoundException;
24
use UaResult\Company\Company;
25
use UaResult\Device\Device;
26
use UaResult\Device\DeviceInterface;
27
use UaResult\Device\Display;
28

29
final readonly class DeviceLoader implements DeviceLoaderInterface
30
{
31
    /** @throws void */
32
    public function __construct(
2✔
33
        private LoggerInterface $logger,
34
        private Data\Device $initData,
35
        private CompanyLoaderInterface $companyLoader,
36
    ) {
37
        // nothing to do
38
    }
2✔
39

40
    /** @throws NotFoundException */
41
    #[Override]
2✔
42
    public function load(string $key): DeviceDataInterface
43
    {
44
        try {
45
            $this->initData->init();
2✔
NEW
46
        } catch (RuntimeException $e) {
×
NEW
47
            throw new NotFoundException('the device with key "' . $key . '" was not found', 0, $e);
×
48
        }
49

50
        $deviceData = $this->initData->getItem($key);
2✔
51

52
        if ($deviceData === null) {
2✔
53
            throw new NotFoundException('the device with key "' . $key . '" was not found');
2✔
54
        }
55

NEW
56
        $device = $this->fromArray($deviceData);
×
57

NEW
58
        return new DeviceData(device: $device, os: $deviceData->getPlatform());
×
59
    }
60

61
    /** @throws void */
NEW
62
    private function fromArray(InitData\Device $data): DeviceInterface
×
63
    {
UNCOV
64
        $manufacturer = new Company(type: 'unknown', name: null, brandname: null);
×
65

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

UNCOV
74
        $brand = new Company(type: 'unknown', name: null, brandname: null);
×
75

NEW
76
        if ($data->getBrand() !== null) {
×
77
            try {
NEW
78
                $brand = $this->companyLoader->load($data->getBrand());
×
NEW
79
            } catch (NotFoundException $e) {
×
NEW
80
                $this->logger->info($e);
×
81
            }
82
        }
83

UNCOV
84
        return new Device(
×
NEW
85
            deviceName: $data->getDeviceName(),
×
NEW
86
            marketingName: $data->getMarketingName(),
×
UNCOV
87
            manufacturer: $manufacturer,
×
UNCOV
88
            brand: $brand,
×
NEW
89
            type: Type::fromName($data->getType()),
×
UNCOV
90
            display: new Display(
×
NEW
91
                width: $data->getDisplay()['width'],
×
NEW
92
                height: $data->getDisplay()['height'],
×
NEW
93
                touch: $data->getDisplay()['touch'],
×
NEW
94
                size: $data->getDisplay()['size'],
×
UNCOV
95
            ),
×
NEW
96
            dualOrientation: $data->getDualOrientation(),
×
NEW
97
            simCount: $data->getSimCount(),
×
UNCOV
98
        );
×
99
    }
100
}
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