Element   A
last analyzed

Complexity

Total Complexity 13

Size/Duplication

Total Lines 102
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 13
lcom 1
cbo 1
dl 0
loc 102
rs 10
c 0
b 0
f 0

8 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A before() 0 8 2
A after() 0 8 2
A getBefore() 0 4 1
A getAfter() 0 4 1
A getTask() 0 4 1
A getTaskList() 0 4 1
A progressIndicatorSteps() 0 18 4
1
<?php
2
3
namespace Robo\Collection;
4
5
use Robo\Contract\TaskInterface;
6
use Robo\Contract\WrappedTaskInterface;
7
use Robo\Contract\ProgressIndicatorAwareInterface;
8
9
/**
10
 * One element in a collection.  Each element consists of a task
11
 * all of its before tasks, and all of its after tasks.
12
 *
13
 * This class is internal to Collection; it should not be used directly.
14
 */
15
class Element
16
{
17
    /**
18
     * @var \Robo\Contract\TaskInterface
19
     */
20
    protected $task;
21
22
    /**
23
     * @var \Robo\Contract\TaskInterface[]|callable[]
24
     */
25
    protected $before = [];
26
27
    /**
28
     * @var \Robo\Contract\TaskInterface[]|callable[]
29
     */
30
    protected $after = [];
31
32
    public function __construct(TaskInterface $task)
33
    {
34
        $this->task = $task;
35
    }
36
37
    /**
38
     * @param \Robo\Contract\TaskInterface|callable $before
39
     * @param string $name
40
     */
41
    public function before($before, $name)
42
    {
43
        if ($name) {
44
            $this->before[$name] = $before;
45
        } else {
46
            $this->before[] = $before;
47
        }
48
    }
49
50
    /**
51
     * @param \Robo\Contract\TaskInterface|callable $after
52
     * @param string $name
53
     */
54
    public function after($after, $name)
55
    {
56
        if ($name) {
57
            $this->after[$name] = $after;
58
        } else {
59
            $this->after[] = $after;
60
        }
61
    }
62
63
    /**
64
     * @return \Robo\Contract\TaskInterface[]|callable[]
65
     */
66
    public function getBefore()
67
    {
68
        return $this->before;
69
    }
70
71
    /**
72
     * @return \Robo\Contract\TaskInterface[]|callable[]
73
     */
74
    public function getAfter()
75
    {
76
        return $this->after;
77
    }
78
79
    /**
80
     * @return \Robo\Contract\TaskInterface
81
     */
82
    public function getTask()
83
    {
84
        return $this->task;
85
    }
86
87
    /**
88
     * @return \Robo\Contract\TaskInterface[]|callable[]
89
     */
90
    public function getTaskList()
91
    {
92
        return array_merge($this->getBefore(), [$this->getTask()], $this->getAfter());
93
    }
94
95
    /**
96
     * @return int
97
     */
98
    public function progressIndicatorSteps()
99
    {
100
        $steps = 0;
101
        foreach ($this->getTaskList() as $task) {
102
            if ($task instanceof WrappedTaskInterface) {
103
                $task = $task->original();
104
            }
105
            // If the task is a ProgressIndicatorAwareInterface, then it
106
            // will advance the progress indicator a number of times.
107
            if ($task instanceof ProgressIndicatorAwareInterface) {
108
                $steps += $task->progressIndicatorSteps();
109
            }
110
            // We also advance the progress indicator once regardless
111
            // of whether it is progress-indicator aware or not.
112
            $steps++;
113
        }
114
        return $steps;
115
    }
116
}
117