Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
CRAP | |
0.00% |
0 / 1 |
| FeatureFlagPropertiesMapping | |
0.00% |
0 / 14 |
|
0.00% |
0 / 4 |
42 | |
0.00% |
0 / 1 |
| addFeatureProperties | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
6 | |||
| addFeatureProperty | |
0.00% |
0 / 10 |
|
0.00% |
0 / 1 |
6 | |||
| getFeatureProperties | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| getAllProperties | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 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) 2024 (original work) Open Assessment Technologies SA. |
| 19 | */ |
| 20 | |
| 21 | declare(strict_types=1); |
| 22 | |
| 23 | namespace oat\tao\model\featureFlag\Service; |
| 24 | |
| 25 | use InvalidArgumentException; |
| 26 | |
| 27 | class FeatureFlagPropertiesMapping |
| 28 | { |
| 29 | private array $featureBasedProperties; |
| 30 | |
| 31 | public function addFeatureProperties(string $featureFlag, array $properties): void |
| 32 | { |
| 33 | foreach ($properties as $property) { |
| 34 | $this->addFeatureProperty($featureFlag, $property); |
| 35 | } |
| 36 | } |
| 37 | |
| 38 | public function addFeatureProperty(string $featureFlag, string $property): void |
| 39 | { |
| 40 | $this->featureBasedProperties[$featureFlag] ??= []; |
| 41 | |
| 42 | if (in_array($property, $this->featureBasedProperties[$featureFlag], true)) { |
| 43 | throw new InvalidArgumentException( |
| 44 | sprintf( |
| 45 | 'Property %s already mapped to the feature %s', |
| 46 | $property, |
| 47 | $featureFlag |
| 48 | ) |
| 49 | ); |
| 50 | } |
| 51 | |
| 52 | $this->featureBasedProperties[$featureFlag][] = $property; |
| 53 | } |
| 54 | |
| 55 | public function getFeatureProperties(string $featureFlag): array |
| 56 | { |
| 57 | return $this->featureBasedProperties[$featureFlag] ?? []; |
| 58 | } |
| 59 | |
| 60 | public function getAllProperties(): array |
| 61 | { |
| 62 | return $this->featureBasedProperties; |
| 63 | } |
| 64 | } |