• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mimmi20 / ua-generic-request / 12795016257

15 Jan 2025 06:47PM UTC coverage: 88.776%. First build
12795016257

push

github

web-flow
Merge pull request #358 from mimmi20/updates

change constants

49 of 50 new or added lines in 2 files covered. (98.0%)

261 of 294 relevant lines covered (88.78%)

6.9 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

97.87
/src/Headers.php
1
<?php
2

3
/**
4
 * This file is part of the mimmi20/ua-generic-request package.
5
 *
6
 * Copyright (c) 2015-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 UaRequest;
15

16
use Psr\Http\Message\MessageInterface;
17

18
use function array_keys;
19
use function array_multisort;
20
use function is_string;
21
use function mb_strtolower;
22
use function mb_substr;
23
use function str_starts_with;
24

25
use const SORT_ASC;
26
use const SORT_NUMERIC;
27

28
enum Headers: string
29
{
30
    case HEADER_BAIDU_FLYFLOW = Constants::HEADER_BAIDU_FLYFLOW;
31

32
    case HEADER_DEVICE_STOCK_UA = Constants::HEADER_DEVICE_STOCK_UA;
33

34
    case HEADER_SEC_CH_UA = Constants::HEADER_SEC_CH_UA;
35

36
    case HEADER_SEC_CH_UA_ARCH = Constants::HEADER_SEC_CH_UA_ARCH;
37

38
    case HEADER_SEC_CH_UA_BITNESS = Constants::HEADER_SEC_CH_UA_BITNESS;
39

40
    case HEADER_SEC_CH_UA_FULL_VERSION = Constants::HEADER_SEC_CH_UA_FULL_VERSION;
41

42
    case HEADER_SEC_CH_UA_FULL_VERSION_LIST = Constants::HEADER_SEC_CH_UA_FULL_VERSION_LIST;
43

44
    case HEADER_SEC_CH_UA_MOBILE = Constants::HEADER_SEC_CH_UA_MOBILE;
45

46
    case HEADER_SEC_CH_UA_MODEL = Constants::HEADER_SEC_CH_UA_MODEL;
47

48
    case HEADER_SEC_CH_UA_PLATFORM = Constants::HEADER_SEC_CH_UA_PLATFORM;
49

50
    case HEADER_SEC_CH_UA_PLATFORM_VERSION = Constants::HEADER_SEC_CH_UA_PLATFORM_VERSION;
51

52
    case HEADER_UA_OS = Constants::HEADER_UA_OS;
53

54
    case HEADER_CRAWLED_BY = Constants::HEADER_CRAWLED_BY;
55

56
    case HEADER_USERAGENT = Constants::HEADER_USERAGENT;
57

58
    case HEADER_ORIGINAL_UA = Constants::HEADER_ORIGINAL_UA;
59

60
    case HEADER_DEVICE_UA = Constants::HEADER_DEVICE_UA;
61

62
    case HEADER_OPERAMINI_PHONE = Constants::HEADER_OPERAMINI_PHONE;
63

64
    case HEADER_OPERAMINI_PHONE_UA = Constants::HEADER_OPERAMINI_PHONE_UA;
65

66
    case HEADER_PUFFIN_UA = Constants::HEADER_PUFFIN_UA;
67

68
    case HEADER_REQUESTED_WITH = Constants::HEADER_REQUESTED_WITH;
69

70
    case HEADER_UCBROWSER_DEVICE = Constants::HEADER_UCBROWSER_DEVICE;
71

72
    case HEADER_UCBROWSER_DEVICE_UA = Constants::HEADER_UCBROWSER_DEVICE_UA;
73

74
    case HEADER_UCBROWSER_PHONE = Constants::HEADER_UCBROWSER_PHONE;
75

76
    case HEADER_UCBROWSER_PHONE_UA = Constants::HEADER_UCBROWSER_PHONE_UA;
77

78
    case HEADER_UCBROWSER_UA = Constants::HEADER_UCBROWSER_UA;
79

80
    /**
81
     * @return array<non-empty-string, non-empty-string>
82
     *
83
     * @throws void
84
     */
85
    public static function filter(MessageInterface $message): array
16✔
86
    {
87
        $filteredHeaders = [];
16✔
88

89
        foreach (array_keys($message->getHeaders()) as $header) {
16✔
90
            if (!is_string($header) || $header === '') {
16✔
91
                continue;
1✔
92
            }
93

94
            $headerLine = $message->getHeaderLine($header);
16✔
95

96
            if ($headerLine === '') {
16✔
97
                continue;
2✔
98
            }
99

100
            $header = mb_strtolower($header);
16✔
101

102
            if (str_starts_with($header, 'http-') || str_starts_with($header, 'http_')) {
16✔
103
                $header = mb_substr($header, 5);
4✔
104
            }
105

106
            if ($header === '' || self::tryFrom($header) === null) {
16✔
107
                continue;
9✔
108
            }
109

110
            $filteredHeaders[$header] = $headerLine;
16✔
111
        }
112

113
        $headerSort = [];
16✔
114

115
        foreach (array_keys($filteredHeaders) as $header) {
16✔
116
            $enum = self::tryFrom($header);
16✔
117

118
            $headerSort[$header] = match ($enum) {
16✔
119
                self::HEADER_SEC_CH_UA_MODEL => 1,
16✔
120
                self::HEADER_SEC_CH_UA_PLATFORM => 2,
16✔
121
                self::HEADER_SEC_CH_UA_PLATFORM_VERSION => 3,
16✔
122
                self::HEADER_SEC_CH_UA_FULL_VERSION_LIST => 4,
16✔
123
                self::HEADER_REQUESTED_WITH => 5,
16✔
124
                self::HEADER_SEC_CH_UA => 6,
16✔
125
                self::HEADER_SEC_CH_UA_FULL_VERSION => 7,
16✔
126
                self::HEADER_SEC_CH_UA_BITNESS => 8,
16✔
127
                self::HEADER_SEC_CH_UA_ARCH => 9,
16✔
128
                self::HEADER_SEC_CH_UA_MOBILE => 10,
16✔
129
                self::HEADER_DEVICE_UA => 11,
16✔
130
                self::HEADER_UCBROWSER_UA => 12,
16✔
131
                self::HEADER_UCBROWSER_DEVICE_UA => 13,
16✔
132
                self::HEADER_UCBROWSER_DEVICE => 14,
16✔
133
                self::HEADER_UCBROWSER_PHONE_UA => 15,
16✔
134
                self::HEADER_UCBROWSER_PHONE => 16,
16✔
135
                self::HEADER_OPERAMINI_PHONE_UA => 17,
16✔
136
                self::HEADER_DEVICE_STOCK_UA => 18,
16✔
137
                self::HEADER_OPERAMINI_PHONE => 19,
15✔
138
                self::HEADER_ORIGINAL_UA => 20,
15✔
139
                self::HEADER_UA_OS => 21,
15✔
140
                self::HEADER_BAIDU_FLYFLOW => 22,
15✔
141
                self::HEADER_PUFFIN_UA => 23,
15✔
142
                self::HEADER_CRAWLED_BY => 24,
15✔
143
                self::HEADER_USERAGENT => 25,
15✔
NEW
144
                default => 26,
×
145
            };
16✔
146
        }
147

148
        array_multisort($headerSort, SORT_ASC, SORT_NUMERIC, $filteredHeaders);
16✔
149

150
        return $filteredHeaders;
16✔
151
    }
152
}
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