Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions src/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -187,16 +187,14 @@ function task(string $name, callable|array|null $body = null): Task
{
$deployer = Deployer::get();

if (empty($body)) {
if ($body === null) {
return $deployer->tasks->get($name);
}

if (is_callable($body)) {
$task = new Task($name, $body);
} elseif (is_array($body)) {
$task = new GroupTask($name, $body);
} else {
throw new \InvalidArgumentException('Task body should be a function or an array.');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But we still need to do this check, no?

Copy link
Contributor Author

@refsz refsz Jan 28, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think so.

If $body is null and task does not exist then the Collection will throw not found. If $body is not of type callable|array|null then a fatal error should be thrown.

We also could transform the if to one line.
$task = is_callable($body) ? new Task($name, $body) : new GroupTask($name, $body)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

$task = is_callable($body) ? new Task($name, $body) : new GroupTask($name, $body)

Nope. Only arrays should be groups.

Copy link
Contributor Author

@refsz refsz Jan 29, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know and the only possbile type for the else is an array.
If the array is a callable then is_callable will be true and a Task will be created.

But maybe I'm overlooking something.

}

if ($deployer->tasks->has($name)) {
Expand Down