| Total Complexity | 4 |
| Total Lines | 44 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 5 | class LambdaStep implements NamedStep |
||
| 6 | { |
||
| 7 | /** |
||
| 8 | * @var callable |
||
| 9 | */ |
||
| 10 | private $executeHandler; |
||
| 11 | |||
| 12 | /** |
||
| 13 | * @var callable |
||
| 14 | */ |
||
| 15 | private $compensateHandler; |
||
| 16 | |||
| 17 | /** |
||
| 18 | * @var string |
||
| 19 | */ |
||
| 20 | private $name; |
||
| 21 | |||
| 22 | public function __construct(callable $execute, callable $compensate = null, string $name = null) |
||
| 23 | { |
||
| 24 | $this->executeHandler = $execute; |
||
| 25 | $this->compensateHandler = $compensate ?? function () { |
||
| 26 | }; |
||
| 27 | |||
| 28 | $this->name = $name ?? "anonymous lambda"; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function execute($state) |
||
| 32 | { |
||
| 33 | $function = $this->executeHandler; |
||
| 34 | return $function($state); |
||
| 35 | } |
||
| 36 | |||
| 37 | public function compensate($state): void |
||
| 41 | } |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @return string the public name of this step |
||
| 45 | */ |
||
| 46 | public function stepName(): string |
||
| 51 |