Skip to content

Commit 9f50cbf

Browse files
author
Bastian Schwarz
committed
Return early when regex is empty
1 parent c0896b4 commit 9f50cbf

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

src/taskMatcher/ByRegexTaskName.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@ final class ByRegexTaskName implements iTaskMatcher {
2727
public function __construct(public string $regex) {}
2828

2929
public function matches(Task $task) : bool {
30-
return preg_match($this->regex, $task->getName()) === 1;
30+
return $this->regex !== '' && preg_match($this->regex, $task->getName()) === 1;
3131
}
32-
}
32+
}

test/taskMatcher/ByRegexTaskNameTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,15 @@ public function testMatches() : void {
4949
self::assertFalse($this->sut->matches($task4));
5050
}
5151

52+
public function testMatches_canReturnFalse_whenRegexIsEmpty() : void {
53+
$this->sut->regex = '';
54+
55+
$task1 = $this->createMock(Task::class);
56+
$task1->expects(self::never())->method('getName');
57+
58+
self::assertFalse($this->sut->matches($task1));
59+
}
60+
5261
public function test__construct() : void {
5362
$regex = 'some regex';
5463

0 commit comments

Comments
 (0)