NumberFilter   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 70
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 93.94%

Importance

Changes 0
Metric Value
wmc 14
lcom 1
cbo 4
dl 0
loc 70
ccs 31
cts 33
cp 0.9394
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getResourceModules() 0 3 1
B getJsDataForRow() 0 32 9
A isValidFilterForPropertyType() 0 4 3
A buildJsConfig() 0 11 1
1
<?php
2
3
namespace SRF\Filtered\Filter;
4
5
/**
6
 * File holding the SRF_FF_Number class
7
 *
8
 * @author Stephan Gambke
9
 * @file
10
 * @ingroup SemanticResultFormats
11
 */
12
13
use SMWPropertyValue;
14
use SRF\Filtered\ResultItem;
15
16
/**
17
 * The SRF_FF_Number class.
18
 *
19
 * Available parameters for this filter:
20
 *   number filter origin: the point from which the number is measured (address or geo coordinate)
21
 *   number filter property: the property containing the point to which number is measured - not implemented yet
22
 *   number filter unit: the unit in which the number is measured
23
 *
24
 * @ingroup SemanticResultFormats
25
 */
26
class NumberFilter extends Filter {
27
28
	/**
29
	 * Returns the name (string) or names (array of strings) of the resource
30
	 * modules to load.
31
	 *
32
	 * @return string|array
33
	 */
34 1
	public function getResourceModules() {
35 1
		return 'ext.srf.filtered.number-filter';
36
	}
37
38
	/**
39
	 * @param ResultItem $row
40
	 *
41
	 * @return array|null
42
	 */
43 1
	public function getJsDataForRow( ResultItem $row ) {
44 1
		$propertyName = $this->getPrintRequest()->getData()->getInceptiveProperty()->getKey();
45
46 1
		foreach ( $row->getValue() as $field ) {
47
48 1
			$printRequest = $field->getPrintRequest();
49
50 1
			if ( $printRequest->getData() instanceof SMWPropertyValue &&
0 ignored issues
show
Bug introduced by Stephan Gambke
The class SMWPropertyValue does not exist. Is this class maybe located in a folder that is not analyzed, or in a newer version of your dependencies than listed in your composer.lock/composer.json?
Loading history...
51 1
				$printRequest->getData()->getInceptiveProperty()->getKey() === $propertyName &&
52 1
				( $field->reset() instanceof \SMWDINumber || $field->reset() instanceof \SMWDITime )
53
			) {
54
55 1
				$values = []; // contains plain text
56 1
				$value = $field->getNextDataValue();
57
58 1
				while ( $value instanceof \SMWNumberValue || $value instanceof \SMWTimeValue ) {
59
60 1
					if ( $value instanceof \SMWNumberValue ) {
61 1
						$cuv = $value->getConvertedUnitValues();
62 1
						$values[] = $cuv[$value->getCanonicalMainUnit()];
63
					} else {
64
						$values[] = $value->getYear();
65
					}
66 1
					$value = $field->getNextDataItem();
67
				}
68
69 1
				return [ 'values' => $values ];
70
			}
71
		}
72
73
		return null;
74
	}
75
76
	/**
77
	 * @return bool
78
	 */
79 1
	public function isValidFilterForPropertyType() {
80 1
		$typeID = $this->getPrintRequest()->getTypeID();
81 1
		return $typeID === '_num' || $typeID === '_qty' || '_dat';
82
	}
83
84 1
	protected function buildJsConfig() {
85 1
		parent::buildJsConfig();
86 1
		$this->addValueToJsConfig( 'number filter collapsible', 'collapsible' );
87 1
		$this->addValueToJsConfig( 'number filter max value', 'max' );
88 1
		$this->addValueToJsConfig( 'number filter min value', 'min' );
89 1
		$this->addValueToJsConfig( 'number filter step', 'step' );
90 1
		$this->addValueToJsConfig( 'number filter sliders', 'sliders' );
91 1
		$this->addValueToJsConfig( 'number filter label', 'caption', $this->getPrintRequest()->getOutputFormat() );
92 1
		$this->addValueListToJsConfig( 'number filter values', 'values' );
93 1
		$this->addValueListToJsConfig( 'number filter switches', 'switches' );
94 1
	}
95
}
96