TaskList::add()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
namespace Genkgo\Srvcleaner;
3
4
use ArrayIterator;
5
use Closure;
6
use Countable;
7
use IteratorAggregate;
8
9
/**
10
 * Class TaskList
11
 * @package Genkgo\Srvcleaner
12
 */
13
class TaskList implements Countable, IteratorAggregate
14
{
15
    /**
16
     * @var array
17
     */
18
    private $tasks = [];
19
20
    /**
21
     * @param $name
22
     * @param TaskInterface $task
23
     */
24
    public function add($name, TaskInterface $task)
25
    {
26
        $this->tasks[$name] = $task;
27
    }
28
29
    /**
30
     * @param Closure $callback
31
     */
32
    public function each(Closure $callback)
33
    {
34
        foreach ($this->tasks as $name => $task) {
35
            $callback($task, $name);
36
        }
37
    }
38
39
    /**
40
     * @return int
41
     */
42
    public function count()
43
    {
44
        return count($this->tasks);
45
    }
46
47
    /**
48
     * @return ArrayIterator
49
     */
50
    public function getIterator()
51
    {
52
        return new ArrayIterator($this->tasks);
53
    }
54
}
55