Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
CRAP | |
100.00% |
1 / 1 |
TestPreviewerConfigurationMapper | |
100.00% |
14 / 14 |
|
100.00% |
3 / 3 |
8 | |
100.00% |
1 / 1 |
map | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getActiveProviders | |
100.00% |
8 / 8 |
|
100.00% |
1 / 1 |
3 | |||
getActivePlugins | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
4 |
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) 2020 (original work) Open Assessment Technologies SA |
19 | */ |
20 | |
21 | declare(strict_types=1); |
22 | |
23 | namespace oat\taoQtiTestPreviewer\models\testConfiguration\mapper; |
24 | |
25 | use oat\oatbox\service\ConfigurableService; |
26 | use oat\tao\model\plugins\PluginModule; |
27 | use oat\tao\model\providers\ProviderModule; |
28 | use oat\taoQtiTestPreviewer\models\testConfiguration\TestPreviewerConfig; |
29 | use oat\taoTests\models\runner\plugins\TestPlugin; |
30 | |
31 | class TestPreviewerConfigurationMapper extends ConfigurableService |
32 | { |
33 | /** |
34 | * @param ProviderModule[] $providerModules |
35 | * @param PluginModule[] $plugins |
36 | * @param mixed[] $options |
37 | * |
38 | * @return TestPreviewerConfig |
39 | */ |
40 | public function map(array $providerModules, array $plugins, array $options): TestPreviewerConfig |
41 | { |
42 | return new TestPreviewerConfig($this->getActiveProviders($providerModules, $plugins), $options); |
43 | } |
44 | |
45 | /** |
46 | * @param ProviderModule[] $providerModules |
47 | * @param PluginModule[] $plugins |
48 | * |
49 | * @return TestPlugin[] |
50 | */ |
51 | private function getActiveProviders(array $providerModules, array $plugins): array |
52 | { |
53 | $providers = []; |
54 | |
55 | foreach ($providerModules as $provider) { |
56 | if ($provider->isActive()) { |
57 | $category = $provider->getCategory(); |
58 | |
59 | $providers[$category][] = $provider; |
60 | } |
61 | } |
62 | |
63 | $plugins = $this->getActivePlugins($plugins); |
64 | |
65 | $providers['plugins'] = array_values($plugins); |
66 | |
67 | return $providers; |
68 | } |
69 | |
70 | /** |
71 | * @param PluginModule[] $plugins |
72 | * |
73 | * @return TestPlugin[] |
74 | */ |
75 | private function getActivePlugins(array $plugins): array |
76 | { |
77 | $result = []; |
78 | |
79 | foreach ($plugins as $key => $plugin) { |
80 | if ($plugin instanceof TestPlugin && $plugin->isActive()) { |
81 | $result[$key] = $plugin; |
82 | } |
83 | } |
84 | |
85 | return $result; |
86 | } |
87 | } |