Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
CRAP | |
0.00% |
0 / 1 |
| AbstractQtiStateManipulationTask | |
0.00% |
0 / 12 |
|
0.00% |
0 / 3 |
20 | |
0.00% |
0 / 1 |
| __invoke | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
| manipulateState | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| validateParameters | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
6 | |||
| getStateMigrationService | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License |
| 6 | * as published by the Free Software Foundation; under version 2 |
| 7 | * of the License (non-upgradable). |
| 8 | * |
| 9 | * This program 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 this program; if not, write to the Free Software |
| 16 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 17 | * |
| 18 | * Copyright (c) 2022 (original work) Open Assessment Technologies SA; |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\taoQtiTest\models\classes\tasks\QtiStateOffload; |
| 24 | |
| 25 | use InvalidArgumentException; |
| 26 | use oat\oatbox\extension\AbstractAction; |
| 27 | use oat\oatbox\reporting\Report; |
| 28 | use oat\oatbox\service\exception\InvalidServiceManagerException; |
| 29 | use oat\tao\model\state\StateMigration; |
| 30 | use oat\tao\model\taskQueue\Task\QueueAssociableInterface; |
| 31 | use oat\tao\model\taskQueue\Task\TaskAwareInterface; |
| 32 | use oat\tao\model\taskQueue\Task\TaskAwareTrait; |
| 33 | use Psr\Container\ContainerExceptionInterface; |
| 34 | use Psr\Container\NotFoundExceptionInterface; |
| 35 | |
| 36 | abstract class AbstractQtiStateManipulationTask extends AbstractAction implements TaskAwareInterface |
| 37 | { |
| 38 | use TaskAwareTrait; |
| 39 | |
| 40 | public const PARAM_USER_ID_KEY = 'userId'; |
| 41 | public const PARAM_CALL_ID_KEY = 'callId'; |
| 42 | public const PARAM_STATE_LABEL_KEY = 'stateLabel'; |
| 43 | |
| 44 | public function __invoke($params): Report |
| 45 | { |
| 46 | [$userId, $callId, $stateLabel] = $this->validateParameters($params); |
| 47 | |
| 48 | return $this->manipulateState($userId, $callId, $stateLabel); |
| 49 | } |
| 50 | |
| 51 | abstract protected function manipulateState(string $userId, string $callId, string $stateLabel): Report; |
| 52 | |
| 53 | /** |
| 54 | * @param $params |
| 55 | * @return array [$userId, $callId, $stateLabel] |
| 56 | */ |
| 57 | private function validateParameters($params): array |
| 58 | { |
| 59 | if ( |
| 60 | !isset( |
| 61 | $params[self::PARAM_USER_ID_KEY], |
| 62 | $params[self::PARAM_CALL_ID_KEY], |
| 63 | $params[self::PARAM_STATE_LABEL_KEY] |
| 64 | ) |
| 65 | ) { |
| 66 | throw new InvalidArgumentException('[%s] Invalid parameter set was provided', self::class); |
| 67 | } |
| 68 | |
| 69 | return [ |
| 70 | $params[self::PARAM_USER_ID_KEY], |
| 71 | $params[self::PARAM_CALL_ID_KEY], |
| 72 | $params[self::PARAM_STATE_LABEL_KEY] |
| 73 | ]; |
| 74 | } |
| 75 | |
| 76 | |
| 77 | /** |
| 78 | * @throws ContainerExceptionInterface |
| 79 | * @throws NotFoundExceptionInterface |
| 80 | * @throws InvalidServiceManagerException |
| 81 | */ |
| 82 | protected function getStateMigrationService(): StateMigration |
| 83 | { |
| 84 | return $this->getServiceLocator()->get(StateMigration::SERVICE_ID); |
| 85 | } |
| 86 | } |