This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
0 ignored issues
–
show
|
|||
2 | /** |
||
3 | * WP GreatSchools API |
||
4 | * |
||
5 | * @package WP-GreatSchools-API |
||
6 | */ |
||
7 | /* |
||
8 | * Plugin Name: WP GreatSchools API |
||
9 | * Plugin URI: https://github.com/wp-api-libraries/wp-greatschools-api |
||
10 | * Description: Perform API requests to GreatSchools in WordPress. |
||
11 | * Author: WP API Libraries |
||
12 | * Version: 1.0.0 |
||
13 | * Author URI: https://wp-api-libraries.com |
||
14 | * GitHub Plugin URI: https://github.com/wp-api-libraries/wp-greatschools-api |
||
15 | * GitHub Branch: master |
||
16 | */ |
||
17 | /* Exit if accessed directly */ |
||
18 | if ( ! defined( 'ABSPATH' ) ) { exit; } |
||
19 | if ( ! class_exists( 'GreatSchoolsAPI' ) ) { |
||
20 | /** |
||
21 | * GreatSchools API Class. |
||
22 | */ |
||
23 | class GreatSchoolsAPI { |
||
0 ignored issues
–
show
PSR1 recommends that each class must be in a namespace of at least one level to avoid collisions.
You can fix this by adding a namespace to your class: namespace YourVendor;
class YourClass { }
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries. ![]() |
|||
24 | /** |
||
25 | * API Key. |
||
26 | * |
||
27 | * @var string |
||
28 | */ |
||
29 | static private $api_key; |
||
30 | /** |
||
31 | * Output Type. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | static private $output; |
||
36 | /** |
||
37 | * BaseAPI Endpoint |
||
38 | * |
||
39 | * @var string |
||
40 | * @access public |
||
41 | */ |
||
42 | public $base_uri = 'http://api.greatschools.org/schools/'; |
||
43 | /** |
||
44 | * __construct function. |
||
45 | * |
||
46 | * @access public |
||
47 | * @param mixed $api_key API Key |
||
48 | * @param string $output (default: 'json') Output. |
||
49 | * @return void |
||
0 ignored issues
–
show
Comprehensibility
Best Practice
introduced
by
Adding a
@return annotation to constructors is generally not recommended as a constructor does not have a meaningful return value.
Adding a Please refer to the PHP core documentation on constructors. ![]() |
|||
50 | */ |
||
51 | public function __construct( $api_key, $output = 'json' ) { |
||
52 | static::$api_key = $api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
53 | static::$output = $output; |
||
0 ignored issues
–
show
Since
$output is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $output to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
54 | } |
||
55 | /** |
||
56 | * Fetch the request from the API. |
||
57 | * |
||
58 | * @access private |
||
59 | * @param mixed $request Request URL. |
||
60 | * @return $body Body. |
||
0 ignored issues
–
show
The doc-type
$body could not be parsed: Unknown type name "$body" at position 0. (view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. ![]() |
|||
61 | */ |
||
62 | View Code Duplication | private function fetch( $request ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
63 | $response = wp_remote_get( $request ); |
||
64 | $code = wp_remote_retrieve_response_code( $response ); |
||
65 | if ( 200 !== $code ) { |
||
66 | return new WP_Error( 'response-error', sprintf( __( 'Server response code: %d', 'text-domain' ), $code ) ); |
||
67 | } |
||
68 | $body = wp_remote_retrieve_body( $response ); |
||
69 | return $body; |
||
70 | } |
||
71 | /** |
||
72 | * get_schools function. |
||
73 | * |
||
74 | * @access public |
||
75 | * @param mixed $state State. |
||
76 | * @param mixed $city City. |
||
77 | * @return void |
||
78 | */ |
||
79 | View Code Duplication | public function get_schools( $state, $city ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
80 | $request = $this->base_uri . $state . '/' . $city . '?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
81 | $xml = simplexml_load_file( $request ); |
||
82 | $json = wp_json_encode( $xml ); |
||
83 | $results = json_decode( $json, true ); |
||
84 | return $results; |
||
85 | } |
||
86 | /** |
||
87 | * get_nearby_schools function. |
||
88 | * |
||
89 | * @access public |
||
90 | * @param mixed $state State. |
||
91 | * @param mixed $zip Zip. |
||
92 | * @param mixed $city City. |
||
93 | * @param mixed $address Address. |
||
94 | * @param mixed $latitude Latitude. |
||
95 | * @param mixed $longitude Longitude. |
||
96 | * @param mixed $school_type School Type. |
||
97 | * @param mixed $level_code Level Code. |
||
98 | * @param mixed $radius Radius. |
||
99 | * @param mixed $limit Limit. |
||
100 | * @return void |
||
101 | */ |
||
102 | public function get_nearby_schools( $state, $zip, $city, $address, $latitude, $longitude, $school_type, $level_code, $radius, $limit ) { |
||
0 ignored issues
–
show
|
|||
103 | } |
||
104 | /** |
||
105 | * Returns a profile data for a specific school. |
||
106 | * |
||
107 | * @access public |
||
108 | * @param mixed $state State. |
||
109 | * @param mixed $school_id School ID. |
||
110 | * @return void |
||
111 | */ |
||
112 | View Code Duplication | public function get_school( $state, $school_id ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
113 | $request = $this->base_uri . $state . '/'. $school_id .'?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
114 | $xml = simplexml_load_file( $request ); |
||
115 | $json = wp_json_encode( $xml ); |
||
116 | $results = json_decode( $json, true ); |
||
117 | return $results; |
||
118 | } |
||
119 | /** |
||
120 | * Returns a list of schools based on a search string. |
||
121 | * |
||
122 | * @access public |
||
123 | * @param mixed $state State. |
||
124 | * @param mixed $query_string Query String. |
||
125 | * @return void |
||
126 | */ |
||
127 | View Code Duplication | public function search_for_schools( $state, $query_string, $level_code, $sort, $limit ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
128 | $request = $this->base_uri . '/search/schools?key=' . static::$api_key . '&state=' . $state . '&q='. $query_string .'&levelCode='. $level_code .'&sort='. $sort .'&limit=' . $limit; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
129 | $xml = simplexml_load_file( $request ); |
||
130 | $json = wp_json_encode( $xml ); |
||
131 | $results = json_decode( $json, true ); |
||
132 | return $results; |
||
133 | } |
||
134 | /** |
||
135 | * Returns a list of the most recent reviews for a school or for any schools in a city. |
||
136 | * |
||
137 | * @access public |
||
138 | * @param mixed $state State. |
||
139 | * @param mixed $city City. |
||
140 | * @param mixed $school_id School ID. |
||
141 | * @param mixed $cutoffage Cut Off Age. |
||
142 | * @param mixed $limit Limit. |
||
143 | * @param mixed $topic_id Topic ID. |
||
144 | * @return void |
||
145 | */ |
||
146 | View Code Duplication | public function get_school_reviews( $state, $city, $school_id, $cutoffage, $limit, $topic_id ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
147 | $request = $this->base_uri . '/reviews/school/' . $state . '/'. $school_id .'?key=' . static::$api_key . '&limit='. $limit .'&cutoffAge='. $cutoffage .'&topicId=' . $topic_id; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
148 | $xml = simplexml_load_file( $request ); |
||
149 | $json = wp_json_encode( $xml ); |
||
150 | $results = json_decode( $json, true ); |
||
151 | return $results; |
||
152 | } |
||
153 | /** |
||
154 | * Returns a list of topics available for topical reviews. |
||
155 | * |
||
156 | * @access public |
||
157 | * @return void |
||
158 | */ |
||
159 | public function get_review_topics() { |
||
160 | $request = $this->base_uri . '/reviews/reviewTopics?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
161 | $xml = simplexml_load_file( $request ); |
||
162 | $json = wp_json_encode( $xml ); |
||
163 | $results = json_decode( $json, true ); |
||
164 | return $results; |
||
165 | } |
||
166 | /** |
||
167 | * Returns test and rank data for a specific school. |
||
168 | * |
||
169 | * @access public |
||
170 | * @param mixed $state State. |
||
171 | * @param mixed $school_id School ID. |
||
172 | * @return void |
||
173 | */ |
||
174 | View Code Duplication | public function get_school_test_scores( $state, $school_id ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
175 | $request = $this->base_uri . '/school/tests/' . $state . '/'. $school_id .'?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
176 | $xml = simplexml_load_file( $request ); |
||
177 | $json = wp_json_encode( $xml ); |
||
178 | $results = json_decode( $json, true ); |
||
179 | return $results; |
||
180 | } |
||
181 | /** |
||
182 | * Returns census and profile data for a school. |
||
183 | * |
||
184 | * @access public |
||
185 | * @param mixed $state State. |
||
186 | * @param mixed $school_id School ID. |
||
187 | * @return void |
||
188 | */ |
||
189 | View Code Duplication | public function get_school_census_data( $state, $school_id ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
190 | $request = $this->base_uri . '/school/census/' . $state . '/'. $school_id .'?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
191 | $xml = simplexml_load_file( $request ); |
||
192 | $json = wp_json_encode( $xml ); |
||
193 | $results = json_decode( $json, true ); |
||
194 | return $results; |
||
195 | } |
||
196 | /** |
||
197 | * Returns information about a city. |
||
198 | * |
||
199 | * @access public |
||
200 | * @param mixed $state State. |
||
201 | * @param mixed $city City. |
||
202 | * @return void |
||
203 | */ |
||
204 | View Code Duplication | public function get_city_schools( $state, $city ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
205 | $request = $this->base_uri . '/cities/' . $state . '/'. $city .'?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
206 | $xml = simplexml_load_file( $request ); |
||
207 | $json = wp_json_encode( $xml ); |
||
208 | $results = json_decode( $json, true ); |
||
209 | return $results; |
||
210 | } |
||
211 | /** |
||
212 | * Returns a list of cities near another city. |
||
213 | * |
||
214 | * @access public |
||
215 | * @param mixed $state State. |
||
216 | * @param mixed $city City. |
||
217 | * @param mixed $radius Radius. |
||
218 | * @param mixed $sort Sort. |
||
219 | * @return void |
||
220 | */ |
||
221 | View Code Duplication | public function get_nearby_cities( $state, $city, $radius, $sort = 'rating' ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
222 | $request = $this->base_uri . '/cities/nearby/' . $state . '/'. $city .'?key=' . static::$api_key . '&radius='. $radius .'&sort=' . $sort; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
223 | $xml = simplexml_load_file( $request ); |
||
224 | $json = wp_json_encode( $xml ); |
||
225 | $results = json_decode( $json, true ); |
||
226 | return $results; |
||
227 | } |
||
228 | /** |
||
229 | * get_districts function. |
||
230 | * |
||
231 | * @access public |
||
232 | * @param mixed $state State. |
||
233 | * @param mixed $city City. |
||
234 | * @return void |
||
235 | */ |
||
236 | View Code Duplication | public function get_districts( $state, $city ) { |
|
0 ignored issues
–
show
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. ![]() |
|||
237 | $request = $this->base_uri . '/districts/' . $state . '/'. $city .'?key=' . static::$api_key; |
||
0 ignored issues
–
show
Since
$api_key is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self , or increasing the visibility of $api_key to at least protected.
Let’s assume you have a class which uses late-static binding: class YourClass
{
private static $someVariable;
public static function getSomeVariable()
{
return static::$someVariable;
}
}
The code above will run fine in your PHP runtime. However, if you now create a
sub-class and call the class YourSubClass extends YourClass { }
YourSubClass::getSomeVariable(); // Will cause an access error.
In the case above, it makes sense to update class SomeClass
{
private static $someVariable;
public static function getSomeVariable()
{
return self::$someVariable; // self works fine with private.
}
}
![]() |
|||
238 | $xml = simplexml_load_file( $request ); |
||
239 | $json = wp_json_encode( $xml ); |
||
240 | $results = json_decode( $json, true ); |
||
241 | return $results; |
||
242 | } |
||
243 | } |
||
244 | } |
||
245 |
The PSR-1: Basic Coding Standard recommends that a file should either introduce new symbols, that is classes, functions, constants or similar, or have side effects. Side effects are anything that executes logic, like for example printing output, changing ini settings or writing to a file.
The idea behind this recommendation is that merely auto-loading a class should not change the state of an application. It also promotes a cleaner style of programming and makes your code less prone to errors, because the logic is not spread out all over the place.
To learn more about the PSR-1, please see the PHP-FIG site on the PSR-1.