RevisionUndoer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 36
Duplicated Lines 13.89 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 5
loc 36
ccs 0
cts 19
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A undo() 0 7 1
A getParamsFromRevision() 5 14 2

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 RevisionUndoer extends Service {
14
15
	/**
16
	 * @param Revision $revision
17
	 *
18
	 * @return bool
19
	 */
20
	public function undo( Revision $revision ) {
21
		$this->api->postRequest( new SimpleRequest(
22
			'edit',
23
			$this->getParamsFromRevision( $revision )
24
		) );
25
		return true;
26
	}
27
28
	/**
29
	 * @param Revision $revision
30
	 *
31
	 * @return array
32
	 */
33
	private function getParamsFromRevision( Revision $revision ) {
34
		$params = [
35
			'undo' => $revision->getId(),
36
			'token' => $this->api->getToken(),
37
		];
38
39 View Code Duplication
		if ( $revision->getPageIdentifier()->getId() !== null ) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
40
			$params['pageid'] = $revision->getPageIdentifier()->getId();
41
		} else {
42
			$params['title'] = $revision->getPageIdentifier()->getTitle()->getTitle();
43
		}
44
45
		return $params;
46
	}
47
48
}
49