Completed
Push — master ( f04bbc...eab9d5 )
by Jeroen De
07:09
created

SemanticMaps/src/SM_GeoCoordsValueDescription.php (1 issue)

Labels
Severity

Upgrade to new PHP Analysis Engine

These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more

1
<?php
2
3
use SMW\DataValueFactory;
4
5
/**
6
 * Description of one data value of type Geographical Coordinates.
7
 * 
8
 * @since 0.6
9
 * @ingroup SemanticMaps
10
 * 
11
 * @author Jeroen De Dauw
12
 */
13
class SMGeoCoordsValueDescription extends SMWValueDescription {
14
15
	/**
16
	 * @see SMWDescription::getQueryString
17
	 * 
18
	 * @since 0.6
19
	 * 
20
	 * @param boolean $asValue
21
	 * @return string
22
	 */
23
	public function getQueryString( $asValue = false ) {
24
		if ( $this->getDataItem() !== null ) {
25
			$queryString = DataValueFactory::newDataItemValue( $this->getDataItem(), $this->getPropertyCompat() )->getWikiValue();
26
			return $asValue ? $queryString : "[[$queryString]]";
27
		} else {
28
			return $asValue ? '+' : '';
29
		}
30
	}
31
32
	private function getPropertyCompat() {
33
		return method_exists( $this, 'getProperty' ) ? $this->getProperty() : $this->m_property;
34
	}
35
	
36
	/**
37
	 * @see SMWDescription::getSQLCondition
38
	 *
39
	 * FIXME: store specific code should be in the store component
40
	 *
41
	 * @since 0.6
42
	 * 
43
	 * @param string $tableName
44
	 * @param array $fieldNames
45
	 * @param DatabaseBase $dbs
46
	 * 
47
	 * @return boolean
48
	 */
49
	public function getSQLCondition( $tableName, array $fieldNames, DatabaseBase $dbs ) {
50
		$dataItem = $this->getDataItem();
51
		
52
		// Only execute the query when the description's type is geographical coordinates,
53
		// the description is valid, and the near comparator is used.
54
		if ( $dataItem instanceof SMWDIGeoCoord ) {
0 ignored issues
show
The class SMWDIGeoCoord does not exist. Did you forget a USE statement, or did you not list all dependencies?

This error could be the result of:

1. Missing dependencies

PHP Analyzer uses your composer.json file (if available) to determine the dependencies of your project and to determine all the available classes and functions. It expects the composer.json to be in the root folder of your repository.

Are you sure this class is defined by one of your dependencies, or did you maybe not list a dependency in either the require or require-dev section?

2. Missing use statement

PHP does not complain about undefined classes in ìnstanceof checks. For example, the following PHP code will work perfectly fine:

if ($x instanceof DoesNotExist) {
    // Do something.
}

If you have not tested against this specific condition, such errors might go unnoticed.

Loading history...
55
			switch ( $this->getComparator() ) {
56
				case SMW_CMP_EQ: $comparator = '='; break;
57
				case SMW_CMP_LEQ: $comparator = '<='; break;
58
				case SMW_CMP_GEQ: $comparator = '>='; break;
59
				case SMW_CMP_NEQ: $comparator = '!='; break;
60
				default: return false;
61
			}
62
63
			$lat = $dbs->addQuotes( $dataItem->getLatitude() );
64
			$lon = $dbs->addQuotes( $dataItem->getLongitude() );
65
66
			$conditions = [];
67
68
			$conditions[] = "{$tableName}.$fieldNames[1] $comparator $lat";
69
			$conditions[] = "{$tableName}.$fieldNames[2] $comparator $lon";
70
71
			return implode( ' AND ', $conditions );
72
		}
73
74
		return false;
75
	}
76
	
77
}