RevisionPatroller   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 10
loc 35
ccs 0
cts 18
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A patrol() 0 8 1
A getTokenForRevision() 10 10 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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