Completed
Push — main ( 2daa48...b5d932 )
by
unknown
08:38
created

RevisionPatroller   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 28.57 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A patrol() 0 8 1
A getTokenForRevision() 0 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 Addwiki\Mediawiki\Api\Service;
4
5
use Addwiki\Mediawiki\Api\Client\SimpleRequest;
6
use Addwiki\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 ): bool {
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
	private function getTokenForRevision( Revision $revision ): string {
35
		$result = $this->api->postRequest( new SimpleRequest( 'query', [
36
			'list' => 'recentchanges',
37
			'rcstart' => $revision->getTimestamp(),
38
			'rcend' => $revision->getTimestamp(),
39
			'rctoken' => 'patrol',
40
		] ) );
41
		$result = array_shift( $result['query']['recentchanges'] );
42
		return $result['patroltoken'];
43
	}
44
45
}
46