RevisionUndoer::undo()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 7
ccs 0
cts 7
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 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