AbstractTask::runAfter()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 5

Duplication

Lines 0
Ratio 0 %
Metric Value
dl 0
loc 10
rs 9.2
cc 4
eloc 5
nc 3
nop 1
1
<?php
2
/**
3
 * Junty
4
 *
5
 * @author Gabriel Jacinto aka. GabrielJMJ <[email protected]>
6
 * @license MIT License
7
 */
8
 
9
namespace Junty\TaskRunner\Task;
10
11
use Junty\TaskRunner\Task\TaskInterface;
12
13
abstract class AbstractTask implements TaskInterface
14
{
15
    private $next = [];
16
17
    public function __invoke(array $params = [])
18
    {
19
        $cb = $this->getCallback();
20
        
21
        return $cb(...$params);
22
    }
23
24
    /**
25
     * Indicates what task must be runned after this one
26
     *
27
     * @param string|array $task
28
     *
29
     * @return self
30
     */
31
    public function runAfter($task) : self
32
    {
33
        if (!is_string($task) && !is_array($task)) {
34
            throw new \InvalidArgumentException('Pass an array with the tasks or a single one.');
35
        }
36
37
        is_string($task) ? $this->next[] = $task : $this->next = array_merge($this->next, $task);
38
39
        return $this;
40
    }
41
42
    /**
43
     * Checks if after this task, another one will be executed
44
     *
45
     * @return boolean
46
     */
47
    public function hasNext() : bool
48
    {
49
        return count($this->next);
50
    }
51
}