Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
Total | |
33.33% |
5 / 15 |
|
37.50% |
3 / 8 |
CRAP | |
0.00% |
0 / 1 |
CountingRemediator | |
33.33% |
5 / 15 |
|
37.50% |
3 / 8 |
26.96 | |
0.00% |
0 / 1 |
__construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
increment | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
redirectInIndex | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
pageNotInIndex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
ghostPageInIndex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
pageInWrongIndex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
oldVersionInIndex | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 | |||
oldDocument | |
0.00% |
0 / 2 |
|
0.00% |
0 / 1 |
2 |
1 | <?php |
2 | |
3 | namespace CirrusSearch\Sanity; |
4 | |
5 | use MediaWiki\Title\Title; |
6 | use WikiPage; |
7 | |
8 | /** |
9 | * Counts problems seen and delegates remediation to another instance. |
10 | * |
11 | * This program is free software; you can redistribute it and/or modify |
12 | * it under the terms of the GNU General Public License as published by |
13 | * the Free Software Foundation; either version 2 of the License, or |
14 | * (at your option) any later version. |
15 | * |
16 | * This program is distributed in the hope that it will be useful, |
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
19 | * GNU General Public License for more details. |
20 | * |
21 | * You should have received a copy of the GNU General Public License along |
22 | * with this program; if not, write to the Free Software Foundation, Inc., |
23 | * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
24 | * http://www.gnu.org/copyleft/gpl.html |
25 | */ |
26 | |
27 | class CountingRemediator implements Remediator { |
28 | |
29 | /** @var Remediator Instance to delgate to */ |
30 | private Remediator $delegate; |
31 | |
32 | /** |
33 | * @var callable Function with no arguments returning a |
34 | * CounterMetric instance. This must be a callable, and |
35 | * not the CounterMetric itself, as the api requires setting |
36 | * all labels for each increment. |
37 | */ |
38 | private $counterFactory; |
39 | |
40 | /** |
41 | * @param Remediator $delegate Instance to delgate to |
42 | * @param callable $counterFactory Function with a single string argument returning a |
43 | * CounterMetric instance. |
44 | */ |
45 | public function __construct( Remediator $delegate, callable $counterFactory ) { |
46 | $this->delegate = $delegate; |
47 | $this->counterFactory = $counterFactory; |
48 | } |
49 | |
50 | private function increment( string $problem ) { |
51 | ( $this->counterFactory )( $problem )->increment(); |
52 | } |
53 | |
54 | /** |
55 | * @inheritDoc |
56 | */ |
57 | public function redirectInIndex( string $docId, WikiPage $page, string $indexSuffix ) { |
58 | $this->increment( __FUNCTION__ ); |
59 | $this->delegate->redirectInIndex( $docId, $page, $indexSuffix ); |
60 | } |
61 | |
62 | /** |
63 | * @inheritDoc |
64 | */ |
65 | public function pageNotInIndex( WikiPage $page ) { |
66 | $this->increment( __FUNCTION__ ); |
67 | $this->delegate->pageNotInIndex( $page ); |
68 | } |
69 | |
70 | /** |
71 | * @inheritDoc |
72 | */ |
73 | public function ghostPageInIndex( $docId, Title $title ) { |
74 | $this->increment( __FUNCTION__ ); |
75 | $this->delegate->ghostPageInIndex( $docId, $title ); |
76 | } |
77 | |
78 | /** |
79 | * @inheritDoc |
80 | */ |
81 | public function pageInWrongIndex( $docId, WikiPage $page, $indexSuffix ) { |
82 | $this->increment( __FUNCTION__ ); |
83 | $this->delegate->pageInWrongIndex( $docId, $page, $indexSuffix ); |
84 | } |
85 | |
86 | /** |
87 | * @inheritDoc |
88 | */ |
89 | public function oldVersionInIndex( $docId, WikiPage $page, $indexSuffix ) { |
90 | $this->increment( __FUNCTION__ ); |
91 | $this->delegate->oldVersionInIndex( $docId, $page, $indexSuffix ); |
92 | } |
93 | |
94 | /** |
95 | * @inheritDoc |
96 | */ |
97 | public function oldDocument( WikiPage $page ) { |
98 | $this->increment( __FUNCTION__ ); |
99 | $this->delegate->oldDocument( $page ); |
100 | } |
101 | } |