diff --git a/src/RobotLoader/RobotLoader.php b/src/RobotLoader/RobotLoader.php index 27a3b29..19423d0 100644 --- a/src/RobotLoader/RobotLoader.php +++ b/src/RobotLoader/RobotLoader.php @@ -122,7 +122,7 @@ public function tryLoad(string $type): void */ public function addDirectory(...$paths): self { - if (is_array($paths[0])) { + if (is_array($paths[0] ?? null)) { trigger_error(__METHOD__ . '() use variadics ...$paths to add an array of paths.', E_USER_WARNING); $paths = $paths[0]; } @@ -144,7 +144,7 @@ public function reportParseErrors(bool $on = true): self */ public function excludeDirectory(...$paths): self { - if (is_array($paths[0])) { + if (is_array($paths[0] ?? null)) { trigger_error(__METHOD__ . '() use variadics ...$paths to add an array of paths.', E_USER_WARNING); $paths = $paths[0]; } diff --git a/tests/Loaders/RobotLoader.emptyArrayVariadicArgument.phpt b/tests/Loaders/RobotLoader.emptyArrayVariadicArgument.phpt new file mode 100644 index 0000000..692d8e6 --- /dev/null +++ b/tests/Loaders/RobotLoader.emptyArrayVariadicArgument.phpt @@ -0,0 +1,28 @@ +setTempDirectory(TEMP_DIR); + +Assert::noError( + function () use ($loader) { + $loader->addDirectory(...[]); + } +); + +Assert::noError( + function () use ($loader) { + $loader->excludeDirectory(...[]); + } +);