Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
CRAP | |
100.00% |
1 / 1 |
GlobalCustomFilter | |
100.00% |
11 / 11 |
|
100.00% |
2 / 2 |
5 | |
100.00% |
1 / 1 |
__construct | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
filterIsUsable | |
100.00% |
6 / 6 |
|
100.00% |
1 / 1 |
4 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Maintenance; |
4 | |
5 | class GlobalCustomFilter { |
6 | /** @var string filter type, probably 'filter' or 'char_filter'; 'filter' by default */ |
7 | public $type; |
8 | |
9 | /** @var string[] plugins that must be present to use the filter */ |
10 | public $requiredPlugins; |
11 | |
12 | /** @var string[] filters this one must come after. see T268730 */ |
13 | public $incompatibleFilters; |
14 | |
15 | /** @var string[] languages where this filter should not be used, by language codes */ |
16 | public $denyList; |
17 | |
18 | /** @var string[] which analyzers to apply to; 'text' and 'text_search' by default */ |
19 | public $applyTo; |
20 | |
21 | public function __construct( |
22 | string $type = 'filter', |
23 | array $requiredPlugins = [], |
24 | array $incompatibleFilters = [], |
25 | array $applyTo = [ 'text', 'text_search' ], |
26 | array $denyList = [] |
27 | ) { |
28 | $this->type = $type; |
29 | $this->requiredPlugins = $requiredPlugins; |
30 | $this->denyList = $denyList; |
31 | $this->incompatibleFilters = $incompatibleFilters; |
32 | $this->applyTo = $applyTo; |
33 | } |
34 | |
35 | /** |
36 | * check to see if the filter is compatible with a given language and set of |
37 | * installed plugins |
38 | * |
39 | * @param string $language |
40 | * @param string[] $installedPlugins |
41 | * @return bool |
42 | */ |
43 | public function filterIsUsable( string $language, array $installedPlugins ): bool { |
44 | if ( in_array( $language, $this->denyList ) ) { |
45 | return false; |
46 | } |
47 | foreach ( $this->requiredPlugins as $reqPlugin ) { |
48 | if ( !in_array( $reqPlugin, $installedPlugins ) ) { |
49 | return false; |
50 | } |
51 | } |
52 | return true; |
53 | } |
54 | } |