Skip to content

Commit 97b4f44

Browse files
josefsabldg
authored andcommitted
RobotLoader: Fixed the empty variadic array in addDirectory() [Closes #17]
1 parent 9ae6fc2 commit 97b4f44

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/RobotLoader/RobotLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ public function tryLoad(string $type): void
122122
*/
123123
public function addDirectory(...$paths): self
124124
{
125-
if (is_array($paths[0])) {
125+
if (is_array($paths[0] ?? null)) {
126126
trigger_error(__METHOD__ . '() use variadics ...$paths to add an array of paths.', E_USER_WARNING);
127127
$paths = $paths[0];
128128
}
@@ -144,7 +144,7 @@ public function reportParseErrors(bool $on = true): self
144144
*/
145145
public function excludeDirectory(...$paths): self
146146
{
147-
if (is_array($paths[0])) {
147+
if (is_array($paths[0] ?? null)) {
148148
trigger_error(__METHOD__ . '() use variadics ...$paths to add an array of paths.', E_USER_WARNING);
149149
$paths = $paths[0];
150150
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
/**
4+
* Test: Nette\Loaders\RobotLoader bug # 17 POC.
5+
*/
6+
7+
declare(strict_types=1);
8+
9+
use Nette\Loaders\RobotLoader;
10+
use Tester\Assert;
11+
12+
13+
require __DIR__ . '/../bootstrap.php';
14+
15+
$loader = new RobotLoader;
16+
$loader->setTempDirectory(TEMP_DIR);
17+
18+
Assert::noError(
19+
function () use ($loader) {
20+
$loader->addDirectory(...[]);
21+
}
22+
);
23+
24+
Assert::noError(
25+
function () use ($loader) {
26+
$loader->excludeDirectory(...[]);
27+
}
28+
);

0 commit comments

Comments
 (0)