• 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

76.92
/src/Parser/Header/UseragentPlatformVersion.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\Exception\NotFoundException;
18
use UaLoader\PlatformLoaderInterface;
19
use UaNormalizer\Normalizer\Exception\Exception;
20
use UaNormalizer\Normalizer\NormalizerInterface;
21
use UaParser\PlatformParserInterface;
22
use UaParser\PlatformVersionInterface;
23
use UnexpectedValueException;
24

25
use function preg_match;
26
use function str_replace;
27

28
final readonly class UseragentPlatformVersion implements PlatformVersionInterface
29
{
30
    /** @throws void */
31
    public function __construct(
21✔
32
        private PlatformParserInterface $platformParser,
33
        private PlatformLoaderInterface $platformLoader,
34
        private NormalizerInterface $normalizer,
35
    ) {
36
        // nothing to do
37
    }
21✔
38

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

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

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

64
        $matches = [];
21✔
65

66
        if (
67
            preg_match('/ov\((?:(wds|android) )?(?P<version>[\d_.]+)\);/i', $normalizedValue, $matches)
21✔
68
        ) {
69
            return str_replace('_', '.', $matches['version']);
11✔
70
        }
71

72
        if ($code === null) {
10✔
73
            $code = $this->platformParser->parse($normalizedValue);
10✔
74

75
            if ($code === '') {
10✔
76
                return null;
3✔
77
            }
78
        }
79

80
        try {
81
            $platform = $this->platformLoader->load($code, $normalizedValue);
7✔
82
        } catch (NotFoundException) {
2✔
83
            return null;
2✔
84
        }
85

86
        try {
87
            $version = $platform->getVersion()->getVersion();
5✔
NEW
88
        } catch (UnexpectedValueException) {
×
NEW
89
            return null;
×
90
        }
91

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

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