From 8a88937349ee1ef7c568d483fc294e33f5e173ac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Josef=20S=C3=A1bl?= Date: Thu, 5 Sep 2019 16:46:50 +0200 Subject: [PATCH] RobotLoader: Fixed the empty variadic array in addDirectory() [Closes #17] --- src/RobotLoader/RobotLoader.php | 4 +-- ...obotLoader.emptyArrayVariadicArgument.phpt | 28 +++++++++++++++++++ 2 files changed, 30 insertions(+), 2 deletions(-) create mode 100644 tests/Loaders/RobotLoader.emptyArrayVariadicArgument.phpt 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(...[]); + } +);