AbstractTask   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0
Metric Value
wmc 6
lcom 1
cbo 0
dl 0
loc 39
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 6 1
A runAfter() 0 10 4
A hasNext() 0 4 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
}