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

johnykvsky / dummygenerator / 17946528254

23 Sep 2025 12:42PM UTC coverage: 98.765%. Remained the same
17946528254

push

github

web-flow
Updated logo (#35)

880 of 891 relevant lines covered (98.77%)

16.55 hits per line

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

98.61
/src/Core/UserAgent.php
1
<?php
2

3
declare(strict_types = 1);
4

5
namespace DummyGenerator\Core;
6

7
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionInterface;
8
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionTrait;
9
use DummyGenerator\Definitions\Extension\UserAgentExtensionInterface;
10

11
class UserAgent implements UserAgentExtensionInterface, RandomizerAwareExtensionInterface
12
{
13
    use RandomizerAwareExtensionTrait;
14

15
    /** @var string[] */
16
    protected array $userAgents = ['firefox', 'chrome', 'internetExplorer', 'opera', 'safari', 'edge'];
17

18
    /** @var string[] */
19
    protected array $windowsPlatformTokens = [
20
        'Windows NT 6.2', 'Windows NT 6.1', 'Windows NT 6.0', 'Windows NT 5.2', 'Windows NT 5.1',
21
        'Windows NT 5.01', 'Windows NT 5.0', 'Windows NT 4.0', 'Windows 98; Win 9x 4.90', 'Windows 98',
22
        'Windows 95', 'Windows CE',
23
    ];
24

25
    /**
26
     * @var string[]
27
     *
28
     * Possible processors on Linux
29
     */
30
    protected array $linuxProcessor = ['i686', 'x86_64'];
31

32
    /**
33
     * @var string[]
34
     *
35
     * Mac processors (it also added U;)
36
     */
37
    protected array $macProcessor = ['Intel', 'PPC', 'U; Intel', 'U; PPC'];
38

39
    /**
40
     * @var string[]
41
     *
42
     * Add as many languages as you like.
43
     */
44
    protected array $lang = ['en-US', 'sl-SI', 'nl-NL'];
45

46
    public function userAgent(): string
47
    {
48
        $userAgentName = $this->randomizer->randomElement($this->userAgents);
1✔
49

50
        return $this->$userAgentName();
1✔
51
    }
52

53
    public function chrome(): string
54
    {
55
        $saf = $this->randomizer->getInt(531, 536) . $this->randomizer->getInt(0, 2);
1✔
56

57
        $platforms = [
1✔
58
            '(' . $this->linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . $this->randomizer->getInt(36, 40) . '.0.'
1✔
59
                . $this->randomizer->getInt(800, 899) . ".0 Mobile Safari/$saf",
1✔
60
            '(' . $this->windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . $this->randomizer->getInt(36, 40) . '.0.'
1✔
61
                . $this->randomizer->getInt(800, 899) . ".0 Mobile Safari/$saf",
1✔
62
            '(' . $this->macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/" . $this->randomizer->getInt(36, 40) . '.0.'
1✔
63
                . $this->randomizer->getInt(800, 899) . ".0 Mobile Safari/$saf",
1✔
64
        ];
1✔
65

66
        return 'Mozilla/5.0 ' . $this->randomizer->randomElement($platforms);
1✔
67
    }
68

69
    public function edge(): string
70
    {
71
        $saf = $this->randomizer->getInt(531, 537) . '.' . $this->randomizer->getInt(0, 2);
1✔
72
        $chrv = $this->randomizer->getInt(79, 99) . '.0';
1✔
73

74
        $platforms = [
1✔
75
            '(' . $this->windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . $this->randomizer->getInt(4000, 4844)
1✔
76
                . '.' . $this->randomizer->getInt(10, 99) . " Safari/$saf Edg/$chrv" . $this->randomizer->getInt(1000, 1146) . '.'
1✔
77
                . $this->randomizer->getInt(0, 99),
1✔
78
            '(' . $this->macPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . $this->randomizer->getInt(4000, 4844)
1✔
79
                . '.' . $this->randomizer->getInt(10, 99) . " Safari/$saf Edg/$chrv" . $this->randomizer->getInt(1000, 1146)
1✔
80
                . '.' . $this->randomizer->getInt(0, 99),
1✔
81
            '(' . $this->linuxPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Chrome/$chrv" . '.' . $this->randomizer->getInt(4000, 4844)
1✔
82
                . '.' . $this->randomizer->getInt(10, 99) . " Safari/$saf EdgA/$chrv" . $this->randomizer->getInt(1000, 1146)
1✔
83
                . '.' . $this->randomizer->getInt(0, 99),
1✔
84
            '(' . $this->iosMobileToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/15.0 EdgiOS/$chrv" . $this->randomizer->getInt(1000, 1146)
1✔
85
                . '.' . $this->randomizer->getInt(0, 99) . " Mobile/15E148 Safari/$saf",
1✔
86
        ];
1✔
87

88
        return 'Mozilla/5.0 ' . $this->randomizer->randomElement($platforms);
1✔
89
    }
90

91
    public function firefox(): string
92
    {
93
        $ver = 'Gecko/' . date('Ymd', $this->randomizer->getInt(strtotime('2010-1-1'), time())) . ' Firefox/'
1✔
94
            . $this->randomizer->getInt(35, 37) . '.0';
1✔
95

96
        $platforms = [
1✔
97
            '(' . $this->windowsPlatformToken() . '; ' . $this->randomizer->randomElement($this->lang) . '; rv:1.9.' . $this->randomizer->getInt(0, 2)
1✔
98
                . '.20) ' . $ver,
1✔
99
            '(' . $this->linuxPlatformToken() . '; rv:' . $this->randomizer->getInt(5, 7) . '.0) ' . $ver,
1✔
100
            '(' . $this->macPlatformToken() . ' rv:' . $this->randomizer->getInt(2, 6) . '.0) ' . $ver,
1✔
101
        ];
1✔
102

103
        return 'Mozilla/5.0 ' . $this->randomizer->randomElement($platforms);
1✔
104
    }
105

106
    public function safari(): string
107
    {
108
        $saf = $this->randomizer->getInt(531, 535) . '.' . $this->randomizer->getInt(1, 50) . '.' . $this->randomizer->getInt(1, 7);
1✔
109

110
        $ver = $this->randomizer->getBool() ?
1✔
111
            $this->randomizer->getInt(4, 5) . '.' . $this->randomizer->getInt(0, 1)
×
112
            :
1✔
113
            $this->randomizer->getInt(4, 5) . '.0.' . $this->randomizer->getInt(1, 5);
1✔
114

115
        $mobileDevices = [
1✔
116
            'iPhone; CPU iPhone OS',
1✔
117
            'iPad; CPU OS',
1✔
118
        ];
1✔
119

120
        $platforms = [
1✔
121
            '(Windows; U; ' . $this->windowsPlatformToken() . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
1✔
122
            '(' . $this->macPlatformToken() . ' rv:' . $this->randomizer->getInt(2, 6) . '.0; ' . $this->randomizer->randomElement($this->lang)
1✔
123
                . ") AppleWebKit/$saf (KHTML, like Gecko) Version/$ver Safari/$saf",
1✔
124
            '(' . $this->randomizer->randomElement($mobileDevices) . ' ' . $this->randomizer->getInt(7, 8) . '_' . $this->randomizer->getInt(0, 2)
1✔
125
                . '_' . $this->randomizer->getInt(1, 2) . ' like Mac OS X; ' . $this->randomizer->randomElement($this->lang)
1✔
126
                . ") AppleWebKit/$saf (KHTML, like Gecko) Version/" . $this->randomizer->getInt(3, 4) . '.0.5 Mobile/8B'
1✔
127
                . $this->randomizer->getInt(111, 119) . " Safari/6$saf",
1✔
128
        ];
1✔
129

130
        return 'Mozilla/5.0 ' . $this->randomizer->randomElement($platforms);
1✔
131
    }
132

133
    public function opera(): string
134
    {
135
        $platforms = [
1✔
136
            '(' . $this->linuxPlatformToken() . '; ' . $this->randomizer->randomElement($this->lang) . ') Presto/2.' . $this->randomizer->getInt(8, 12)
1✔
137
                . '.' . $this->randomizer->getInt(160, 355) . ' Version/' . $this->randomizer->getInt(10, 12) . '.00',
1✔
138
            '(' . $this->windowsPlatformToken() . '; ' . $this->randomizer->randomElement($this->lang) . ') Presto/2.' . $this->randomizer->getInt(8, 12)
1✔
139
                . '.' . $this->randomizer->getInt(160, 355) . ' Version/' . $this->randomizer->getInt(10, 12) . '.00',
1✔
140
        ];
1✔
141

142
        return 'Opera/' . $this->randomizer->getInt(8, 9) . '.' . $this->randomizer->getInt(10, 99) . ' ' . $this->randomizer->randomElement($platforms);
1✔
143
    }
144

145
    public function internetExplorer(): string
146
    {
147
        return 'Mozilla/5.0 (compatible; MSIE ' . $this->randomizer->getInt(5, 11) . '.0; ' . $this->windowsPlatformToken() . '; Trident/'
2✔
148
                . $this->randomizer->getInt(3, 5) . '.' . $this->randomizer->getInt(0, 1) . ')';
2✔
149
    }
150

151
    public function windowsPlatformToken(): string
152
    {
153
        return $this->randomizer->randomElement($this->windowsPlatformTokens);
8✔
154
    }
155

156
    public function macPlatformToken(): string
157
    {
158
        return 'Macintosh; ' . $this->randomizer->randomElement($this->macProcessor) . ' Mac OS X 10_' . $this->randomizer->getInt(5, 8)
5✔
159
                . '_' . $this->randomizer->getInt(0, 9);
5✔
160
    }
161

162
    public function iosMobileToken(): string
163
    {
164
        $iosVer = $this->randomizer->getInt(13, 15) . '_' . $this->randomizer->getInt(0, 2);
2✔
165

166
        return 'iPhone; CPU iPhone OS ' . $iosVer . ' like Mac OS X';
2✔
167
    }
168

169
    public function androidMobileToken(): string
170
    {
171
        return 'Linux; Android ' . $this->randomizer->getInt(8, 15);
1✔
172
    }
173

174
    public function linuxPlatformToken(): string
175
    {
176
        return 'X11; Linux ' . $this->randomizer->randomElement($this->linuxProcessor);
5✔
177
    }
178
}
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