LogListGetter   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 9

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 9
dl 0
loc 66
ccs 0
cts 47
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getLogList() 0 36 3
A getLogDetailsFromEvent() 0 15 1
1
<?php
2
3
namespace Mediawiki\Api\Service;
4
5
use Mediawiki\Api\SimpleRequest;
6
use Mediawiki\DataModel\Log;
7
use Mediawiki\DataModel\LogList;
8
use Mediawiki\DataModel\Page;
9
use Mediawiki\DataModel\PageIdentifier;
10
use Mediawiki\DataModel\Revisions;
11
use Mediawiki\DataModel\Title;
12
13
/**
14
 * @access private
15
 *
16
 * @author Thomas Arrow
17
 */
18
class LogListGetter extends Service {
19
20
	/**
21
	 * @param array $extraParams
22
	 *
23
	 * @return LogList
24
	 */
25
	public function getLogList( array $extraParams = [] ) {
26
		$logList = new LogList();
27
28
		while ( true ) {
29
			$params = [
30
				'list' => 'logevents',
31
				'leprop' => 'title|ids|type|user|timestamp|comment|details'
32
			];
33
34
			$newParams = array_merge( $extraParams, $params );
35
			$result = $this->api->getRequest( new SimpleRequest( 'query', $newParams ) );
36
37
			foreach ( $result[ 'query' ]['logevents'] as $logevent ) {
38
				$logList->addLog(
39
					new Log(
40
						$logevent['logid'],
41
						$logevent['type'],
42
						$logevent['action'],
43
						$logevent['timestamp'],
44
						$logevent['user'],
45
						new Page(
0 ignored issues
show
Documentation introduced by
new \Mediawiki\DataModel...\DataModel\Revisions()) is of type object<Mediawiki\DataModel\Page>, but the function expects a object<Mediawiki\DataModel\PageIdentifier>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
46
							new PageIdentifier(
47
								new Title( $logevent['title'], $logevent['ns'] ),
48
								$logevent['pageid']
49
							),
50
							new Revisions()
51
						),
52
						$logevent['comment'],
53
						$this->getLogDetailsFromEvent( $logevent )
54
					)
55
				);
56
			}
57
58
			return $logList;
59
		}
60
	}
61
62
	/**
63
	 * @param array $event
64
	 *
65
	 * @return array
66
	 */
67
	private function getLogDetailsFromEvent( $event ) {
68
		$ignoreKeys = array_flip( [
69
			'logid',
70
			'ns',
71
			'title',
72
			'pageid',
73
			'logpage',
74
			'type',
75
			'action',
76
			'user',
77
			'type',
78
			'timestamp',
79
			'comment' ] );
80
		return array_diff_key( $event, $ignoreKeys );
81
	}
82
83
}
84