1 | <?php |
||
9 | abstract class AbstractStep |
||
10 | { |
||
11 | /** |
||
12 | * @var callable |
||
13 | */ |
||
14 | public $function; |
||
15 | protected $name; |
||
16 | /** |
||
17 | * Indicates was this step performed or not |
||
18 | * |
||
19 | * @var bool |
||
20 | */ |
||
21 | protected $skipped; |
||
22 | |||
23 | 8 | public function __construct(callable $callable, string $name = null) |
|
29 | |||
30 | 6 | public function isSkipped() : bool |
|
34 | |||
35 | 3 | public function skip() : bool |
|
39 | |||
40 | 4 | public function functionName() : string |
|
45 | |||
46 | /** |
||
47 | * Transform all results into valid resut array form |
||
48 | * It could be Result object instance for nested steps |
||
49 | */ |
||
50 | 3 | protected function normalizeStepResult($result) : array |
|
51 | { |
||
52 | 3 | $stepResult = $result; |
|
53 | |||
54 | 3 | if (is_a($result, Result::class)) { |
|
55 | 1 | if ($result->isSuccess()) { |
|
56 | $stepResult = [ |
||
57 | 1 | 'type' => RESPONSE_TYPE_OK, |
|
58 | 1 | 'appendParams' => $result->params() |
|
59 | ]; |
||
60 | } else { |
||
61 | $stepResult = [ |
||
62 | 'type' => RESPONSE_TYPE_ERROR, |
||
63 | 'appendError' => $result->errors() |
||
64 | ]; |
||
65 | } |
||
66 | } |
||
67 | |||
68 | 3 | return $stepResult; |
|
69 | } |
||
70 | |||
71 | abstract public function __invoke(&$params, string $track); |
||
72 | } |
||
73 |
When comparing two booleans, it is generally considered safer to use the strict comparison operator.