getSpecialGroupOnSpecificationChange()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace SMW\Notifications\ChangeNotification;
4
5
use SMW\Notifications\PropertyRegistry;
6
use SMW\ApplicationFactory;
7
use SMW\Notifications\DataValues\NotificationGroupValue;
8
use SMW\Store;
9
use SMW\DIProperty;
10
use SMWDIBlob as DIBlob;
11
use SMWDataItem as DataItem;
12
13
/**
14
 * @license GNU GPL v2+
15
 * @since 1.0
16
 *
17
 * @author mwjames
18
 */
19
class NotificationGroupsLocator {
20
21
	/**
22
	 * @var Store
23
	 */
24
	private $store;
25
26
	/**
27
	 * @since 1.0
28
	 *
29
	 * @param  Store $store
30
	 */
31 5
	public function __construct( Store $store ) {
32 5
		$this->store = $store;
33 5
	}
34
35
	/**
36
	 * Special group
37
	 *
38
	 * @since 1.0
39
	 *
40
	 * @return []
0 ignored issues
show
Documentation introduced by
The doc-type [] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)

This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.

Loading history...
41
	 */
42 1
	public function getSpecialGroupOnSpecificationChange() {
43
		return array(
44 1
			NotificationGroupValue::SPECIAL_GROUP => array( new DIBlob( NotificationGroupValue::getSpecialGroupName() ) )
45
		);
46
	}
47
48
	/**
49
	 * @since 1.0
50
	 *
51
	 * @param DataItem $dataItem
52
	 * @param array $subSemanticDataMatch
53
	 *
54
	 * @return DataItem[]
55
	 */
56 2
	public function findNotificationsToGroupList( DataItem $dataItem, array $subSemanticDataMatch ) {
57
58 2
		$property = new DIProperty(
59 2
			PropertyRegistry::NOTIFICATIONS_TO_GROUP
60
		);
61
62
		// Either match the property on a plain assignment or
63 2
		if ( ( $pv = $this->store->getPropertyValues( $dataItem, $property ) ) !== array() ) {
64
			return $pv;
65
		}
66
67
		// Find out whether a detection matrix was build using a subobject
68 2
		$semanticData = $this->store->getSemanticData(
69 2
			$dataItem
0 ignored issues
show
Compatibility introduced by
$dataItem of type object<SMWDataItem> is not a sub-type of object<SMW\DIWikiPage>. It seems like you assume a child class of the class SMWDataItem to be always present.

This check looks for parameters that are defined as one type in their type hint or doc comment but seem to be used as a narrower type, i.e an implementation of an interface or a subclass.

Consider changing the type of the parameter or doing an instanceof check before assuming your parameter is of the expected type.

Loading history...
70
		);
71
72 2
		$propertyValues = array();
73
74
		// Get the group from the subobject that contained the matchable
75
		// condition from the preceding filterOnChange process
76 2
		foreach ( $subSemanticDataMatch as $hash => $value ) {
77 1
			foreach ( $value as $sobj ) {
78
				if (
79 1
					( $hash === $dataItem->getHash() ) &&
80 1
					( $subSemanticData = $semanticData->findSubSemanticData( $sobj ) ) !== array() ) {
81 1
					$propertyValues = array_merge( $propertyValues, $subSemanticData->getPropertyValues( $property ) );
82
				}
83
			}
84
		}
85
86 2
		return $propertyValues;
87
	}
88
89
	/**
90
	 * @since 1.0
91
	 *
92
	 * @param array $subSemanticDataMatch
93
	 *
94
	 * @return Closure
95
	 */
96
	public function getNotificationsToGroupListAsCallback( array $subSemanticDataMatch ) {
97 1
		return function( $dataItem ) use( $subSemanticDataMatch ) {
98
			return $this->findNotificationsToGroupList( $dataItem, $subSemanticDataMatch );
99 1
		};
100
	}
101
102
}
103