Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
64.71% |
11 / 17 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| PropertySpecificationContext | |
64.71% |
11 / 17 |
|
50.00% |
1 / 2 |
10.81 | |
0.00% |
0 / 1 |
| getSupportedParameters | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| validateParameter | |
50.00% |
6 / 12 |
|
0.00% |
0 / 1 |
13.12 | |||
| 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\model\Lists\Business\Specification; |
| 24 | |
| 25 | use core_kernel_classes_Property; |
| 26 | use InvalidArgumentException; |
| 27 | use oat\tao\model\Context\AbstractContext; |
| 28 | |
| 29 | class PropertySpecificationContext extends AbstractContext |
| 30 | { |
| 31 | public const PARAM_PROPERTY = 'property'; |
| 32 | public const PARAM_FORM_INDEX = 'form-index'; |
| 33 | public const PARAM_FORM_DATA = 'form-data'; |
| 34 | |
| 35 | protected function getSupportedParameters(): array |
| 36 | { |
| 37 | return [ |
| 38 | self::PARAM_PROPERTY, |
| 39 | self::PARAM_FORM_INDEX, |
| 40 | self::PARAM_FORM_DATA, |
| 41 | ]; |
| 42 | } |
| 43 | |
| 44 | protected function validateParameter(string $parameter, $parameterValue): void |
| 45 | { |
| 46 | if ($parameter === self::PARAM_PROPERTY && $parameterValue instanceof core_kernel_classes_Property) { |
| 47 | return; |
| 48 | } |
| 49 | |
| 50 | if ($parameter === self::PARAM_FORM_INDEX && is_int($parameterValue)) { |
| 51 | return; |
| 52 | } |
| 53 | |
| 54 | if ($parameter === self::PARAM_FORM_DATA && is_array($parameterValue)) { |
| 55 | return; |
| 56 | } |
| 57 | |
| 58 | throw new InvalidArgumentException( |
| 59 | sprintf( |
| 60 | 'Invalid argument for %s', |
| 61 | $parameter |
| 62 | ) |
| 63 | ); |
| 64 | } |
| 65 | } |