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 | * @license GPL-2.0-or-later |
| 4 | */ |
| 5 | |
| 6 | namespace CirrusSearch\Sanity; |
| 7 | |
| 8 | use MediaWiki\Page\WikiPage; |
| 9 | use MediaWiki\Title\Title; |
| 10 | |
| 11 | /** |
| 12 | * Counts problems seen and delegates remediation to another instance. |
| 13 | */ |
| 14 | class CountingRemediator implements Remediator { |
| 15 | |
| 16 | /** @var Remediator Instance to delgate to */ |
| 17 | private Remediator $delegate; |
| 18 | |
| 19 | /** |
| 20 | * @var callable Function with no arguments returning a |
| 21 | * CounterMetric instance. This must be a callable, and |
| 22 | * not the CounterMetric itself, as the api requires setting |
| 23 | * all labels for each increment. |
| 24 | */ |
| 25 | private $counterFactory; |
| 26 | |
| 27 | /** |
| 28 | * @param Remediator $delegate Instance to delgate to |
| 29 | * @param callable $counterFactory Function with a single string argument returning a |
| 30 | * CounterMetric instance. |
| 31 | */ |
| 32 | public function __construct( Remediator $delegate, callable $counterFactory ) { |
| 33 | $this->delegate = $delegate; |
| 34 | $this->counterFactory = $counterFactory; |
| 35 | } |
| 36 | |
| 37 | private function increment( string $problem ) { |
| 38 | ( $this->counterFactory )( $problem )->increment(); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * @inheritDoc |
| 43 | */ |
| 44 | public function redirectInIndex( string $docId, WikiPage $page, string $indexSuffix ) { |
| 45 | $this->increment( __FUNCTION__ ); |
| 46 | $this->delegate->redirectInIndex( $docId, $page, $indexSuffix ); |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * @inheritDoc |
| 51 | */ |
| 52 | public function pageNotInIndex( WikiPage $page ) { |
| 53 | $this->increment( __FUNCTION__ ); |
| 54 | $this->delegate->pageNotInIndex( $page ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * @inheritDoc |
| 59 | */ |
| 60 | public function ghostPageInIndex( $docId, Title $title ) { |
| 61 | $this->increment( __FUNCTION__ ); |
| 62 | $this->delegate->ghostPageInIndex( $docId, $title ); |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * @inheritDoc |
| 67 | */ |
| 68 | public function pageInWrongIndex( $docId, WikiPage $page, $indexSuffix ) { |
| 69 | $this->increment( __FUNCTION__ ); |
| 70 | $this->delegate->pageInWrongIndex( $docId, $page, $indexSuffix ); |
| 71 | } |
| 72 | |
| 73 | /** |
| 74 | * @inheritDoc |
| 75 | */ |
| 76 | public function oldVersionInIndex( $docId, WikiPage $page, $indexSuffix ) { |
| 77 | $this->increment( __FUNCTION__ ); |
| 78 | $this->delegate->oldVersionInIndex( $docId, $page, $indexSuffix ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * @inheritDoc |
| 83 | */ |
| 84 | public function oldDocument( WikiPage $page ) { |
| 85 | $this->increment( __FUNCTION__ ); |
| 86 | $this->delegate->oldDocument( $page ); |
| 87 | } |
| 88 | } |