Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
| set_variable_node | |
100.00% |
8 / 8 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
| type | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| params | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| branches | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| execute | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
3 | |||
| 1 | <?php |
| 2 | // This file is part of Moodle - https://moodle.org/ |
| 3 | // |
| 4 | // Moodle is free software: you can redistribute it and/or modify |
| 5 | // it under the terms of the GNU General Public License as published by |
| 6 | // the Free Software Foundation, either version 3 of the License, or |
| 7 | // (at your option) any later version. |
| 8 | // |
| 9 | // Moodle is distributed in the hope that it will be useful, |
| 10 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 | // GNU General Public License for more details. |
| 13 | // |
| 14 | // You should have received a copy of the GNU General Public License |
| 15 | // along with Moodle. If not, see <https://www.gnu.org/licenses/>. |
| 16 | |
| 17 | declare(strict_types=1); |
| 18 | |
| 19 | namespace tool_autoflow\local\engine\nodes; |
| 20 | |
| 21 | use tool_autoflow\local\engine\node_failed; |
| 22 | use tool_autoflow\local\engine\node_result; |
| 23 | use tool_autoflow\local\engine\node_type; |
| 24 | use tool_autoflow\local\engine\param; |
| 25 | |
| 26 | /** |
| 27 | * Stores a value under a name, readable later as {{vars.<name>}}. |
| 28 | * |
| 29 | * @package tool_autoflow |
| 30 | * @copyright 2026 DevLMS <contact@devlms.com> |
| 31 | * @license https://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later |
| 32 | */ |
| 33 | final class set_variable_node implements node_type { |
| 34 | /** |
| 35 | * Type name. |
| 36 | * |
| 37 | * @return string |
| 38 | */ |
| 39 | public function type(): string { |
| 40 | return 'logic.set'; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Parameters. |
| 45 | * |
| 46 | * @return param[] |
| 47 | */ |
| 48 | public function params(): array { |
| 49 | return [new param('name', 'text', true), new param('value', 'text', false)]; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Branches. |
| 54 | * |
| 55 | * @return string[] |
| 56 | */ |
| 57 | public function branches(): array { |
| 58 | return []; |
| 59 | } |
| 60 | |
| 61 | /** |
| 62 | * Set the variable. |
| 63 | * |
| 64 | * @param array $params name, value |
| 65 | * @param array $context |
| 66 | * @return node_result |
| 67 | */ |
| 68 | public function execute(array $params, array $context): node_result { |
| 69 | $name = $params['name'] ?? ''; |
| 70 | if (!is_string($name) || $name === '') { |
| 71 | throw new node_failed('Set variable needs a name.'); |
| 72 | } |
| 73 | $value = $params['value'] ?? null; |
| 74 | return new node_result(['value' => $value], null, [$name => $value]); |
| 75 | } |
| 76 | } |