• 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

96.0
/src/Loader/DeviceLoaderFactory.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\InitData\Device as DataDevice;
17
use Laminas\Hydrator\ArraySerializableHydrator;
18
use Laminas\Hydrator\Exception\InvalidArgumentException;
19
use Laminas\Hydrator\Strategy\CollectionStrategy;
20
use Laminas\Hydrator\Strategy\SerializableStrategy;
21
use Laminas\Hydrator\Strategy\StrategyChain;
22
use Laminas\Serializer\Adapter\Json;
23
use Override;
24
use Psr\Log\LoggerInterface;
25
use UaLoader\DeviceLoaderInterface;
26

27
use function array_key_exists;
28

29
final class DeviceLoaderFactory implements DeviceLoaderFactoryInterface
30
{
31
    /** @var array<string, DeviceLoaderInterface> */
32
    private array $loader = [];
33

34
    /** @throws void */
35
    public function __construct(
1✔
36
        private readonly LoggerInterface $logger,
37
        private readonly CompanyLoaderInterface $companyLoader,
38
    ) {
39
        // nothing to do
40
    }
1✔
41

42
    /** @throws InvalidArgumentException */
43
    #[Override]
1✔
44
    public function __invoke(string $company = ''): DeviceLoaderInterface
45
    {
46
        if (array_key_exists($company, $this->loader)) {
1✔
UNCOV
47
            return $this->loader[$company];
×
48
        }
49

50
        $serializableStrategy = new SerializableStrategy(
1✔
51
            new Json(),
1✔
52
        );
1✔
53

54
        $this->loader[$company] = new DeviceLoader(
1✔
55
            logger: $this->logger,
1✔
56
            initData: new Data\Device(
1✔
57
                strategy: new StrategyChain(
1✔
58
                    [
1✔
59
                        new CollectionStrategy(
1✔
60
                            new ArraySerializableHydrator(),
1✔
61
                            DataDevice::class,
1✔
62
                        ),
1✔
63
                        $serializableStrategy,
1✔
64
                    ],
1✔
65
                ),
1✔
66
                company: $company,
1✔
67
            ),
1✔
68
            companyLoader: $this->companyLoader,
1✔
69
        );
1✔
70

71
        return $this->loader[$company];
1✔
72
    }
73
}
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