Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| AbstractQtiIdentifierSetter | |
0.00% |
0 / 15 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| __construct | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| set | |
0.00% |
0 / 12 |
|
0.00% |
0 / 1 |
12 | |||
| applyIdentifier | n/a |
0 / 0 |
n/a |
0 / 0 |
0 | |||||
| getResource | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getIdentifier | |
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) 2024 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\Translation\Service; |
| 24 | |
| 25 | use core_kernel_classes_Resource; |
| 26 | use InvalidArgumentException; |
| 27 | use Psr\Log\LoggerInterface; |
| 28 | use Throwable; |
| 29 | |
| 30 | abstract class AbstractQtiIdentifierSetter |
| 31 | { |
| 32 | public const OPTION_RESOURCE = 'resource'; |
| 33 | public const OPTION_IDENTIFIER = 'identifier'; |
| 34 | |
| 35 | private LoggerInterface $logger; |
| 36 | |
| 37 | public function __construct(LoggerInterface $logger) |
| 38 | { |
| 39 | $this->logger = $logger; |
| 40 | } |
| 41 | |
| 42 | public function set(array $options): void |
| 43 | { |
| 44 | try { |
| 45 | if (!isset($options[self::OPTION_RESOURCE], $options[self::OPTION_IDENTIFIER])) { |
| 46 | throw new InvalidArgumentException( |
| 47 | sprintf( |
| 48 | 'Options %s and %s are required to set QTI Identifier.', |
| 49 | self::OPTION_RESOURCE, |
| 50 | self::OPTION_IDENTIFIER |
| 51 | ) |
| 52 | ); |
| 53 | } |
| 54 | |
| 55 | $this->applyIdentifier($options); |
| 56 | } catch (Throwable $exception) { |
| 57 | $this->logger->error('An error occurred while setting QTI identifier: ' . $exception->getMessage()); |
| 58 | |
| 59 | throw $exception; |
| 60 | } |
| 61 | } |
| 62 | |
| 63 | abstract protected function applyIdentifier(array $options): void; |
| 64 | |
| 65 | protected function getResource(array $options): core_kernel_classes_Resource |
| 66 | { |
| 67 | return $options[self::OPTION_RESOURCE]; |
| 68 | } |
| 69 | |
| 70 | protected function getIdentifier(array $options): string |
| 71 | { |
| 72 | return $options[self::OPTION_IDENTIFIER]; |
| 73 | } |
| 74 | } |