diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index 93513469a8..67c2a8417f 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -633,6 +633,11 @@ parameters: count: 1 path: src/Faker/Provider/Base.php + - + message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\\\)\\: string, array\\{class\\-string\\, 'randomDigit'\\} given\\.$#" + count: 1 + path: src/Faker/Provider/Base.php + - message: "#^Parameter \\$validator of method Faker\\\\Provider\\\\Base\\:\\:valid\\(\\) has invalid type Faker\\\\Provider\\\\Closure\\.$#" count: 1 @@ -733,6 +738,11 @@ parameters: count: 2 path: src/Faker/Provider/cs_CZ/Person.php + - + message: "#^Parameter \\#2 \\$callback of function preg_replace_callback expects callable\\(array\\\\)\\: string, array\\{class\\-string\\, 'randomDigit'\\} given\\.$#" + count: 1 + path: src/Faker/Provider/en_CA/Address.php + - message: "#^Unsafe call to private method Faker\\\\Provider\\\\en_GB\\\\Company\\:\\:generateBranchTraderVatNumber\\(\\) through static\\:\\:\\.$#" count: 1 diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 1c521356cc..37222a4ffe 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,7 +13,7 @@ - + diff --git a/psalm.baseline.xml b/psalm.baseline.xml index 2a60af42df..7c3b4e8717 100644 --- a/psalm.baseline.xml +++ b/psalm.baseline.xml @@ -139,6 +139,9 @@ + + [static::class, 'randomDigit'] + $array diff --git a/src/Faker/Provider/Base.php b/src/Faker/Provider/Base.php index 4ff4492a4e..e3713ce0e6 100644 --- a/src/Faker/Provider/Base.php +++ b/src/Faker/Provider/Base.php @@ -363,7 +363,7 @@ public static function shuffleString($string = '', $encoding = 'UTF-8') return implode('', static::shuffleArray($array)); } - private static function replaceWildcard($string, $wildcard = '#', $callback = 'static::randomDigit') + private static function replaceWildcard($string, $wildcard, $callback) { if (($pos = strpos($string, $wildcard)) === false) { return $string; @@ -415,7 +415,7 @@ public static function numerify($string = '###') $string[$toReplace[$i]] = $numbers[$i]; } } - $string = self::replaceWildcard($string, '%', 'static::randomDigitNotNull'); + $string = self::replaceWildcard($string, '%', [static::class, 'randomDigitNotNull']); return $string; } @@ -429,7 +429,7 @@ public static function numerify($string = '###') */ public static function lexify($string = '????') { - return self::replaceWildcard($string, '?', 'static::randomLetter'); + return self::replaceWildcard($string, '?', [static::class, 'randomLetter']); } /** @@ -460,7 +460,7 @@ public static function bothify($string = '## ??') */ public static function asciify($string = '****') { - return preg_replace_callback('/\*/u', 'static::randomAscii', $string); + return preg_replace_callback('/\*/u', [static::class, 'randomAscii'], $string); } /** @@ -532,8 +532,8 @@ public static function regexify($regex = '') return str_replace('.', '\.', $randomElement); }, $regex); // replace \d with number and \w with letter and . with ascii - $regex = preg_replace_callback('/\\\w/', 'static::randomLetter', $regex); - $regex = preg_replace_callback('/\\\d/', 'static::randomDigit', $regex); + $regex = preg_replace_callback('/\\\w/', [static::class, 'randomLetter'], $regex); + $regex = preg_replace_callback('/\\\d/', [static::class, 'randomDigit'], $regex); //replace . with ascii except backslash $regex = preg_replace_callback('/(?