Completed
Push — master ( dc1683...3e9aec )
by mw
07:38 queued 05:33
created

CompoundQueryResult::addResult()   B

Complexity

Conditions 6
Paths 15

Size

Total Lines 24
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 24
rs 8.5125
c 0
b 0
f 0
cc 6
eloc 14
nc 15
nop 1
1
<?php
2
3
namespace SCQ;
4
5
use SMWQueryResult as QueryResult;
6
use SMWResultArray as ResultArray;
7
8
/**
9
 * Subclass of SMWQueryResult - this class was mostly created in order to
10
 * get around an inconvenient print-request-compatibility check in
11
 * SMWQueryResult::addRow
12
 *
13
 * @license GNU GPL v2+
14
 * @since 1.0
15
 *
16
 * @author Yaron Koren
17
 */
18
class CompoundQueryResult extends QueryResult {
19
20
	/**
21
	 * Adds in the pages from a new query result to the existing set of
22
	 * pages - only pages that weren't in the set already get added.
23
	 *
24
	 * @param QueryResult $newResult
25
	 */
26
	public function addResult( QueryResult $newResult ) {
27
		$existingPageNames = array();
28
29
		while ( $row = $this->getNext() ) {
30
			if ( $row[0] instanceof ResultArray ) {
31
				$content = $row[0]->getContent();
32
				$existingPageNames[] = $content[0]->getLongText( SMW_OUTPUT_WIKI );
33
			}
34
		}
35
36
		while ( ( $row = $newResult->getNext() ) !== false ) {
37
			if ( property_exists( $newResult, 'display_options' ) ) {
38
				$row[0]->display_options = $newResult->display_options;
0 ignored issues
show
Bug introduced by
The property display_options does not seem to exist in SMWQueryResult.

An attempt at access to an undefined property has been detected. This may either be a typographical error or the property has been renamed but there are still references to its old name.

If you really want to allow access to undefined properties, you can define magic methods to allow access. See the php core documentation on Overloading.

Loading history...
39
			}
40
			$content = $row[0]->getContent();
41
			$pageName = $content[0]->getLongText( SMW_OUTPUT_WIKI );
42
43
			if ( !in_array( $pageName, $existingPageNames ) ) {
44
				$this->m_content[] = $row;
0 ignored issues
show
Bug introduced by
The property m_content does not exist. Did you maybe forget to declare it?

In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:

class MyClass { }

$x = new MyClass();
$x->foo = true;

Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion:

class MyClass {
    public $foo;
}

$x = new MyClass();
$x->foo = true;
Loading history...
45
			}
46
		}
47
48
		reset( $this->m_content );
49
	}
50
51
}
52