Completed
Push — master ( 91c77a...12ca8b )
by Yannick
08:33
created

SpotterLive::addLiveSpotterData()   F

Complexity

Conditions 39
Paths > 20000

Size

Total Lines 250
Code Lines 99

Duplication

Lines 7
Ratio 2.8 %

Importance

Changes 0
Metric Value
cc 39
eloc 99
nc 429496.7295
nop 27
dl 7
loc 250
rs 2
c 0
b 0
f 0

How to fix   Long Method    Complexity    Many Parameters   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

Many Parameters

Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.

There are several approaches to avoid long parameter lists:

1
<?php
2
//$global_query = "SELECT spotter_live.* FROM spotter_live";
3
4
class SpotterLive {
5
	public $db;
6
	static $global_query = "SELECT spotter_live.* FROM spotter_live";
7
8
	function __construct($dbc = null) {
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
9
		$Connection = new Connection($dbc);
10
		$this->db = $Connection->db;
11
	}
12
	    
13
	/**
14
	* Gets all the spotter information based on the latest data entry
15
	*
16
	* @return Array the spotter information
17
	*
18
	*/
19
	public function getLiveSpotterData($limit = '', $sort = '', $filter = array())
20
	{
21
		global $globalDBdriver, $globalLiveInterval;
22
		$Spotter = new Spotter($this->db);
23
		date_default_timezone_set('UTC');
24
25
		$filter_query = '';
26
		if (isset($filter['source']) && !empty($filter['source'])) {
27
			$filter_query = " AND format_source IN ('".implode("','",$filter['source'])."')";
28
		}
29
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
30
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id";
31
		}
32
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
33
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id ";
34
		}
35
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
36
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
37
		}
38
		
39
		$limit_query = '';
40
		if ($limit != '')
41
		{
42
			$limit_array = explode(',', $limit);
43
			$limit_array[0] = filter_var($limit_array[0],FILTER_SANITIZE_NUMBER_INT);
44
			$limit_array[1] = filter_var($limit_array[1],FILTER_SANITIZE_NUMBER_INT);
45
			if ($limit_array[0] >= 0 && $limit_array[1] >= 0)
46
			{
47
				$limit_query = ' LIMIT '.$limit_array[1].' OFFSET '.$limit_array[0];
48
			}
49
		}
50
		$orderby_query = '';
51
		if ($sort != '')
52
		{
53
			$search_orderby_array = $this->getOrderBy();
54
			$orderby_query = ' '.$search_orderby_array[$sort]['sql'];
55
		}
56
57
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
58
		if ($globalDBdriver == 'mysql') {
59
			//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
60
			$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query.$orderby_query;
61
                } else if ($globalDBdriver == 'pgsql') {
62
			$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query.$orderby_query;
63
		}
64
		$spotter_array = $Spotter->getDataFromDB($query.$limit_query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
65
66
		return $spotter_array;
67
	}
68
69
	/**
70
	* Gets Minimal Live Spotter data
71
	*
72
	* @return Array the spotter information
73
	*
74
	*/
75 View Code Duplication
	public function getMinLiveSpotterData($filter = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
76
	{
77
		global $globalDBdriver, $globalLiveInterval;
78
		date_default_timezone_set('UTC');
79
80
		$filter_query = '';
81
		if (isset($filter['source']) && !empty($filter['source'])) {
82
			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
83
		}
84
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
85
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id ";
86
		}
87
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
88
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id ";
89
		}
90
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
91
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
92
		}
93
94
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
95
		if ($globalDBdriver == 'mysql') {
96
//			$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL ".$globalLiveInterval." SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query";
97
//			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao';
98
//			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
99
100
			$query  = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
101
			FROM spotter_live 
102
			INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao';
103
104
//			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date ORDER BY spotter_live.date GROUP BY spotter_live.flightaware_id'.$filter_query;
105
106
			//$query = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk  FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date '.$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao';
107
                } else if ($globalDBdriver == 'pgsql') {
108
            		//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '30 SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate";
109
            		//$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate$orderby_query";
110
			//$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, a.aircraft_shadow FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate '.$filter_query.'INNER JOIN (SELECT * FROM aircraft) a on spotter_live.aircraft_icao = a.icao';
111
			$query  = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
112
			FROM spotter_live
113
			INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ".$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao';
114
		}
115
//		$spotter_array = Spotter->getDataFromDB($query.$limit_query);
116
		//echo $query;
117
118
    		try {
119
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
120
			$sth->execute();
121
		} catch(PDOException $e) {
122
			return "error";
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'error'; (string) is incompatible with the return type documented by SpotterLive::getMinLiveSpotterData of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
123
		}
124
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
125
126
		return $spotter_array;
127
	}
128
129
	/**
130
	* Gets Minimal Live Spotter data since xx seconds
131
	*
132
	* @return Array the spotter information
133
	*
134
	*/
135 View Code Duplication
	public function getMinLastLiveSpotterData($filter = array())
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
136
	{
137
		global $globalDBdriver, $globalLiveInterval;
138
		date_default_timezone_set('UTC');
139
140
		$filter_query = '';
141
		if (isset($filter['source']) && !empty($filter['source'])) {
142
			$filter_query .= " AND format_source IN ('".implode("','",$filter['source'])."') ";
143
		}
144
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
145
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id ";
146
		}
147
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
148
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id ";
149
		}
150
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
151
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
152
		}
153
154
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
155
		if ($globalDBdriver == 'mysql') {
156
157
			$query  = 'SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
158
			FROM spotter_live LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= spotter_live.date
159
			'.$filter_query.'ORDER BY spotter_live.flightaware_id, spotter_live.date';
160
                } else if ($globalDBdriver == 'pgsql') {
161
/*
162
			$query  = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
163
			FROM spotter_live WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date 
164
			".$filter_query.'LEFT JOIN (SELECT aircraft_shadow,icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao ORDER BY spotter_live.flightaware_id, spotter_live.date';
165
*/
166
			$query  = "SELECT a.aircraft_shadow, spotter_live.ident, spotter_live.flightaware_id, spotter_live.aircraft_icao, spotter_live.departure_airport_icao as departure_airport, spotter_live.arrival_airport_icao as arrival_airport, spotter_live.latitude, spotter_live.longitude, spotter_live.altitude, spotter_live.heading, spotter_live.ground_speed, spotter_live.squawk, spotter_live.date, spotter_live.format_source 
167
			FROM spotter_live LEFT JOIN (SELECT aircraft_shadow, icao FROM aircraft) a ON spotter_live.aircraft_icao = a.icao WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= spotter_live.date 
168
			".$filter_query.'ORDER BY spotter_live.flightaware_id, spotter_live.date';
169
//			echo $query;
170
		}
171
172
    		try {
173
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
174
			$sth->execute();
175
		} catch(PDOException $e) {
176
			return "error";
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'error'; (string) is incompatible with the return type documented by SpotterLive::getMinLastLiveSpotterData of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
177
		}
178
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
179
180
		return $spotter_array;
181
	}
182
183
	/**
184
	* Gets number of latest data entry
185
	*
186
	* @return String number of entry
187
	*
188
	*/
189
	public function getLiveSpotterCount($filter = array())
190
	{
191
		global $globalDBdriver, $globalLiveInterval;
192
		$filter_query = '';
193
		if (isset($filter['source']) && !empty($filter['source'])) {
194
			$filter_query = " AND format_source IN ('".implode("','",$filter['source'])."')";
195
		}
196
		if (isset($filter['airlines']) && !empty($filter['airlines'])) {
197
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id";
198
		}
199
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
200
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id ";
201
		}
202
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
203
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
204
		}
205
206
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
207
		if ($globalDBdriver == 'mysql') {
208
            		//$query  = 'SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate'.$filter_query;
209
			$query = 'SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= date'.$filter_query;
210
            	} elseif ($globalDBdriver == 'pgsql') {
211
	                //$query  = "SELECT COUNT(*) as nb FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() AT TIME ZONE 'UTC' - '".$globalLiveInterval." SECONDS'->INTERVAL <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate".$filter_query;
212
			$query = "SELECT COUNT(DISTINCT flightaware_id) as nb FROM spotter_live WHERE CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '".$globalLiveInterval." SECONDS' <= date".$filter_query;
213
                }
214
    		try {
215
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
216
			$sth->execute();
217
		} catch(PDOException $e) {
218
			return "error";
219
		}
220
		$result = $sth->fetch(PDO::FETCH_ASSOC);
221
		return $result['nb'];
222
	}
223
224
	/**
225
	* Gets all the spotter information based on the latest data entry and coord
226
	*
227
	* @return Array the spotter information
228
	*
229
	*/
230
	public function getLiveSpotterDatabyCoord($coord, $filter = array())
231
	{
232
		global $globalDBdriver, $globalLiveInterval;
233
		$Spotter = new Spotter($this->db);
234
		if (!isset($globalLiveInterval)) $globalLiveInterval = '200';
235
		$filter_query = '';
236
		if (isset($filter['source'])) {
237
			$filter_query = " AND format_source IN ('".implode(',',$filter['source'])."')";
238
		}
239
		if (isset($filter['airlines'])) {
240
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_icao IN ('".implode("','",$filter['airlines'])."')) so ON so.flightaware_id = spotter_live.flightaware_id";
241
		}
242
		if (isset($filter['airlinestype']) && !empty($filter['airlinestype'])) {
243
			$filter_query .= " INNER JOIN (SELECT flightaware_id FROM spotter_output WHERE spotter_output.airline_type = '".$filter['airlinestype']."') sa ON sa.flightaware_id = spotter_live.flightaware_id ";
244
		}
245
		if (isset($filter['source_aprs']) && !empty($filter['source_aprs'])) {
246
			$filter_query = " AND format_source = 'aprs' AND source_name IN ('".implode("','",$filter['source_aprs'])."')";
247
		}
248
249 View Code Duplication
		if (is_array($coord)) {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
250
                        $minlong = filter_var($coord[0],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
251
                        $minlat = filter_var($coord[1],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
252
                        $maxlong = filter_var($coord[2],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
253
                        $maxlat = filter_var($coord[3],FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
254
                } else return array();
255
                if ($globalDBdriver == 'mysql') {
256
        		//$query  = "SELECT spotter_output.* FROM spotter_output WHERE spotter_output.flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL ".$globalLiveInterval." SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong.")";
257
        		$query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL '.$globalLiveInterval.' SECOND) <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN '.$minlat.' AND '.$maxlat.' AND spotter_live.longitude BETWEEN '.$minlong.' AND '.$maxlong.' GROUP BY spotter_live.flightaware_id'.$filter_query;
258 View Code Duplication
        	} else if ($globalDBdriver == 'pgsql') {
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
259
            		$query  = "SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE NOW() at time zone 'UTC'  - INTERVAL '".$globalLiveInterval." SECONDS' <= l.date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND spotter_live.latitude BETWEEN ".$minlat." AND ".$maxlat." AND spotter_live.longitude BETWEEN ".$minlong." AND ".$maxlong." GROUP BY spotter_live.flightaware_id".$filter_query;
260
                }
261
                $spotter_array = $Spotter->getDataFromDB($query);
0 ignored issues
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
262
                return $spotter_array;
263
        }
264
265
	/**
266
        * Gets all the spotter information based on a user's latitude and longitude
267
        *
268
        * @return Array the spotter information
269
        *
270
        */
271
        public function getLatestSpotterForLayar($lat, $lng, $radius, $interval)
272
        {
273
    		$Spotter = new Spotter($this->db);
274
                date_default_timezone_set('UTC');
275
276
        if ($lat != '')
277
                {
278
                        if (!is_numeric($lat))
279
                        {
280
                                return false;
281
                        }
282
                }
283
        
284
        if ($lng != '')
285
                {
286
                        if (!is_numeric($lng))
287
                        {
288
                                return false;
289
                        }
290
                }
291
292
                if ($radius != '')
293
                {
294
                        if (!is_numeric($radius))
295
                        {
296
                                return false;
297
                        }
298
                }
299
        
300
        if ($interval != '')
301
                {
302
                        if (!is_string($interval))
303
                        {
304
                                $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
0 ignored issues
show
Unused Code introduced by
$additional_query is not used, you could remove the assignment.

This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.

$myVar = 'Value';
$higher = false;

if (rand(1, 6) > 3) {
    $higher = true;
} else {
    $higher = false;
}

Both the $myVar assignment in line 1 and the $higher assignment in line 2 are dead. The first because $myVar is never used and the second because $higher is always overwritten for every possible time line.

Loading history...
305
                return false;
306
                        } else {
307
                if ($interval == '1m')
308
                {
309
                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';
310
                } else if ($interval == '15m'){
311
                    $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 15 MINUTE) <= spotter_live.date ';
312
                } 
313
            }
314
                } else {
315
         $additional_query = ' AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 MINUTE) <= spotter_live.date ';   
316
        }
317
318
                $query  = "SELECT spotter_live.*, ( 6371 * acos( cos( radians(:lat) ) * cos( radians( latitude ) ) * cos( radians( longitude ) - radians(:lng) ) + sin( radians(:lat) ) * sin( radians( latitude ) ) ) ) AS distance FROM spotter_live 
319
                   WHERE spotter_live.latitude <> '' 
320
                                   AND spotter_live.longitude <> '' 
321
                   ".$additional_query."
0 ignored issues
show
Bug introduced by
The variable $additional_query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
322
                   HAVING distance < :radius  
323
                                   ORDER BY distance";
324
325
                $spotter_array = $Spotter->getDataFromDB($query, array(':lat' => $lat, ':lng' => $lng,':radius' => $radius),$limit_query);
0 ignored issues
show
Bug introduced by
The variable $limit_query does not exist. Did you forget to declare it?

This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.

Loading history...
326
327
                return $spotter_array;
328
        }
329
330
    
331
        /**
332
	* Gets all the spotter information based on a particular callsign
333
	*
334
	* @return Array the spotter information
335
	*
336
	*/
337 View Code Duplication
	public function getLastLiveSpotterDataByIdent($ident)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
338
	{
339
		$Spotter = new Spotter($this->db);
340
		date_default_timezone_set('UTC');
341
342
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
343
                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
344
345
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident));
346
347
		return $spotter_array;
348
	}
349
350
        /**
351
	* Gets all the spotter information based on a particular callsign
352
	*
353
	* @return Array the spotter information
354
	*
355
	*/
356 View Code Duplication
	public function getDateLiveSpotterDataByIdent($ident,$date)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
357
	{
358
		$Spotter = new Spotter($this->db);
359
		date_default_timezone_set('UTC');
360
361
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
362
                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.ident = :ident AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
363
364
                $date = date('c',$date);
365
		$spotter_array = $Spotter->getDataFromDB($query,array(':ident' => $ident,':date' => $date));
366
367
		return $spotter_array;
368
	}
369
370
        /**
371
	* Gets last spotter information based on a particular callsign
372
	*
373
	* @return Array the spotter information
374
	*
375
	*/
376 View Code Duplication
	public function getLastLiveSpotterDataById($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
377
	{
378
		$Spotter = new Spotter($this->db);
379
		date_default_timezone_set('UTC');
380
381
		$id = filter_var($id, FILTER_SANITIZE_STRING);
382
                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
383
384
		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id));
385
386
		return $spotter_array;
387
	}
388
389
        /**
390
	* Gets last spotter information based on a particular callsign
391
	*
392
	* @return Array the spotter information
393
	*
394
	*/
395 View Code Duplication
	public function getDateLiveSpotterDataById($id,$date)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
396
	{
397
		$Spotter = new Spotter($this->db);
398
		date_default_timezone_set('UTC');
399
400
		$id = filter_var($id, FILTER_SANITIZE_STRING);
401
                $query  = 'SELECT spotter_live.* FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l WHERE l.flightaware_id = :id AND l.date <= :date GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate ORDER BY spotter_live.date DESC';
402
                $date = date('c',$date);
403
		$spotter_array = $Spotter->getDataFromDB($query,array(':id' => $id,':date' => $date));
404
405
		return $spotter_array;
406
	}
407
408
        /**
409
	* Gets altitude information based on a particular callsign
410
	*
411
	* @return Array the spotter information
412
	*
413
	*/
414 View Code Duplication
	public function getAltitudeLiveSpotterDataByIdent($ident)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
415
	{
416
417
		date_default_timezone_set('UTC');
418
419
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
420
                $query  = 'SELECT spotter_live.altitude, spotter_live.date FROM spotter_live WHERE spotter_live.ident = :ident';
421
422
    		try {
423
			
424
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
425
			$sth->execute(array(':ident' => $ident));
426
		} catch(PDOException $e) {
427
			return "error";
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'error'; (string) is incompatible with the return type documented by SpotterLive::getAltitudeLiveSpotterDataByIdent of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
428
		}
429
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
430
431
		return $spotter_array;
432
	}
433
434
        /**
435
	* Gets all the spotter information based on a particular id
436
	*
437
	* @return Array the spotter information
438
	*
439
	*/
440 View Code Duplication
	public function getAllLiveSpotterDataById($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
441
	{
442
		date_default_timezone_set('UTC');
443
		$id = filter_var($id, FILTER_SANITIZE_STRING);
444
		$query  = self::$global_query.' WHERE spotter_live.flightaware_id = :id ORDER BY date';
445
//		$spotter_array = Spotter->getDataFromDB($query,array(':id' => $id));
446
447
    		try {
448
			
449
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
450
			$sth->execute(array(':id' => $id));
451
		} catch(PDOException $e) {
452
			return "error";
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'error'; (string) is incompatible with the return type documented by SpotterLive::getAllLiveSpotterDataById of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
453
		}
454
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
455
456
		return $spotter_array;
457
	}
458
459
        /**
460
	* Gets all the spotter information based on a particular ident
461
	*
462
	* @return Array the spotter information
463
	*
464
	*/
465 View Code Duplication
	public function getAllLiveSpotterDataByIdent($ident)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
466
	{
467
		date_default_timezone_set('UTC');
468
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
469
		$query  = self::$global_query.' WHERE spotter_live.ident = :ident';
470
    		try {
471
			
472
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
473
			$sth->execute(array(':ident' => $ident));
474
		} catch(PDOException $e) {
475
			return "error";
0 ignored issues
show
Bug Best Practice introduced by
The return type of return 'error'; (string) is incompatible with the return type documented by SpotterLive::getAllLiveSpotterDataByIdent of type array.

If you return a value from a function or method, it should be a sub-type of the type that is given by the parent type f.e. an interface, or abstract method. This is more formally defined by the Lizkov substitution principle, and guarantees that classes that depend on the parent type can use any instance of a child type interchangably. This principle also belongs to the SOLID principles for object oriented design.

Let’s take a look at an example:

class Author {
    private $name;

    public function __construct($name) {
        $this->name = $name;
    }

    public function getName() {
        return $this->name;
    }
}

abstract class Post {
    public function getAuthor() {
        return 'Johannes';
    }
}

class BlogPost extends Post {
    public function getAuthor() {
        return new Author('Johannes');
    }
}

class ForumPost extends Post { /* ... */ }

function my_function(Post $post) {
    echo strtoupper($post->getAuthor());
}

Our function my_function expects a Post object, and outputs the author of the post. The base class Post returns a simple string and outputting a simple string will work just fine. However, the child class BlogPost which is a sub-type of Post instead decided to return an object, and is therefore violating the SOLID principles. If a BlogPost were passed to my_function, PHP would not complain, but ultimately fail when executing the strtoupper call in its body.

Loading history...
476
		}
477
		$spotter_array = $sth->fetchAll(PDO::FETCH_ASSOC);
478
		return $spotter_array;
479
	}
480
481
482
	/**
483
	* Deletes all info in the table
484
	*
485
	* @return String success or false
486
	*
487
	*/
488 View Code Duplication
	public function deleteLiveSpotterData()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
489
	{
490
		global $globalDBdriver;
491
		if ($globalDBdriver == 'mysql') {
492
			//$query  = "DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE) >= spotter_live.date";
493
			$query  = 'DELETE FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(),INTERVAL 9 HOUR) >= spotter_live.date';
494
            		//$query  = "DELETE FROM spotter_live WHERE spotter_live.id IN (SELECT spotter_live.id FROM spotter_live INNER JOIN (SELECT l.flightaware_id, max(l.date) as maxdate FROM spotter_live l GROUP BY l.flightaware_id) s on spotter_live.flightaware_id = s.flightaware_id AND spotter_live.date = s.maxdate AND DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) >= spotter_live.date)";
495
496
		} elseif ($globalDBdriver == 'pgsql') {
497
			$query  = "DELETE FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date";
498
		}
499
        
500
    		try {
501
			
502
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
503
			$sth->execute();
504
		} catch(PDOException $e) {
505
			return "error";
506
		}
507
508
		return "success";
509
	}
510
511
	/**
512
	* Deletes all info in the table for aircraft not seen since 2 HOUR
513
	*
514
	* @return String success or false
515
	*
516
	*/
517
	public function deleteLiveSpotterDataNotUpdated()
518
	{
519
		global $globalDBdriver, $globalDebug;
520
		if ($globalDBdriver == 'mysql') {
521
			//$query = 'SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE DATE_SUB(UTC_TIMESTAMP(), INTERVAL 1 HOUR) < spotter_live.date) LIMIT 800 OFFSET 0';
522
    			$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND DATE_SUB(UTC_TIMESTAMP(), INTERVAL 2 HOUR) >= s.max_date LIMIT 1200 OFFSET 0";
523
    			try {
524
				
525
				$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
526
				$sth->execute();
527
			} catch(PDOException $e) {
528
				return "error";
529
			}
530
			$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
531
                        $i = 0;
532
                        $j =0;
533
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
534
			foreach($all as $row)
535
			{
536
				$i++;
537
				$j++;
538
				if ($j == 30) {
539
					if ($globalDebug) echo ".";
540
				    	try {
541
						
542
						$sth = $this->db->prepare(substr($query_delete,0,-1).")");
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
543
						$sth->execute();
544
					} catch(PDOException $e) {
545
						return "error";
546
					}
547
                                	$query_delete = 'DELETE FROM spotter_live WHERE flightaware_id IN (';
548
                                	$j = 0;
549
				}
550
				$query_delete .= "'".$row['flightaware_id']."',";
551
			}
552
			if ($i > 0) {
553
    				try {
554
					
555
					$sth = $this->db->prepare(substr($query_delete,0,-1).")");
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
556
					$sth->execute();
557
				} catch(PDOException $e) {
558
					return "error";
559
				}
560
			}
561
			return "success";
562
		} elseif ($globalDBdriver == 'pgsql') {
563
			//$query = "SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' >= spotter_live.date AND spotter_live.flightaware_id NOT IN (SELECT flightaware_id FROM spotter_live WHERE NOW() AT TIME ZONE 'UTC' - INTERVAL '9 HOURS' < spotter_live.date) LIMIT 800 OFFSET 0";
564
    			//$query = "SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0";
565
    			$query = "DELETE FROM spotter_live WHERE flightaware_id IN (SELECT spotter_live.flightaware_id FROM spotter_live INNER JOIN (SELECT flightaware_id,MAX(date) as max_date FROM spotter_live GROUP BY flightaware_id) s ON s.flightaware_id = spotter_live.flightaware_id AND NOW() AT TIME ZONE 'UTC' - INTERVAL '2 HOURS' >= s.max_date LIMIT 800 OFFSET 0)";
566
    			try {
567
				
568
				$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
569
				$sth->execute();
570
			} catch(PDOException $e) {
571
				return "error";
572
			}
573
/*			$query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN (";
574
                        $i = 0;
575
                        $j =0;
576
			$all = $sth->fetchAll(PDO::FETCH_ASSOC);
577
			foreach($all as $row)
578
			{
579
				$i++;
580
				$j++;
581
				if ($j == 100) {
582
					if ($globalDebug) echo ".";
583
				    	try {
584
						
585
						$sth = $this->db->query(substr($query_delete,0,-1).")");
586
						//$sth->execute();
587
					} catch(PDOException $e) {
588
						return "error";
589
					}
590
                                	$query_delete = "DELETE FROM spotter_live WHERE flightaware_id IN (";
591
                                	$j = 0;
592
				}
593
				$query_delete .= "'".$row['flightaware_id']."',";
594
			}
595
			if ($i > 0) {
596
    				try {
597
					
598
					$sth = $this->db->query(substr($query_delete,0,-1).")");
599
					//$sth->execute();
600
				} catch(PDOException $e) {
601
					return "error";
602
				}
603
			}
604
*/
605
			return "success";
606
		}
607
	}
608
609
	/**
610
	* Deletes all info in the table for an ident
611
	*
612
	* @return String success or false
613
	*
614
	*/
615 View Code Duplication
	public function deleteLiveSpotterDataByIdent($ident)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
616
	{
617
		$ident = filter_var($ident, FILTER_SANITIZE_STRING);
618
		$query  = 'DELETE FROM spotter_live WHERE ident = :ident';
619
        
620
    		try {
621
			
622
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
623
			$sth->execute(array(':ident' => $ident));
624
		} catch(PDOException $e) {
625
			return "error";
626
		}
627
628
		return "success";
629
	}
630
631
	/**
632
	* Deletes all info in the table for an id
633
	*
634
	* @return String success or false
635
	*
636
	*/
637 View Code Duplication
	public function deleteLiveSpotterDataById($id)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
638
	{
639
		$id = filter_var($id, FILTER_SANITIZE_STRING);
640
		$query  = 'DELETE FROM spotter_live WHERE flightaware_id = :id';
641
        
642
    		try {
643
			
644
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
645
			$sth->execute(array(':id' => $id));
646
		} catch(PDOException $e) {
647
			return "error";
648
		}
649
650
		return "success";
651
	}
652
653
654
	/**
655
	* Gets the aircraft ident within the last hour
656
	*
657
	* @return String the ident
658
	*
659
	*/
660 View Code Duplication
	public function getIdentFromLastHour($ident)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
661
	{
662
		global $globalDBdriver, $globalTimezone;
663
		if ($globalDBdriver == 'mysql') {
664
			$query  = 'SELECT spotter_live.ident FROM spotter_live 
665
				WHERE spotter_live.ident = :ident 
666
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 1 HOUR) 
667
				AND spotter_live.date < UTC_TIMESTAMP()';
668
			$query_data = array(':ident' => $ident);
669
		} elseif ($globalDBdriver == 'pgsql') {
670
			$query  = "SELECT spotter_live.ident FROM spotter_live 
671
				WHERE spotter_live.ident = :ident 
672
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '1 HOURS'
673
				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
674
			$query_data = array(':ident' => $ident);
675
		}
676
		
677
		$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
678
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
679
		$ident_result='';
680
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
681
		{
682
			$ident_result = $row['ident'];
683
		}
684
		return $ident_result;
685
        }
686
687
	/**
688
	* Check recent aircraft
689
	*
690
	* @return String the ident
691
	*
692
	*/
693 View Code Duplication
	public function checkIdentRecent($ident)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
694
	{
695
		global $globalDBdriver, $globalTimezone;
696
		if ($globalDBdriver == 'mysql') {
697
			$query  = 'SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
698
				WHERE spotter_live.ident = :ident 
699
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
700
//				AND spotter_live.date < UTC_TIMESTAMP()";
701
			$query_data = array(':ident' => $ident);
702
		} elseif ($globalDBdriver == 'pgsql') {
703
			$query  = "SELECT spotter_live.ident, spotter_live.flightaware_id FROM spotter_live 
704
				WHERE spotter_live.ident = :ident 
705
				AND spotter_live.date >= now() AT TIME ZONE 'UTC' - INTERVAL '30 MINUTES'";
706
//				AND spotter_live.date < now() AT TIME ZONE 'UTC'";
707
			$query_data = array(':ident' => $ident);
708
		}
709
		
710
		$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
711
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
712
		$ident_result='';
713
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
714
		{
715
			$ident_result = $row['flightaware_id'];
716
		}
717
		return $ident_result;
718
        }
719
720
	/**
721
	* Check recent aircraft by ModeS
722
	*
723
	* @return String the ModeS
724
	*
725
	*/
726 View Code Duplication
	public function checkModeSRecent($modes)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
727
	{
728
		global $globalDBdriver, $globalTimezone;
729
		if ($globalDBdriver == 'mysql') {
730
			$query  = 'SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live 
731
				WHERE spotter_live.ModeS = :modes 
732
				AND spotter_live.date >= DATE_SUB(UTC_TIMESTAMP(),INTERVAL 30 MINUTE)'; 
733
//				AND spotter_live.date < UTC_TIMESTAMP()";
734
			$query_data = array(':modes' => $modes);
735
		} elseif ($globalDBdriver == 'pgsql') {
736
			$query  = "SELECT spotter_live.ModeS, spotter_live.flightaware_id FROM spotter_live 
737
				WHERE spotter_live.ModeS = :modes 
738
				AND spotter_live.date >= CURRENT_TIMESTAMP AT TIME ZONE 'UTC' - INTERVAL '30 MINUTE'";
739
//			//	AND spotter_live.date < CURRENT_TIMESTAMP AT TIME ZONE 'UTC'";
740
			$query_data = array(':modes' => $modes);
741
		}
742
		
743
		$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The variable $query does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
744
		$sth->execute($query_data);
0 ignored issues
show
Bug introduced by
The variable $query_data does not seem to be defined for all execution paths leading up to this point.

If you define a variable conditionally, it can happen that it is not defined for all execution paths.

Let’s take a look at an example:

function myFunction($a) {
    switch ($a) {
        case 'foo':
            $x = 1;
            break;

        case 'bar':
            $x = 2;
            break;
    }

    // $x is potentially undefined here.
    echo $x;
}

In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.

Available Fixes

  1. Check for existence of the variable explicitly:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        if (isset($x)) { // Make sure it's always set.
            echo $x;
        }
    }
    
  2. Define a default value for the variable:

    function myFunction($a) {
        $x = ''; // Set a default which gets overridden for certain paths.
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
        }
    
        echo $x;
    }
    
  3. Add a value for the missing path:

    function myFunction($a) {
        switch ($a) {
            case 'foo':
                $x = 1;
                break;
    
            case 'bar':
                $x = 2;
                break;
    
            // We add support for the missing case.
            default:
                $x = '';
                break;
        }
    
        echo $x;
    }
    
Loading history...
745
		$ident_result='';
746
		while($row = $sth->fetch(PDO::FETCH_ASSOC))
747
		{
748
			//$ident_result = $row['spotter_live_id'];
749
			$ident_result = $row['flightaware_id'];
750
		}
751
		return $ident_result;
752
        }
753
754
	/**
755
	* Adds a new spotter data
756
	*
757
	* @param String $flightaware_id the ID from flightaware
758
	* @param String $ident the flight ident
759
	* @param String $aircraft_icao the aircraft type
760
	* @param String $departure_airport_icao the departure airport
761
	* @param String $arrival_airport_icao the arrival airport
762
	* @return String success or false
763
	*
764
	*/
765
	public function addLiveSpotterData($flightaware_id = '', $ident = '', $aircraft_icao = '', $departure_airport_icao = '', $arrival_airport_icao = '', $latitude = '', $longitude = '', $waypoints = '', $altitude = '', $heading = '', $groundspeed = '', $date = '',$departure_airport_time = '', $arrival_airport_time = '', $squawk = '', $route_stop = '', $ModeS = '', $putinarchive = false,$registration = '',$pilot_id = '', $pilot_name = '', $verticalrate = '', $noarchive = false, $ground = false,$format_source = '', $source_name = '', $over_country = '')
0 ignored issues
show
Unused Code introduced by
The parameter $registration is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
766
	{
767
		global $globalURL, $globalArchive, $globalDebug;
768
		$Common = new Common();
769
		$SpotterArchive = new SpotterArchive($this->db);
770
		date_default_timezone_set('UTC');
771
772
		$registration = '';
773
		//getting the registration
774
		
775
776
//		if ($ModeS != '') $registration = Spotter->getAircraftRegistrationBymodeS($ModeS);
777
		
778
779
		//getting the airline information
780
		if ($ident != '')
781
		{
782
			if (!is_string($ident))
783
			{
784
				return false;
785
			} 
786
			/*
787
			else {
788
				//if (!is_numeric(substr($ident, -1, 1)))
789
				if (!is_numeric(substr($ident, 0, 3)))
790
				{
791
					if (is_numeric(substr(substr($ident, 0, 3), -1, 1))) {
792
						$airline_array = Spotter->getAllAirlineInfo(substr($ident, 0, 2));
793
					} elseif (is_numeric(substr(substr($ident, 0, 4), -1, 1))) {
794
						$airline_array = Spotter->getAllAirlineInfo(substr($ident, 0, 3));
795
					} else {
796
						$airline_array = Spotter->getAllAirlineInfo("NA");
797
					}
798
					//print_r($airline_array);
799
					if (count($airline_array) == 0) {
800
					    $airline_array = Spotter->getAllAirlineInfo("NA");
801
					} elseif ($airline_array[0]['icao'] == ''){
802
					    $airline_array = Spotter->getAllAirlineInfo("NA");
803
					}
804
805
				} else {
806
					//echo "\n arg numeric : ".substr($ident, -1, 1)." - ".substr($ident, 0, 3)."\n";
807
					$airline_array = Spotter->getAllAirlineInfo("NA");
808
				}
809
			}
810
		*/
811
		}
812
813
		//getting the aircraft information
814
		if ($aircraft_icao != '')
815
		{
816
			if (!is_string($aircraft_icao))
817
			{
818
				return false;
819
			} 
820
			/*
821
			else {
822
				if ($aircraft_icao == '' || $aircraft_icao == "XXXX")
823
				{
824
					$aircraft_array = Spotter->getAllAircraftInfo("NA");
825
				} else {
826
					$aircraft_array = Spotter->getAllAircraftInfo($aircraft_icao);
827
				}
828
			}
829
			*/
830
		} 
831
		//getting the departure airport information
832
		if ($departure_airport_icao != '')
833
		{
834
			if (!is_string($departure_airport_icao))
835
			{
836
				return false;
837
			} 
838
			/*
839
			else {
840
				$departure_airport_array = Spotter->getAllAirportInfo($departure_airport_icao);
841
			}
842
			*/
843
		}
844
845
		//getting the arrival airport information
846
		if ($arrival_airport_icao != '')
847
		{
848
			if (!is_string($arrival_airport_icao))
849
			{
850
				return false;
851
			}
852
			/*
853
			
854
			 else {
855
				$arrival_airport_array = Spotter->getAllAirportInfo($arrival_airport_icao);
856
			}
857
			*/
858
		}
859
860
861
		if ($latitude != '')
862
		{
863
			if (!is_numeric($latitude))
864
			{
865
				return false;
866
			}
867
		}
868
869
		if ($longitude != '')
870
		{
871
			if (!is_numeric($longitude))
872
			{
873
				return false;
874
			}
875
		}
876
877
		if ($waypoints != '')
878
		{
879
			if (!is_string($waypoints))
880
			{
881
				return false;
882
			}
883
		}
884
885 View Code Duplication
		if ($altitude != '')
1 ignored issue
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
886
		{
887
			if (!is_numeric($altitude))
888
			{
889
				return false;
890
			}
891
		} else $altitude = 0;
892
893
		if ($heading != '')
894
		{
895
			if (!is_numeric($heading))
896
			{
897
				return false;
898
			}
899
		}
900
901
		if ($groundspeed != '')
902
		{
903
			if (!is_numeric($groundspeed))
904
			{
905
				return false;
906
			}
907
		}
908
		date_default_timezone_set('UTC');
909
		if ($date == '') $date = date("Y-m-d H:i:s", time());
910
911
/*
912
		//getting the aircraft image
913
		if ($registration != '')
914
		{
915
			$image_array = Image->getSpotterImage($registration);
916
			if (!isset($image_array[0]['registration']))
917
			{
918
				Image->addSpotterImage($registration);
919
			}
920
		}
921
  */
922
        
923
		$flightaware_id = filter_var($flightaware_id,FILTER_SANITIZE_STRING);
924
		$ident = filter_var($ident,FILTER_SANITIZE_STRING);
925
		$aircraft_icao = filter_var($aircraft_icao,FILTER_SANITIZE_STRING);
926
		$departure_airport_icao = filter_var($departure_airport_icao,FILTER_SANITIZE_STRING);
927
		$arrival_airport_icao = filter_var($arrival_airport_icao,FILTER_SANITIZE_STRING);
928
		$latitude = filter_var($latitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
929
		$longitude = filter_var($longitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
930
		$waypoints = filter_var($waypoints,FILTER_SANITIZE_STRING);
931
		$altitude = filter_var($altitude,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
932
		$heading = filter_var($heading,FILTER_SANITIZE_NUMBER_INT);
933
		$groundspeed = filter_var($groundspeed,FILTER_SANITIZE_NUMBER_FLOAT,FILTER_FLAG_ALLOW_FRACTION);
934
		$squawk = filter_var($squawk,FILTER_SANITIZE_NUMBER_INT);
935
		$route_stop = filter_var($route_stop,FILTER_SANITIZE_STRING);
936
		$ModeS = filter_var($ModeS,FILTER_SANITIZE_STRING);
937
		$pilot_id = filter_var($pilot_id,FILTER_SANITIZE_STRING);
938
		$pilot_name = filter_var($pilot_name,FILTER_SANITIZE_STRING);
939
		$format_source = filter_var($format_source,FILTER_SANITIZE_STRING);
940
		$source_name = filter_var($source_name,FILTER_SANITIZE_STRING);
941
		$over_country = filter_var($over_country,FILTER_SANITIZE_STRING);
942
		$verticalrate = filter_var($verticalrate,FILTER_SANITIZE_NUMBER_INT);
943
944
/*
945
		if (!isset($airline_array) || count($airline_array) == 0) {
946
			$airline_array = Spotter->getAllAirlineInfo('NA');
947
		}
948
		if (!isset($aircraft_array) || count($aircraft_array) == 0) {
949
			$aircraft_array = Spotter->getAllAircraftInfo('NA');
950
            	}
951
            	if ($registration == '') $registration = 'NA';
952
		$airline_name = $airline_array[0]['name'];
953
		$airline_icao = $airline_array[0]['icao'];
954
		$airline_country = $airline_array[0]['country'];
955
		$airline_type = $airline_array[0]['type'];
956
		$aircraft_shadow = $aircraft_array[0]['aircraft_shadow'];
957
		$aircraft_type = $aircraft_array[0]['type'];
958
		$aircraft_manufacturer = $aircraft_array[0]['manufacturer'];
959
*/
960
		$airline_name = '';
961
		$airline_icao = '';
962
		$airline_country = '';
963
		$airline_type = '';
964
		$aircraft_shadow = '';
965
		$aircraft_type = '';
966
		$aircraft_manufacturer = '';
967
968
969
970
		$aircraft_name = '';
971
		if (isset($departure_airport_array[0])) {
0 ignored issues
show
Bug introduced by
The variable $departure_airport_array seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
972
			$departure_airport_name = $departure_airport_array[0]['name'];
973
			$departure_airport_city = $departure_airport_array[0]['city'];
974
			$departure_airport_country = $departure_airport_array[0]['country'];
975
		} else {
976
			$departure_airport_name = '';
977
			$departure_airport_city = '';
978
			$departure_airport_country = '';
979
		}
980
		if (isset($arrival_airport_array[0])) {
0 ignored issues
show
Bug introduced by
The variable $arrival_airport_array seems to never exist, and therefore isset should always return false. Did you maybe rename this variable?

This check looks for calls to isset(...) or empty() on variables that are yet undefined. These calls will always produce the same result and can be removed.

This is most likely caused by the renaming of a variable or the removal of a function/method parameter.

Loading history...
981
			$arrival_airport_name = $arrival_airport_array[0]['name'];
982
			$arrival_airport_city = $arrival_airport_array[0]['city'];
983
			$arrival_airport_country = $arrival_airport_array[0]['country'];
984
		} else {
985
			$arrival_airport_name = '';
986
			$arrival_airport_city = '';
987
			$arrival_airport_country = '';
988
		}
989
            	
990
            	if ($squawk == '' || $Common->isInteger($squawk) == false ) $squawk = NULL;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
991
            	if ($verticalrate == '' || $Common->isInteger($verticalrate) == false ) $verticalrate = NULL;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
992
            	if ($groundspeed == '' || $Common->isInteger($groundspeed) == false ) $groundspeed = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
993
            	if ($heading == '' || $Common->isInteger($heading) == false ) $heading = 0;
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
994
            	
995
		$query  = 'INSERT INTO spotter_live (flightaware_id, ident, registration, airline_name, airline_icao, airline_country, airline_type, aircraft_icao, aircraft_shadow, aircraft_name, aircraft_manufacturer, departure_airport_icao, departure_airport_name, departure_airport_city, departure_airport_country, arrival_airport_icao, arrival_airport_name, arrival_airport_city, arrival_airport_country, latitude, longitude, waypoints, altitude, heading, ground_speed, date, departure_airport_time, arrival_airport_time, squawk, route_stop, ModeS, pilot_id, pilot_name, verticalrate, ground, format_source, source_name, over_country) 
996
		VALUES (:flightaware_id,:ident,:registration,:airline_name,:airline_icao,:airline_country,:airline_type,:aircraft_icao,:aircraft_shadow,:aircraft_type,:aircraft_manufacturer,:departure_airport_icao,:departure_airport_name, :departure_airport_city, :departure_airport_country, :arrival_airport_icao, :arrival_airport_name, :arrival_airport_city, :arrival_airport_country, :latitude,:longitude,:waypoints,:altitude,:heading,:groundspeed,:date,:departure_airport_time,:arrival_airport_time,:squawk,:route_stop,:ModeS, :pilot_id, :pilot_name, :verticalrate, :ground, :format_source, :source_name, :over_country)';
997
998
		$query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_name,':airline_icao' => $airline_icao,':airline_country' => $airline_country,':airline_type' => $airline_type,':aircraft_icao' => $aircraft_icao,':aircraft_shadow' => $aircraft_shadow,':aircraft_type' => $aircraft_type,':aircraft_manufacturer' => $aircraft_manufacturer,':departure_airport_icao' => $departure_airport_icao,':departure_airport_name' => $departure_airport_name,':departure_airport_city' => $departure_airport_city,':departure_airport_country' => $departure_airport_country,':arrival_airport_icao' => $arrival_airport_icao,':arrival_airport_name' => $arrival_airport_name,':arrival_airport_city' => $arrival_airport_city,':arrival_airport_country' => $arrival_airport_country,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date, ':departure_airport_time' => $departure_airport_time,':arrival_airport_time' => $arrival_airport_time, ':squawk' => $squawk,':route_stop' => $route_stop,':ModeS' => $ModeS, ':pilot_id' => $pilot_id, ':pilot_name' => $pilot_name, ':verticalrate' => $verticalrate, ':format_source' => $format_source,':ground' => $ground, ':source_name' => $source_name, ':over_country' => $over_country);
999
		//$query_values = array(':flightaware_id' => $flightaware_id,':ident' => $ident, ':registration' => $registration,':airline_name' => $airline_array[0]['name'],':airline_icao' => $airline_array[0]['icao'],':airline_country' => $airline_array[0]['country'],':airline_type' => $airline_array[0]['type'],':aircraft_icao' => $aircraft_icao,':aircraft_type' => $aircraft_array[0]['type'],':aircraft_manufacturer' => $aircraft_array[0]['manufacturer'],':departure_airport_icao' => $departure_airport_icao,':arrival_airport_icao' => $arrival_airport_icao,':latitude' => $latitude,':longitude' => $longitude, ':waypoints' => $waypoints,':altitude' => $altitude,':heading' => $heading,':groundspeed' => $groundspeed,':date' => $date);
1000
		try {
1001
			
1002
			$sth = $this->db->prepare($query);
1 ignored issue
show
Bug introduced by
The method prepare cannot be called on $this->db (of type null).

Methods can only be called on objects. This check looks for methods being called on variables that have been inferred to never be objects.

Loading history...
1003
			$sth->execute($query_values);
1004
                } catch(PDOException $e) {
1005
                	return "error : ".$e->getMessage();
1006
                }
1007
		if (isset($globalArchive) && $globalArchive && $putinarchive && !$noarchive) {
1008
		    if ($globalDebug) echo '(Add to SBS archive : ';
1009
		    $result =  $SpotterArchive->addSpotterArchiveData($flightaware_id, $ident, $registration, $airline_name, $airline_icao, $airline_country, $airline_type, $aircraft_icao, $aircraft_shadow, $aircraft_name, $aircraft_manufacturer, $departure_airport_icao, $departure_airport_name, $departure_airport_city, $departure_airport_country, $departure_airport_time,$arrival_airport_icao, $arrival_airport_name, $arrival_airport_city, $arrival_airport_country, $arrival_airport_time, $route_stop, $date,$latitude, $longitude, $waypoints, $altitude, $heading, $groundspeed, $squawk, $ModeS, $pilot_id, $pilot_name,$verticalrate,$format_source,$source_name, $over_country);
1010
		    if ($globalDebug) echo $result.')';
1011
		}
1012
		return "success";
1013
1014
	}
1015
1016
	public function getOrderBy()
1017
	{
1018
		$orderby = array("aircraft_asc" => array("key" => "aircraft_asc", "value" => "Aircraft Type - ASC", "sql" => "ORDER BY spotter_live.aircraft_icao ASC"), "aircraft_desc" => array("key" => "aircraft_desc", "value" => "Aircraft Type - DESC", "sql" => "ORDER BY spotter_live.aircraft_icao DESC"),"manufacturer_asc" => array("key" => "manufacturer_asc", "value" => "Aircraft Manufacturer - ASC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer ASC"), "manufacturer_desc" => array("key" => "manufacturer_desc", "value" => "Aircraft Manufacturer - DESC", "sql" => "ORDER BY spotter_live.aircraft_manufacturer DESC"),"airline_name_asc" => array("key" => "airline_name_asc", "value" => "Airline Name - ASC", "sql" => "ORDER BY spotter_live.airline_name ASC"), "airline_name_desc" => array("key" => "airline_name_desc", "value" => "Airline Name - DESC", "sql" => "ORDER BY spotter_live.airline_name DESC"), "ident_asc" => array("key" => "ident_asc", "value" => "Ident - ASC", "sql" => "ORDER BY spotter_live.ident ASC"), "ident_desc" => array("key" => "ident_desc", "value" => "Ident - DESC", "sql" => "ORDER BY spotter_live.ident DESC"), "airport_departure_asc" => array("key" => "airport_departure_asc", "value" => "Departure Airport - ASC", "sql" => "ORDER BY spotter_live.departure_airport_city ASC"), "airport_departure_desc" => array("key" => "airport_departure_desc", "value" => "Departure Airport - DESC", "sql" => "ORDER BY spotter_live.departure_airport_city DESC"), "airport_arrival_asc" => array("key" => "airport_arrival_asc", "value" => "Arrival Airport - ASC", "sql" => "ORDER BY spotter_live.arrival_airport_city ASC"), "airport_arrival_desc" => array("key" => "airport_arrival_desc", "value" => "Arrival Airport - DESC", "sql" => "ORDER BY spotter_live.arrival_airport_city DESC"), "date_asc" => array("key" => "date_asc", "value" => "Date - ASC", "sql" => "ORDER BY spotter_live.date ASC"), "date_desc" => array("key" => "date_desc", "value" => "Date - DESC", "sql" => "ORDER BY spotter_live.date DESC"));
1019
		return $orderby;
1020
	}
1021
1022
}
1023
1024
1025
?>
1 ignored issue
show
Best Practice introduced by
It is not recommended to use PHP's closing tag ?> in files other than templates.

Using a closing tag in PHP files that only contain PHP code is not recommended as you might accidentally add whitespace after the closing tag which would then be output by PHP. This can cause severe problems, for example headers cannot be sent anymore.

A simple precaution is to leave off the closing tag as it is not required, and it also has no negative effects whatsoever.

Loading history...
1026