Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
RemoteSourceContext | |
100.00% |
20 / 20 |
|
100.00% |
2 / 2 |
8 | |
100.00% |
1 / 1 |
getSupportedParameters | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
1 | |||
validateParameter | |
100.00% |
12 / 12 |
|
100.00% |
1 / 1 |
7 |
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\Domain; |
24 | |
25 | use InvalidArgumentException; |
26 | use oat\tao\model\Context\AbstractContext; |
27 | |
28 | class RemoteSourceContext extends AbstractContext |
29 | { |
30 | public const PARAM_SOURCE_URL = 'sourceUrl'; |
31 | public const PARAM_URI_PATH = 'uriPath'; |
32 | public const PARAM_LABEL_PATH = 'labelPath'; |
33 | public const PARAM_DEPENDENCY_URI_PATH = 'dependencyUriPath'; |
34 | public const PARAM_PARSER = 'parser'; |
35 | public const PARAM_JSON = 'json'; |
36 | |
37 | protected function getSupportedParameters(): array |
38 | { |
39 | return [ |
40 | self::PARAM_SOURCE_URL, |
41 | self::PARAM_URI_PATH, |
42 | self::PARAM_LABEL_PATH, |
43 | self::PARAM_DEPENDENCY_URI_PATH, |
44 | self::PARAM_PARSER, |
45 | self::PARAM_JSON, |
46 | ]; |
47 | } |
48 | |
49 | protected function validateParameter(string $parameter, $parameterValue): void |
50 | { |
51 | if ($parameter === self::PARAM_JSON && is_array($parameterValue)) { |
52 | return; |
53 | } |
54 | |
55 | if ($parameter === self::PARAM_DEPENDENCY_URI_PATH && $parameterValue === null) { |
56 | return; |
57 | } |
58 | |
59 | if ($parameter !== self::PARAM_JSON && is_string($parameterValue)) { |
60 | return; |
61 | } |
62 | |
63 | throw new InvalidArgumentException( |
64 | sprintf( |
65 | 'Context parameter %s is not valid.', |
66 | $parameter |
67 | ) |
68 | ); |
69 | } |
70 | } |