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

PageMover   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 17.39 %

Coupling/Cohesion

Components 0
Dependencies 0

Importance

Changes 0
Metric Value
dl 8
loc 46
c 0
b 0
f 0
wmc 3
lcom 0
cbo 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A move() 0 9 1
A moveFromPageId() 0 7 1
A getMoveParams() 8 8 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\Page;
7
use Addwiki\Mediawiki\DataModel\Title;
8
9
/**
10
 * @access private
11
 *
12
 * @author Addshore
13
 */
14
class PageMover extends Service {
15
16
	/**
17
	 * @since 0.2
18
	 *
19
	 * @param Page $page
20
	 * @param Title $target
21
	 * @param array $extraParams
22
	 */
23
	public function move( Page $page, Title $target, array $extraParams = [] ): bool {
24
		$this->api->postRequest(
25
			new SimpleRequest(
26
				'move', $this->getMoveParams( $page->getId(), $target, $extraParams )
27
			)
28
		);
29
30
		return true;
31
	}
32
33
	/**
34
	 * @since 0.2
35
	 *
36
	 *
37
	 */
38
	public function moveFromPageId( int $pageid, Title $target, array $extraParams = [] ): bool {
39
		$this->api->postRequest(
40
			new SimpleRequest( 'move', $this->getMoveParams( $pageid, $target, $extraParams ) )
41
		);
42
43
		return true;
44
	}
45
46
	/**
47
	 *
48
	 * @return mixed[]
49
	 */
50 View Code Duplication
	private function getMoveParams( int $pageid, \Addwiki\Mediawiki\DataModel\Title $target, array $extraParams ): array {
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...
51
		$params = [];
52
		$params['fromid'] = $pageid;
53
		$params['to'] = $target->getTitle();
54
		$params['token'] = $this->api->getToken( 'move' );
55
56
		return array_merge( $extraParams, $params );
57
	}
58
59
}
60