Skip to content

Commit 6658d9c

Browse files
authoredJun 25, 2021
Fix FakeIpPlugin (#316)
1 parent 186cc1a commit 6658d9c

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed
 

‎Plugin/FakeIpPlugin.php

+10-14
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626
class FakeIpPlugin implements Plugin
2727
{
2828
/**
29-
* @var string
29+
* @var string|null
3030
*/
3131
private $needle;
3232

@@ -35,21 +35,15 @@ class FakeIpPlugin implements Plugin
3535
*/
3636
private $replacement;
3737

38-
/**
39-
* @var bool
40-
*/
41-
private $useFaker;
42-
4338
/**
4439
* @var Generator|null
4540
*/
4641
private $faker;
4742

48-
public function __construct(string $needle, string $replacement = null, bool $useFaker = false)
43+
public function __construct(?string $needle, string $replacement = null, bool $useFaker = false)
4944
{
5045
$this->needle = $needle;
5146
$this->replacement = $replacement;
52-
$this->useFaker = $useFaker;
5347

5448
if ($useFaker) {
5549
$this->faker = new Generator();
@@ -69,14 +63,16 @@ public function handleQuery(Query $query, callable $next, callable $first)
6963
$replacement = $this->replacement;
7064

7165
if (null !== $this->faker) {
72-
$replacement = $this->faker->ipv4;
66+
$replacement = $this->faker->ipv4();
7367
}
7468

75-
$text = str_replace($this->needle, $replacement, $query->getText(), $count);
76-
if ($count > 0) {
77-
$query = $query->withText($text);
78-
}
79-
if (null === $this->needle || '' === $this->needle) {
69+
if (null !== $this->needle && '' !== $this->needle) {
70+
$text = str_replace($this->needle, $replacement, $query->getText(), $count);
71+
72+
if ($count > 0) {
73+
$query = $query->withText($text);
74+
}
75+
} else {
8076
$query = $query->withText($replacement);
8177
}
8278

‎Tests/Plugin/FakeIpPluginTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function testSimpleHandleQuery()
3535

3636
/**
3737
* @testWith [null]
38-
* ['']
38+
* [""]
3939
*/
4040
public function testEmptyLocalIpQuery(?string $localIp)
4141
{

‎composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
"require-dev": {
2323
"doctrine/cache": "~1.3",
2424
"doctrine/orm": "~2.8",
25-
"fakerphp/faker": "^1.9",
25+
"fakerphp/faker": "^1.14",
2626
"friendsofphp/php-cs-fixer": "^3.0",
2727
"geocoder-php/algolia-places-provider": "^0.3",
2828
"geocoder-php/arcgis-online-provider": "^4.3",

‎phpstan.neon.dist

+3
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,6 @@ parameters:
1212
-
1313
path: %currentWorkingDirectory%/ProviderFactory/GeoipFactory.php
1414
message: '#Geocoder\\Provider\\Geoip\\Geoip not found#'
15+
-
16+
path: %currentWorkingDirectory%/Plugin/FakeIpPlugin.php
17+
message: '#Call to an undefined method Faker\\Generator::ipv4\(\)#'

0 commit comments

Comments
 (0)