Completed
Pull Request — master (#36)
by
unknown
03:09
created

PagePurger   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 42.11%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 5
dl 0
loc 63
ccs 8
cts 19
cp 0.4211
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A purge() 0 7 1
A purgePages() 0 9 2
A purgeGenerator() 0 7 1
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\Generator\ApiGenerator;
6
use Mediawiki\Api\MediawikiApi;
7
use Mediawiki\Api\SimpleRequest;
8
use Mediawiki\DataModel\Pages;
9
use Mediawiki\DataModel\Page;
10
11
/**
12
 * @access private
13
 *
14
 * @author Addshore
15
 * @author Thomas Arrow
16
 */
17
class PagePurger {
18
19
	/**
20
	 * @var MediawikiApi
21
	 */
22
	private $api;
23
24
	/**
25
	 * @param MediawikiApi $api
26
	 */
27 2
	public function __construct( MediawikiApi $api ) {
28 2
		$this->api = $api;
29 2
	}
30
31
	/**
32
	 * @since 0.3
33
	 *
34
	 * @param Page $page
35
	 *
36
	 * @return bool
37
	 */
38 1
	public function purge( Page $page ) {
39 1
		$this->api->postRequest(
40 1
			new SimpleRequest( 'purge', [ 'pageids' => $page->getId() ] )
0 ignored issues
show
Deprecated Code introduced by
The method Mediawiki\DataModel\Page::getId() has been deprecated with message: since 0.5

This method has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the method will be removed from the class and what other method or class to use instead.

Loading history...
41 1
		);
42
43 1
		return true;
44
	}
45
46
	/**
47
	 * @since 0.x
48
	 *
49
	 * @param Pages $pages
50
	 *
51
	 * @return bool
52
	 *
53
	 */
54
	public function purgePages( Pages $pages ) {
55
		$pagesArray = $pages->toArray();
56
57
		foreach ( $pagesArray as $page ) {
58
			$this->purge( $page );
59
		}
60
61
		return true;
62
	}
63
64
	/**
65
	 * @since 0.6
66
	 *
67
	 * @param ApiGenerator $generator
68
	 *
69
	 * @return bool
70
	 */
71
	public function purgeGenerator( ApiGenerator $generator ) {
72
		$this->api->postRequest(
73
			new SimpleRequest( 'purge', $generator->getParams() )
74
		);
75
76
		return true;
77
	}
78
79
}
80