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

johnykvsky / dummygenerator / 18040378415

26 Sep 2025 02:16PM UTC coverage: 98.667% (-0.1%) from 98.765%
18040378415

Pull #36

github

web-flow
Merge 7e01a822d into 7e80368d5
Pull Request #36: Updated anydatetime

12 of 12 new or added lines in 2 files covered. (100.0%)

2 existing lines in 2 files now uncovered.

888 of 900 relevant lines covered (98.67%)

16.66 hits per line

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

93.62
/src/Core/Internet.php
1
<?php
2

3
declare(strict_types = 1);
4

5
namespace DummyGenerator\Core;
6

7
use DummyGenerator\Definitions\Extension\Awareness\GeneratorAwareExtensionInterface;
8
use DummyGenerator\Definitions\Extension\Awareness\GeneratorAwareExtensionTrait;
9
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionInterface;
10
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionTrait;
11
use DummyGenerator\Definitions\Extension\Awareness\ReplacerAwareExtensionInterface;
12
use DummyGenerator\Definitions\Extension\Awareness\ReplacerAwareExtensionTrait;
13
use DummyGenerator\Definitions\Extension\Exception\ExtensionRuntimeException;
14
use DummyGenerator\Definitions\Extension\InternetExtensionInterface;
15

16
class Internet implements
17
    InternetExtensionInterface,
18
    GeneratorAwareExtensionInterface,
19
    RandomizerAwareExtensionInterface,
20
    ReplacerAwareExtensionInterface
21
{
22
    use GeneratorAwareExtensionTrait;
23
    use RandomizerAwareExtensionTrait;
24
    use ReplacerAwareExtensionTrait;
25

26
    /** @var string[] */
27
    protected array $freeEmailDomain = ['gmail.com', 'yahoo.com', 'hotmail.com'];
28

29
    /** @var string[] */
30
    protected array $tld = ['com', 'com', 'com', 'com', 'com', 'com', 'biz', 'info', 'net', 'org'];
31

32
    /** @var string[] */
33
    protected array $userNameFormats = [
34
        '{{lastName}}.{{firstName}}',
35
        '{{firstName}}.{{lastName}}',
36
        '{{firstName}}##',
37
        '?{{lastName}}',
38
    ];
39

40
    /** @var string[] */
41
    protected array $emailFormats = [
42
        '{{userName}}@{{domainName}}',
43
        '{{userName}}@{{freeEmailDomain}}',
44
    ];
45

46
    /** @var string[] */
47
    protected array $urlFormats = [
48
        'http://www.{{domainName}}/',
49
        'http://{{domainName}}/',
50
        'http://www.{{domainName}}/{{slug}}',
51
        'http://www.{{domainName}}/{{slug}}',
52
        'https://www.{{domainName}}/{{slug}}',
53
        'http://www.{{domainName}}/{{slug}}.html',
54
        'http://{{domainName}}/{{slug}}',
55
        'http://{{domainName}}/{{slug}}',
56
        'http://{{domainName}}/{{slug}}.html',
57
        'https://{{domainName}}/{{slug}}.html',
58
    ];
59

60
    /**
61
     * @var array<int,array<string>>
62
     *
63
     * @see https://tools.ietf.org/html/rfc1918#section-3
64
     */
65
    protected array $localIpBlocks = [
66
        ['10.0.0.0', '10.255.255.255'],
67
        ['172.16.0.0', '172.31.255.255'],
68
        ['192.168.0.0', '192.168.255.255'],
69
    ];
70

71
    public function email(): string
72
    {
73
        $format = $this->randomizer->randomElement($this->emailFormats);
1✔
74

75
        return $this->generator->parse($format);
1✔
76
    }
77

78
    public function safeEmail(): string
79
    {
80
        return preg_replace('/\s/u', '', $this->userName() . '@' . $this->safeEmailDomain()) ?? '';
1✔
81
    }
82

83
    public function freeEmail(): string
84
    {
85
        return preg_replace('/\s/u', '', $this->userName() . '@' . $this->freeEmailDomain()) ?? '';
1✔
86
    }
87

88
    public function companyEmail(): string
89
    {
90
        return preg_replace('/\s/u', '', $this->userName() . '@' . $this->domainName()) ?? '';
2✔
91
    }
92

93
    public function freeEmailDomain(): string
94
    {
95
        return $this->randomizer->randomElement($this->freeEmailDomain);
2✔
96
    }
97

98
    public function safeEmailDomain(): string
99
    {
100
        $domains = [
2✔
101
            'example.com',
2✔
102
            'example.org',
2✔
103
            'example.net',
2✔
104
        ];
2✔
105

106
        return $this->randomizer->randomElement($domains);
2✔
107
    }
108

109
    public function userName(): string
110
    {
111
        $format = $this->randomizer->randomElement($this->userNameFormats);
6✔
112
        $username = $this->replacer->bothify($this->generator->parse($format));
6✔
113
        $username = $this->replacer->toLower($this->replacer->transliterate($username));
6✔
114

115
        // check if transliterate() didn't support the language and removed all letters
116
        if (trim($username, '._') === '') {
6✔
117
            throw new ExtensionRuntimeException('userName failed with the selected locale. Try a different locale or activate the "intl" PHP extension.');
×
118
        }
119

120
        // clean possible trailing dots from first/last names
121
        $username = str_replace('..', '.', $username);
6✔
122
        return rtrim($username, '.');
6✔
123
    }
124

125
    public function password(int $minLength = 6, int $maxLength = 20): string
126
    {
127
        $pattern = str_repeat('?', $this->randomizer->getInt($minLength, $maxLength));
1✔
128

129
        return $this->replacer->lexify($pattern, true);
1✔
130
    }
131

132
    public function domainName(): string
133
    {
134
        return $this->domainWord() . '.' . $this->tld();
4✔
135
    }
136

137
    public function domainWord(): string
138
    {
139
        // @phpstan-ignore-next-line
140
        $lastName = $this->generator->lastName();
5✔
141

142
        $lastName = $this->replacer->toLower($this->replacer->transliterate($lastName));
5✔
143

144
        // check if transliterate() didn't support the language and removed all letters
145
        if (trim($lastName, '._') === '') {
5✔
146
            throw new ExtensionRuntimeException('domainWord failed with the selected locale. Try a different locale or activate the "intl" PHP extension.');
×
147
        }
148

149
        // clean possible trailing dot from last name
150
        return rtrim($lastName, '.');
5✔
151
    }
152

153
    public function tld(): string
154
    {
155
        return $this->randomizer->randomElement($this->tld);
5✔
156
    }
157

158
    public function url(): string
159
    {
160
        $format = $this->randomizer->randomElement($this->urlFormats);
1✔
161

162
        return $this->generator->parse($format);
1✔
163
    }
164

165
    public function slug(int $nbWords = 6, bool $variableNbWords = true): string
166
    {
167
        if ($nbWords <= 0) {
2✔
168
            return '';
1✔
169
        }
170

171
        if ($variableNbWords) {
1✔
UNCOV
172
            $nbWords = (int) ($nbWords * $this->randomizer->getInt(60, 140) / 100) + 1;
×
173
        }
174

175
        // @phpstan-ignore-next-line
176
        $words = $this->generator->words($nbWords);
1✔
177

178
        return implode('-', $words);
1✔
179
    }
180

181
    public function ipv4(): string
182
    {
183
        return long2ip($this->randomizer->getBool() ? $this->randomizer->getInt(-2147483648, -2) : $this->randomizer->getInt(16777216, 2147483647));
1✔
184
    }
185

186
    public function ipv6(): string
187
    {
188
        $res = [];
1✔
189

190
        for ($i = 0; $i < 8; ++$i) {
1✔
191
            $res[] = dechex($this->randomizer->getInt(0, 65535));
1✔
192
        }
193

194
        return implode(':', $res);
1✔
195
    }
196

197
    public function localIpv4(): string
198
    {
199
        $ipBlock = $this->randomizer->randomElement($this->localIpBlocks);
1✔
200

201
        return long2ip($this->randomizer->getInt((int) ip2long($ipBlock[0]), (int) ip2long($ipBlock[1])));
1✔
202
    }
203

204
    public function macAddress(): string
205
    {
206
        $mac = [];
1✔
207

208
        for ($i = 0; $i < 6; ++$i) {
1✔
209
            $mac[] = sprintf('%02X', $this->randomizer->getInt(0, 0xff));
1✔
210
        }
211

212
        return implode(':', $mac);
1✔
213
    }
214
}
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