Updated to Drupal 8.5. Core Media not yet in use.
[yaffs-website] / vendor / consolidation / robo / src / Collection / Element.php
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 array
24      */
25     protected $before = [];
26
27     /**
28      * @var array
29      */
30     protected $after = [];
31
32     public function __construct(TaskInterface $task)
33     {
34         $this->task = $task;
35     }
36
37     /**
38      * @param mixed $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 mixed $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 array
65      */
66     public function getBefore()
67     {
68         return $this->before;
69     }
70
71     /**
72      * @return array
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 array
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 }