From 377a4674333937e4134998310dadb30972fabfcc Mon Sep 17 00:00:00 2001 From: jrfnl Date: Fri, 5 Mar 2021 02:22:24 +0100 Subject: [PATCH] PHP 8.1: fix deprecation notice [2] The `Fixer::generateDiff()` method calls the `shell_exec()` method to retrieve the `diff` between two files. In the unit tests, this is used to compare the expected content in a `.fixed` file with the generate fixed file contents. If the expected content matches the generated content, the diff command will produce no output and `shell_exec()` will return `null`. Ref: https://www.php.net/manual/en/function.shell-exec.php This result is subsequently passed to `explode()` as the second parameter, but `explode()` only excepts strings as the second parameter. Ref: https://www.php.net/manual/en/function.explode As of PHP 8.1, this will generate a deprecation notice `explode(): Passing null to parameter #2 ($string) of type string is deprecated`. Discovered while testing an external standard against PHPCS `master` on PHP 8.1. Fixed now. --- src/Fixer.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/Fixer.php b/src/Fixer.php index 1e1f2561d4..ed6adb15dc 100644 --- a/src/Fixer.php +++ b/src/Fixer.php @@ -255,6 +255,10 @@ public function generateDiff($filePath=null, $colors=true) unlink($tempName); } + if ($diff === null) { + return ''; + } + if ($colors === false) { return $diff; }