RevisionPatroller::patrol()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 8
ccs 0
cts 8
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
crap 2
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Mediawiki\DataModel\Revision;
7
8
/**
9
 * @access private
10
 *
11
 * @author Addshore
12
 */
13
class RevisionPatroller extends Service {
14
15
	/**
16
	 * @since 0.3
17
	 *
18
	 * @param Revision $revision
19
	 *
20
	 * @return bool success
21
	 */
22
	public function patrol( Revision $revision ) {
23
		$this->api->postRequest( new SimpleRequest(
24
			'patrol', [
25
				'revid' => $revision->getId(),
26
				'token' => $this->getTokenForRevision( $revision ),
27
			] ) );
28
		return true;
29
	}
30
31
	/**
32
	 * @param Revision $revision
33
	 *
34
	 * @return string
35
	 */
36 View Code Duplication
	private function getTokenForRevision( Revision $revision ) {
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
37
		$result = $this->api->postRequest( new SimpleRequest( 'query', [
38
			'list' => 'recentchanges',
39
			'rcstart' => $revision->getTimestamp(),
40
			'rcend' => $revision->getTimestamp(),
41
			'rctoken' => 'patrol',
42
		] ) );
43
		$result = array_shift( $result['query']['recentchanges'] );
44
		return $result['patroltoken'];
45
	}
46
47
}
48