Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
92.86% |
13 / 14 |
|
85.71% |
6 / 7 |
CRAP | |
0.00% |
0 / 1 |
ExtensionRegistryProfileRepository | |
92.86% |
13 / 14 |
|
85.71% |
6 / 7 |
8.02 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
4 / 4 |
|
100.00% |
1 / 1 |
1 | |||
repositoryType | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
repositoryName | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
getProfile | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
extractAttribute | |
75.00% |
3 / 4 |
|
0.00% |
0 / 1 |
2.06 | |||
hasProfile | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
listExposedProfiles | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Profile; |
4 | |
5 | use ExtensionRegistry; |
6 | |
7 | class ExtensionRegistryProfileRepository implements SearchProfileRepository { |
8 | private string $type; |
9 | private string $name; |
10 | private string $attributeName; |
11 | private ExtensionRegistry $extensionRegistry; |
12 | |
13 | /** |
14 | * @param string $type |
15 | * @param string $name |
16 | * @param string $attributeName |
17 | * @param ExtensionRegistry $extensionRegistry |
18 | */ |
19 | public function __construct( string $type, string $name, string $attributeName, ExtensionRegistry $extensionRegistry ) { |
20 | $this->type = $type; |
21 | $this->name = $name; |
22 | $this->attributeName = $attributeName; |
23 | $this->extensionRegistry = $extensionRegistry; |
24 | } |
25 | |
26 | public function repositoryType() { |
27 | return $this->type; |
28 | } |
29 | |
30 | public function repositoryName() { |
31 | return $this->name; |
32 | } |
33 | |
34 | public function getProfile( $name ) { |
35 | $profiles = $this->extractAttribute(); |
36 | return $profiles[$name] ?? null; |
37 | } |
38 | |
39 | public function extractAttribute(): array { |
40 | $profiles = $this->extensionRegistry->getAttribute( $this->attributeName ); |
41 | if ( !is_array( $profiles ) ) { |
42 | throw new SearchProfileException( "Attribute {configEntry} must be an array or unset" ); |
43 | } |
44 | return $profiles; |
45 | } |
46 | |
47 | /** |
48 | * @inheritDoc |
49 | */ |
50 | public function hasProfile( $name ) { |
51 | return isset( $this->extractAttribute()[$name] ); |
52 | } |
53 | |
54 | /** |
55 | * @inheritDoc |
56 | */ |
57 | public function listExposedProfiles() { |
58 | return $this->extractAttribute(); |
59 | } |
60 | } |