Completed
Push — master ( f40723...0452ba )
by mw
90:24 queued 55:06
created

RequestOptions::getExtraConditions()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 0
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace SMW;
4
5
/**
6
 * Container object for various options that can be used when retrieving
7
 * data from the store. These options are mostly relevant for simple,
8
 * direct requests -- inline queries may require more complex options due
9
 * to their more complex structure.
10
 * Options that should not be used or where default values should be used
11
 * can be left as initialised.
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author Markus Krötzsch
17
 */
18
class RequestOptions {
19
20
	/**
21
	 * The maximum number of results that should be returned.
22
	 */
23
	public $limit = -1;
24
25
	/**
26
	 * A numerical offset. The first $offset results are skipped.
27
	 * Note that this does not imply a defined order of results
28
	 * (see SMWRequestOptions->$sort below).
29
	 */
30
	public $offset = 0;
31
32
	/**
33
	 * Should the result be ordered? The employed order is defined
34
	 * by the type of result that are requested: wiki pages and strings
35
	 * are ordered alphabetically, whereas other data is ordered
36
	 * numerically. Usually, the order should be fairly "natural".
37
	 */
38
	public $sort = false;
39
40
	/**
41
	 * If SMWRequestOptions->$sort is true, this parameter defines whether
42
	 * the results are ordered in ascending or descending order.
43
	 */
44
	public $ascending = true;
45
46
	/**
47
	 * Specifies a lower or upper bound for the values returned by the query.
48
	 * Whether it is lower or upper is specified by the parameter "ascending"
49
	 * (true->lower, false->upper).
50
	 */
51
	public $boundary = null;
52
53
	/**
54
	 * Specifies whether or not the requested boundary should be returned
55
	 * as a result.
56
	 */
57
	public $include_boundary = true;
58
59
	/**
60
	 * An array of string conditions that are applied if the result has a
61
	 * string label that can be subject to those patterns.
62
	 */
63
	private $stringConditions = array();
64
65
	/**
66
	 * An array extra conditions
67
	 */
68
	private $extraConditions = array();
69
70
	/**
71
	 * @since 1.0
72 2
	 *
73 2
	 * @param string $string to match
74 2
	 * @param integer $condition one of STRCOND_PRE, STRCOND_POST, STRCOND_MID
75
	 * @param boolean $isDisjunctiveCondition
76
	 */
77
	public function addStringCondition( $string, $condition, $isDisjunctiveCondition = false ) {
78
		$this->stringConditions[] = new StringCondition( $string, $condition, $isDisjunctiveCondition );
0 ignored issues
show
Documentation introduced by
$string is of type string, but the function expects a object<SMW\srting>.

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...
79
	}
80
81
	/**
82
	 * Return the specified array of SMWStringCondition objects.
83 54
	 *
84 54
	 * @since 1.0
85
	 *
86
	 * @return array
87
	 */
88
	public function getStringConditions() {
89
		return $this->stringConditions;
90
	}
91
92 1
	/**
93 1
	 * @since 2.5
94 1
	 *
95
	 * @param mixed $extraCondition
96
	 */
97
	public function addExtraCondition( $extraCondition ) {
98
		$this->extraConditions[] = $extraCondition;
99
	}
100
101 1
	/**
102 1
	 * @since 2.5
103
	 *
104
	 * @param array
105
	 */
106
	public function getExtraConditions() {
107
		return $this->extraConditions;
108
	}
109
110 1
	/**
111 1
	 * @since 2.5
112 1
	 *
113
	 * @param integer $limit
114
	 */
115
	public function setLimit( $limit ) {
116
		$this->limit = $limit;
117
	}
118
119 1
	/**
120 1
	 * @since 2.5
121
	 *
122
	 * @return integer
123
	 */
124
	public function getLimit() {
125
		return $this->limit;
126
	}
127
128 54
	/**
129
	 * @since 2.5
130 54
	 *
131
	 * @param integer $offset
132 54
	 */
133 2
	public function setOffset( $offset ) {
134
		$this->offset = $offset;
135
	}
136 54
137 54
	/**
138 54
	 * @since 2.5
139 54
	 *
140 54
	 * @return integer
141 54
	 */
142 54
	public function getOffset() {
143
		return $this->offset;
144
	}
145
146
	/**
147
	 * @since 2.4
148
	 *
149
	 * @return string
150
	 */
151
	public function getHash() {
152
153
		$stringConditions = '';
154
155
		foreach ( $this->stringConditions as $stringCondition ) {
156
			$stringConditions .= $stringCondition->getHash();
157
		}
158
159
		return $this->limit . '#' .
160
			$this->offset . '#' .
161
			$this->sort . '#' .
162
			$this->ascending . '#' .
163
			$this->boundary . '#' .
164
			$this->include_boundary . '#' .
165
			( $stringConditions !== '' ? '|' . $stringConditions : '' );
166
			( $this->extraConditions !== array() ? implode( '#', $this->extraConditions ): '' );
0 ignored issues
show
Unused Code introduced by
$this->extraConditions !...>extraConditions) : ''; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
167
	}
168
169
}
170