2626class 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
0 commit comments