• 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

76.92
/src/Parser/Header/UseragentEngineVersion.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 UaLoader\EngineLoaderInterface;
18
use UaNormalizer\Normalizer\Exception\Exception;
19
use UaNormalizer\Normalizer\NormalizerInterface;
20
use UaParser\EngineParserInterface;
21
use UaParser\EngineVersionInterface;
22
use UnexpectedValueException;
23

24
use function preg_match;
25

26
final readonly class UseragentEngineVersion implements EngineVersionInterface
27
{
28
    /** @throws void */
29
    public function __construct(
21✔
30
        private EngineParserInterface $engineParser,
31
        private EngineLoaderInterface $engineLoader,
32
        private NormalizerInterface $normalizer,
33
    ) {
34
        // nothing to do
35
    }
21✔
36

37
    /**
38
     * @throws void
39
     *
40
     * @phpcsSuppress SlevomatCodingStandard.Functions.UnusedParameter.UnusedParameter
41
     */
42
    #[Override]
21✔
43
    public function hasEngineVersion(string $value): bool
44
    {
45
        return true;
21✔
46
    }
47

48
    /** @throws void */
49
    #[Override]
21✔
50
    public function getEngineVersion(string $value, string | null $code = null): string | null
51
    {
52
        try {
53
            $normalizedValue = $this->normalizer->normalize($value);
21✔
NEW
54
        } catch (Exception) {
×
NEW
55
            return null;
×
56
        }
57

58
        if ($normalizedValue === '' || $normalizedValue === null) {
21✔
NEW
59
            return null;
×
60
        }
61

62
        $matches = [];
21✔
63

64
        if (preg_match('/(?<!o)re\([^\/]+\/(?P<version>[\d.]+)/', $normalizedValue, $matches)) {
21✔
65
            return $matches['version'];
10✔
66
        }
67

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

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

76
        try {
77
            $engine = $this->engineLoader->load($code, $normalizedValue);
8✔
78
        } catch (UnexpectedValueException) {
2✔
79
            return null;
2✔
80
        }
81

82
        try {
83
            $version = $engine->getVersion()->getVersion();
6✔
NEW
84
        } catch (UnexpectedValueException) {
×
NEW
85
            return null;
×
86
        }
87

88
        if ($version === '') {
6✔
NEW
89
            return null;
×
90
        }
91

92
        return $version;
6✔
93
    }
94
}
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