Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
CRAP | |
100.00% |
1 / 1 |
ConfigSearchProfileOverride | |
100.00% |
13 / 13 |
|
100.00% |
4 / 4 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
1 | |||
getOverriddenName | |
100.00% |
3 / 3 |
|
100.00% |
1 / 1 |
2 | |||
priority | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
explain | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
1 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Profile; |
4 | |
5 | use MediaWiki\Config\Config; |
6 | |
7 | /** |
8 | * Overrider that gets its name using an entry in a Config object |
9 | */ |
10 | class ConfigSearchProfileOverride implements SearchProfileOverride { |
11 | |
12 | /** |
13 | * @var Config |
14 | */ |
15 | private $config; |
16 | |
17 | /** |
18 | * @var string |
19 | */ |
20 | private $configEntry; |
21 | |
22 | /** |
23 | * @var int |
24 | */ |
25 | private $priority; |
26 | |
27 | /** |
28 | * @param Config $config |
29 | * @param string $configEntry the name of the config entry holding the name of the overridden profile |
30 | * @param int $priority |
31 | */ |
32 | public function __construct( Config $config, $configEntry, $priority = SearchProfileOverride::CONFIG_PRIO ) { |
33 | $this->config = $config; |
34 | $this->configEntry = $configEntry; |
35 | $this->priority = $priority; |
36 | } |
37 | |
38 | /** |
39 | * Get the overridden name or null if it cannot be overridden. |
40 | * @param string[] $contextParams |
41 | * @return string|null |
42 | */ |
43 | public function getOverriddenName( array $contextParams ) { |
44 | if ( $this->config->has( $this->configEntry ) ) { |
45 | return $this->config->get( $this->configEntry ); |
46 | } |
47 | return null; |
48 | } |
49 | |
50 | /** |
51 | * The priority of this override, lower wins |
52 | * @return int |
53 | */ |
54 | public function priority() { |
55 | return $this->priority; |
56 | } |
57 | |
58 | /** |
59 | * @return array |
60 | */ |
61 | public function explain(): array { |
62 | return [ |
63 | 'type' => 'config', |
64 | 'priority' => $this->priority(), |
65 | 'configEntry' => $this->configEntry, |
66 | 'value' => $this->getOverriddenName( [] ) |
67 | ]; |
68 | } |
69 | } |