Total Complexity | 8 |
Total Lines | 103 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | <?php |
||
7 | abstract class Task |
||
8 | { |
||
9 | /** |
||
10 | * Pipe handlers results for current task. |
||
11 | * |
||
12 | * @var array |
||
13 | */ |
||
14 | protected $results = []; |
||
15 | |||
16 | /** |
||
17 | * Method name to be executed on each pipe. |
||
18 | * |
||
19 | * @var string |
||
20 | */ |
||
21 | protected $pipeMethod = 'process'; |
||
22 | |||
23 | /** |
||
24 | * Get the pipes list. |
||
25 | * |
||
26 | * @return array |
||
27 | */ |
||
28 | abstract public function pipes(); |
||
29 | |||
30 | /** |
||
31 | * Completed task handler. |
||
32 | * |
||
33 | * @return mixed |
||
34 | */ |
||
35 | public function completed() |
||
36 | { |
||
37 | return true; |
||
38 | } |
||
39 | |||
40 | /** |
||
41 | * Failed task handler. |
||
42 | * |
||
43 | * @param PipelineTaskFailedException $exception |
||
44 | * |
||
45 | * @return mixed |
||
46 | */ |
||
47 | public function failed(PipelineTaskFailedException $exception) |
||
48 | { |
||
49 | return false; |
||
50 | } |
||
51 | |||
52 | /** |
||
53 | * Get the pipe method. |
||
54 | * |
||
55 | * @return string |
||
56 | */ |
||
57 | public function pipeMethod() |
||
60 | } |
||
61 | |||
62 | /** |
||
63 | * Store pipe result. |
||
64 | * |
||
65 | * @param string $name |
||
66 | * @param mixed $result |
||
67 | * |
||
68 | * @return $this |
||
69 | */ |
||
70 | public function setPipeResult(string $name, $result) |
||
75 | } |
||
76 | |||
77 | /** |
||
78 | * Determines if result for the given pipe already exists. |
||
79 | * |
||
80 | * @param string $name |
||
81 | * |
||
82 | * @return bool |
||
83 | */ |
||
84 | public function hasPipeResult(string $name) |
||
87 | } |
||
88 | |||
89 | /** |
||
90 | * Get pipe result. |
||
91 | * |
||
92 | * @param string $name |
||
93 | * @param mixed $default = null |
||
94 | * |
||
95 | * @return mixed |
||
96 | */ |
||
97 | public function getPipeResult(string $name, $default = null) |
||
98 | { |
||
99 | return $this->hasPipeResult($name) ? $this->results[$name] : $default; |
||
100 | } |
||
101 | |||
102 | /** |
||
103 | * Get all available results. |
||
104 | * |
||
105 | * @return array |
||
106 | */ |
||
107 | public function results() |
||
110 | } |
||
111 | } |
||
112 |