AbuseFilter::abuselog()   B
last analyzed

Complexity

Conditions 6
Paths 32

Size

Total Lines 22
Code Lines 15

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 42

Importance

Changes 0
Metric Value
cc 6
eloc 15
nc 32
nop 8
dl 0
loc 22
rs 8.6737
c 0
b 0
f 0
ccs 0
cts 18
cp 0
crap 42

How to fix   Many Parameters   

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
3
/**
4
 * This file is part of Peachy MediaWiki Bot API
5
 *
6
 * Peachy is free software: you can redistribute it and/or modify
7
 * it under the terms of the GNU General Public License as published by
8
 * the Free Software Foundation, either version 3 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18
 */
19
20
class AbuseFilter {
21
22
	/**
23
	 * Wiki class
24
	 *
25
	 * @var Wiki
26
	 * @access private
27
	 */
28
	private $wiki;
29
30
	/**
31
	 * Construction method for the AbuseFilter class
32
	 *
33
	 * @access public
34
	 * @param Wiki &$wikiClass The Wiki class object
35
	 * @throws DependencyError
36
	 */
37
	public function __construct(Wiki &$wikiClass)
38
	{
39
		$this->wiki = $wikiClass;
40
41
		if( !array_key_exists( 'Abuse Filter', $wikiClass->get_extensions() ) ) {
42
			throw new DependencyError( "AbuseFilter", "http://www.mediawiki.org/wiki/Extension:AbuseFilter" );
0 ignored issues
show
Documentation introduced by
'http://www.mediawiki.or.../Extension:AbuseFilter' is of type string, but the function expects a boolean.

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...
43
		}
44
	}
45
46
	/**
47
	 * Returns the abuse filter log
48
	 *
49
	 * @access public
50
	 * @param int $filter Filter ID. Default null
51
	 * @param string $user Show entries by this user. Default null
52
	 * @param string $title Show entries to this title. Default null
53
	 * @param int $limit Number of entries to retrieve. Defautl null
54
	 * @param string $start Timestamp to start at. Default null
55
	 * @param string $end Timestamp to end at. Default null
56
	 * @param string $dir Direction to list. Default older
57
	 * @param array $prop Properties to retrieve. Default array( 'ids', 'filter', 'user', 'ip', 'title', 'action', 'details', 'result', 'timestamp' )
58
	 * @return array
59
	 */
60
	public function abuselog( $filter = null, $user = null, $title = null, $limit = null, $start = null, $end = null, $dir = 'older', $prop = array(
61
		'ids', 'filter', 'user', 'ip', 'title', 'action', 'details', 'result', 'timestamp'
62
	) ) {
63
64
		$tArray = array(
65
			'prop'   => $prop,
66
			'_code'  => 'afl',
67
			'afldir' => $dir,
68
			'_limit' => $limit,
69
			'list'   => 'abuselog',
70
		);
71
72
		if( !is_null( $filter ) ) $tArray['aflfilter'] = $filter;
73
		if( !is_null( $user ) ) $tArray['afluser'] = $user;
74
		if( !is_null( $title ) ) $tArray['afltitle'] = $title;
75
		if( !is_null( $start ) ) $tArray['aflstart'] = $start;
76
		if( !is_null( $end ) ) $tArray['aflend'] = $end;
77
78
		pecho( "Getting abuse log...\n\n", PECHO_NORMAL );
79
80
		return $this->wiki->listHandler( $tArray );
81
	}
82
83
	/**
84
	 * Returns a list of all filters
85
	 *
86
	 * @access public
87
	 * @param int $start Filter ID to start at. Default null
88
	 * @param int $end Filter ID to end at. Default null
89
	 * @param string $dir Direction to list. Default newer
90
	 * @param bool $enabled Only list enabled filters. true => only enabled, false => only disabled, null => all
91
	 * @param bool $deleted Only list deleted filters. true => only deleted, false => only non-deleted, null => all
92
	 * @param bool $private Only list private filters. true => only private, false => only non-private, null => all
93
	 * @param int $limit Number of filters to get. Default null
94
	 * @param array $prop Properties to retrieve. Default array( 'id', 'description', 'pattern', 'actions', 'hits', 'comments', 'lasteditor', 'lastedittime', 'status', 'private' )
95
	 * @return array
96
	 */
97
	public function abusefilters( $start = null, $end = null, $dir = 'newer', $enabled = null, $deleted = false, $private = null, $limit = null, $prop = array(
98
		'id', 'description', 'pattern', 'actions', 'hits', 'comments', 'lasteditor', 'lastedittime', 'status', 'private'
99
	) ) {
100
101
		$tArray = array(
102
			'prop'    => $prop,
103
			'_code'   => 'abf',
104
			'abfdir'  => $dir,
105
			'_limit'  => $limit,
106
			'abfshow' => array(),
107
			'list'    => 'abusefilters'
108
		);
109
110
		if( !is_null( $enabled ) ) {
111
			if( $enabled ) {
112
				$tArray['abfshow'][] = 'enabled';
113
			} else {
114
				$tArray['abfshow'][] = '!enabled';
115
			}
116
		}
117
118
		if( !is_null( $deleted ) ) {
119
			if( $deleted ) {
120
				$tArray['abfshow'][] = 'deleted';
121
			} else {
122
				$tArray['abfshow'][] = '!deleted';
123
			}
124
		}
125
126
		if( !is_null( $private ) ) {
127
			if( $private ) {
128
				$tArray['abfshow'][] = 'private';
129
			} else {
130
				$tArray['abfshow'][] = '!private';
131
			}
132
		}
133
134
		$tArray['abfshow'] = implode( '|', $tArray['abfshow'] );
135
136
		if( !is_null( $start ) ) $tArray['abfstartid'] = $start;
137
		if( !is_null( $end ) ) $tArray['abfendid'] = $end;
138
139
		pecho( "Getting abuse filter list...\n\n", PECHO_NORMAL );
140
141
		return $this->wiki->listHandler( $tArray );
142
	}
143
144
145
}