Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
60.00% |
12 / 20 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ResourceRepositoryContext | |
60.00% |
12 / 20 |
|
50.00% |
1 / 2 |
12.10 | |
0.00% |
0 / 1 |
| getSupportedParameters | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| validateParameter | |
38.46% |
5 / 13 |
|
0.00% |
0 / 1 |
18.42 | |||
| 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) 2021 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\generis\model\resource\Context; |
| 24 | |
| 25 | use InvalidArgumentException; |
| 26 | use core_kernel_classes_Class; |
| 27 | use core_kernel_classes_Resource; |
| 28 | use oat\generis\model\Context\AbstractContext; |
| 29 | |
| 30 | class ResourceRepositoryContext extends AbstractContext |
| 31 | { |
| 32 | public const PARAM_RESOURCE = 'resource'; |
| 33 | public const PARAM_CLASS = 'class'; |
| 34 | public const PARAM_DELETE_REFERENCE = 'deleteReference'; |
| 35 | public const PARAM_SELECTED_CLASS = 'selectedClass'; |
| 36 | public const PARAM_PARENT_CLASS = 'parentClass'; |
| 37 | |
| 38 | protected function getSupportedParameters(): array |
| 39 | { |
| 40 | return [ |
| 41 | self::PARAM_RESOURCE, |
| 42 | self::PARAM_CLASS, |
| 43 | self::PARAM_DELETE_REFERENCE, |
| 44 | self::PARAM_SELECTED_CLASS, |
| 45 | self::PARAM_PARENT_CLASS, |
| 46 | ]; |
| 47 | } |
| 48 | |
| 49 | protected function validateParameter(string $parameter, $parameterValue): void |
| 50 | { |
| 51 | if ($parameter === self::PARAM_RESOURCE && $parameterValue instanceof core_kernel_classes_Resource) { |
| 52 | return; |
| 53 | } |
| 54 | |
| 55 | if ( |
| 56 | in_array($parameter, [self::PARAM_CLASS, self::PARAM_SELECTED_CLASS, self::PARAM_PARENT_CLASS], true) |
| 57 | && $parameterValue instanceof core_kernel_classes_Class |
| 58 | ) { |
| 59 | return; |
| 60 | } |
| 61 | |
| 62 | if ($parameter === self::PARAM_DELETE_REFERENCE && is_bool($parameterValue)) { |
| 63 | return; |
| 64 | } |
| 65 | |
| 66 | throw new InvalidArgumentException( |
| 67 | sprintf( |
| 68 | 'Context parameter %s is not valid.', |
| 69 | $parameter |
| 70 | ) |
| 71 | ); |
| 72 | } |
| 73 | } |