• 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

84.21
/src/Parser/Header/UseragentEngineCode.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\Parser\Header;
15

16
use Override;
17
use UaNormalizer\Normalizer\Exception\Exception;
18
use UaNormalizer\Normalizer\NormalizerInterface;
19
use UaParser\EngineCodeInterface;
20
use UaParser\EngineParserInterface;
21

22
use function mb_strtolower;
23
use function preg_match;
24

25
final readonly class UseragentEngineCode implements EngineCodeInterface
26
{
27
    /** @throws void */
28
    public function __construct(private EngineParserInterface $engineParser, private NormalizerInterface $normalizer)
21✔
29
    {
30
        // nothing to do
31
    }
21✔
32

33
    /**
34
     * @throws void
35
     *
36
     * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
37
     */
38
    #[Override]
21✔
39
    public function hasEngineCode(string $value): bool
40
    {
41
        return true;
21✔
42
    }
43

44
    /** @throws void */
45
    #[Override]
21✔
46
    public function getEngineCode(string $value): string | null
47
    {
48
        try {
49
            $normalizedValue = $this->normalizer->normalize($value);
21✔
NEW
50
        } catch (Exception) {
×
NEW
51
            return null;
×
52
        }
53

54
        if ($normalizedValue === '' || $normalizedValue === null) {
21✔
NEW
55
            return null;
×
56
        }
57

58
        $matches = [];
21✔
59

60
        if (preg_match('/(?<!o)re\((?P<engine>[^\/)]+)(?:\/[\d.]+)?/', $normalizedValue, $matches)) {
21✔
61
            $code = mb_strtolower($matches['engine']);
10✔
62

63
            return match ($code) {
64
                'applewebkit' => 'webkit',
10✔
65
                default => $code,
10✔
66
            };
67
        }
68

69
        $code = $this->engineParser->parse($normalizedValue);
11✔
70

71
        if ($code === '') {
11✔
72
            return null;
3✔
73
        }
74

75
        return $code;
8✔
76
    }
77
}
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