Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
HashModelLookup | |
100.00% |
10 / 10 |
|
100.00% |
4 / 4 |
6 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getModelId | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getModelVersion | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
2 | |||
getModels | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | /** |
3 | * This program is free software: you can redistribute it and/or modify |
4 | * it under the terms of the GNU General Public License as published by |
5 | * the Free Software Foundation, either version 3 of the License, or |
6 | * (at your option) any later version. |
7 | * |
8 | * This program is distributed in the hope that it will be useful, |
9 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
10 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
11 | * GNU General Public License for more details. |
12 | * |
13 | * You should have received a copy of the GNU General Public License |
14 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
15 | */ |
16 | |
17 | namespace ORES\Storage; |
18 | |
19 | use InvalidArgumentException; |
20 | |
21 | class HashModelLookup implements ModelLookup { |
22 | |
23 | /** @var array[] */ |
24 | private $modelData; |
25 | |
26 | public function __construct( array $modelData ) { |
27 | $this->modelData = $modelData; |
28 | } |
29 | |
30 | /** |
31 | * @see ModelLookup::getModelId() |
32 | * @param string $model |
33 | * |
34 | * @throws InvalidArgumentException |
35 | * @return int |
36 | */ |
37 | public function getModelId( $model ) { |
38 | $modelData = $this->modelData; |
39 | if ( !array_key_exists( $model, $modelData ) ) { |
40 | throw new InvalidArgumentException( "No model available for [{$model}]" ); |
41 | } |
42 | |
43 | return $modelData[$model]['id']; |
44 | } |
45 | |
46 | /** |
47 | * @see ModelLookup::getModelVersion() |
48 | * @param string $model |
49 | * |
50 | * @throws InvalidArgumentException |
51 | * @return string |
52 | */ |
53 | public function getModelVersion( $model ) { |
54 | $modelData = $this->modelData; |
55 | if ( !array_key_exists( $model, $modelData ) ) { |
56 | throw new InvalidArgumentException( "No model available for [{$model}]" ); |
57 | } |
58 | |
59 | return $modelData[$model]['version']; |
60 | } |
61 | |
62 | /** |
63 | * @see ModelLookup::getModels() |
64 | * |
65 | * @return array[] |
66 | */ |
67 | public function getModels() { |
68 | return $this->modelData; |
69 | } |
70 | |
71 | } |