• 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

78.57
/src/Parser/Header/UseragentClientVersion.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\BrowserLoaderInterface;
18
use UaLoader\Exception\NotFoundException;
19
use UaNormalizer\Normalizer\Exception\Exception;
20
use UaNormalizer\Normalizer\NormalizerInterface;
21
use UaParser\BrowserParserInterface;
22
use UaParser\ClientVersionInterface;
23
use UnexpectedValueException;
24

25
use function preg_match;
26

27
final readonly class UseragentClientVersion implements ClientVersionInterface
28
{
29
    /** @throws void */
30
    public function __construct(
21✔
31
        private BrowserParserInterface $browserParser,
32
        private BrowserLoaderInterface $browserLoader,
33
        private NormalizerInterface $normalizer,
34
    ) {
35
        // nothing to do
36
    }
21✔
37

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

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

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

63
        $matches = [];
21✔
64

65
        if (preg_match('/pr\([^\/]+\/(?P<version>[\d.]+)\);/', $normalizedValue, $matches)) {
21✔
66
            return $matches['version'];
11✔
67
        }
68

69
        if ($code === null) {
10✔
70
            try {
71
                $code = $this->browserParser->parse($normalizedValue);
10✔
72

73
                if ($code === '') {
7✔
74
                    return null;
7✔
75
                }
76
            } catch (UnexpectedValueException) {
3✔
77
                return null;
3✔
78
            }
79
        }
80

81
        try {
82
            $clientData = $this->browserLoader->load($code, $normalizedValue);
4✔
83
        } catch (NotFoundException) {
2✔
84
            return null;
2✔
85
        }
86

87
        try {
88
            $version = $clientData->getClient()->getVersion()->getVersion();
2✔
NEW
89
        } catch (UnexpectedValueException) {
×
NEW
90
            return null;
×
91
        }
92

93
        if ($version === '') {
2✔
NEW
94
            return null;
×
95
        }
96

97
        return $version;
2✔
98
    }
99
}
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