Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
75 / 75
100.00% covered (success)
100.00%
19 / 19
CRAP
100.00% covered (success)
100.00%
1 / 1
GlobalCustomFilter
100.00% covered (success)
100.00%
75 / 75
100.00% covered (success)
100.00%
19 / 19
46
100.00% covered (success)
100.00%
1 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setLanguageDenyList
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setLanguageAllowList
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setRequiredPlugins
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setFallbackFilter
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setApplyToAnalyzers
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 getApplyToAnalyzers
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 setRequiredTokenizer
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setDisallowedTokenFilters
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setDisallowedCharFilters
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 setMustFollowFilters
100.00% covered (success)
100.00%
2 / 2
100.00% covered (success)
100.00%
1 / 1
1
 enableGlobalCustomFilters
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
7
 languageCheck
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 pluginsAvailable
100.00% covered (success)
100.00%
4 / 4
100.00% covered (success)
100.00%
1 / 1
3
 requiredTokenizerUsed
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
4
 disallowedTokenFiltersPresent
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 disallowedCharFiltersPresent
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
3
 analyzerCheck
100.00% covered (success)
100.00%
9 / 9
100.00% covered (success)
100.00%
1 / 1
7
 insertGlobalCustomFilter
100.00% covered (success)
100.00%
10 / 10
100.00% covered (success)
100.00%
1 / 1
4
1<?php
2
3namespace CirrusSearch\Maintenance;
4
5class GlobalCustomFilter {
6    /** @var string filter type, probably 'filter' or 'char_filter'; 'filter' by default */
7    private $type;
8
9    /** @var string[] languages where this filter should not be used, by language codes */
10    private $languageDenyList = [];
11
12    /** @var string[] only languages where this filter should be used, by language codes */
13    private $languageAllowList = [];
14
15    /** @var string[] plugins that must be present to use the filter */
16    private $requiredPlugins = [];
17
18    /** @var string local filter to use instead if requiredPlugins are not available */
19    private $fallbackFilter = '';
20
21    /** @var string[] which analyzers to apply to; 'text' and 'text_search' by default */
22    private $applyToAnalyzers = [ 'text', 'text_search' ];
23
24    /** @var string tokenizer that must be present to use the filter */
25    private $requiredTokenizer = '';
26
27    /** @var string[] token filters with which the filter is not allowed/needed */
28    private $disallowedTokenFilters = [];
29
30    /** @var string[] character filters with which the filter is not allowed/needed */
31    private $disallowedCharFilters = [];
32
33    /** @var string[] filters this one must come after. see T268730 */
34    private $mustFollowFilters = [];
35
36    public function __construct( string $type = 'filter' ) {
37        $this->type = $type;
38    }
39
40    /**
41     * @param string[] $languageDenyList
42     * @return self
43     */
44    public function setLanguageDenyList( array $languageDenyList ): self {
45        $this->languageDenyList = $languageDenyList;
46        return $this;
47    }
48
49    /**
50     * @param string[] $languageAllowList
51     * @return self
52     */
53    public function setLanguageAllowList( array $languageAllowList ): self {
54        $this->languageAllowList = $languageAllowList;
55        return $this;
56    }
57
58    /**
59     * @param string[] $requiredPlugins
60     * @return self
61     */
62    public function setRequiredPlugins( array $requiredPlugins ): self {
63        $this->requiredPlugins = $requiredPlugins;
64        return $this;
65    }
66
67    /**
68     * @param string $fallbackFilter
69     * @return self
70     */
71    public function setFallbackFilter( string $fallbackFilter ): self {
72        $this->fallbackFilter = $fallbackFilter;
73        return $this;
74    }
75
76    /**
77     * @param string[] $applyToAnalyzers
78     * @return self
79     */
80    public function setApplyToAnalyzers( array $applyToAnalyzers ): self {
81        $this->applyToAnalyzers = $applyToAnalyzers;
82        return $this;
83    }
84
85    public function getApplyToAnalyzers() {
86        return $this->applyToAnalyzers;
87    }
88
89    /**
90     * @param string $requiredTokenizer
91     * @return self
92     */
93    public function setRequiredTokenizer( string $requiredTokenizer ): self {
94        $this->requiredTokenizer = $requiredTokenizer;
95        return $this;
96    }
97
98    /**
99     * @param string[] $disallowedTokenFilters
100     * @return self
101     */
102    public function setDisallowedTokenFilters( array $disallowedTokenFilters ): self {
103        $this->disallowedTokenFilters = $disallowedTokenFilters;
104        return $this;
105    }
106
107    /**
108     * @param string[] $disallowedCharFilters
109     * @return self
110     */
111    public function setDisallowedCharFilters( array $disallowedCharFilters ): self {
112        $this->disallowedCharFilters = $disallowedCharFilters;
113        return $this;
114    }
115
116    /**
117     * @param string[] $mustFollowFilters
118     * @return self
119     */
120    public function setMustFollowFilters( array $mustFollowFilters ): self {
121        $this->mustFollowFilters = $mustFollowFilters;
122        return $this;
123    }
124
125    /**
126     * update languages with global custom filters (e.g., homoglyph & nnbsp filters)
127     *
128     * @param mixed[] $config
129     * @param string $language
130     * @param GlobalCustomFilter[] $customFilters list of filters and info
131     * @param string[] $installedPlugins
132     * @return mixed[] updated config
133     */
134    public static function enableGlobalCustomFilters( array $config, string $language,
135            array $customFilters, array $installedPlugins ) {