Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
70.00% |
14 / 20 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| ElementFactoryContext | |
70.00% |
14 / 20 |
|
50.00% |
1 / 2 |
11.19 | |
0.00% |
0 / 1 |
| getSupportedParameters | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 | |||
| validateParameter | |
57.14% |
8 / 14 |
|
0.00% |
0 / 1 |
13.04 | |||
| 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\tao\helpers\form\Factory; |
| 24 | |
| 25 | use core_kernel_classes_Property; |
| 26 | use InvalidArgumentException; |
| 27 | use oat\tao\model\Context\AbstractContext; |
| 28 | |
| 29 | class ElementFactoryContext extends AbstractContext |
| 30 | { |
| 31 | public const PARAM_RANGE = 'range'; |
| 32 | public const PARAM_INDEX = 'index'; |
| 33 | public const PARAM_PROPERTY = 'property'; |
| 34 | public const PARAM_DATA = 'data'; |
| 35 | |
| 36 | protected function getSupportedParameters(): array |
| 37 | { |
| 38 | return [ |
| 39 | self::PARAM_RANGE, |
| 40 | self::PARAM_INDEX, |
| 41 | self::PARAM_PROPERTY, |
| 42 | self::PARAM_DATA, |
| 43 | ]; |
| 44 | } |
| 45 | |
| 46 | protected function validateParameter(string $parameter, $parameterValue): void |
| 47 | { |
| 48 | if ($parameter === self::PARAM_PROPERTY && $parameterValue instanceof core_kernel_classes_Property) { |
| 49 | return; |
| 50 | } |
| 51 | |
| 52 | if ($parameter === self::PARAM_INDEX && is_int($parameterValue)) { |
| 53 | return; |
| 54 | } |
| 55 | |
| 56 | if ($parameter === self::PARAM_DATA && is_array($parameterValue)) { |
| 57 | return; |
| 58 | } |
| 59 | |
| 60 | if ($parameter === self::PARAM_RANGE) { |
| 61 | return; |
| 62 | } |
| 63 | |
| 64 | throw new InvalidArgumentException( |
| 65 | sprintf( |
| 66 | 'Invalid argument for %s', |
| 67 | $parameter |
| 68 | ) |
| 69 | ); |
| 70 | } |
| 71 | } |