imFORZA /
re-pro
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 Walkscore API |
||
| 4 | * |
||
| 5 | * @package WP-Walkscore-API |
||
| 6 | */ |
||
| 7 | /* |
||
| 8 | * Plugin Name: WP WalkScore API |
||
| 9 | * Plugin URI: https://github.com/wp-api-libraries/wp-walkscore-api |
||
| 10 | * Description: Perform API requests to Walkscore 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-walkscore-api |
||
| 15 | * GitHub Branch: master |
||
| 16 | */ |
||
| 17 | /* Exit if accessed directly. */ |
||
| 18 | if ( ! defined( 'ABSPATH' ) ) { exit; } |
||
| 19 | /* Check if class exists. */ |
||
| 20 | if ( ! class_exists( 'WalkscoreAPI' ) ) { |
||
| 21 | /** |
||
| 22 | * Walkscore API Class. |
||
| 23 | */ |
||
| 24 | class WalkscoreAPI { |
||
|
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. Loading history...
|
|||
| 25 | /** |
||
| 26 | * API Key. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | static private $wsapikey; |
||
| 31 | /** |
||
| 32 | * Return format. XML or JSON. |
||
| 33 | * |
||
| 34 | * @var [string |
||
| 35 | */ |
||
| 36 | static private $output; |
||
| 37 | /** |
||
| 38 | * URL to the API. |
||
| 39 | * |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | private $base_uri = 'http://api.walkscore.com'; |
||
| 43 | /** |
||
| 44 | * __construct function. |
||
| 45 | * |
||
| 46 | * @access public |
||
| 47 | * @param mixed $wsapikey API Key. |
||
| 48 | * @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. Loading history...
|
|||
| 49 | */ |
||
| 50 | public function __construct( $wsapikey, $output = 'json' ) { |
||
| 51 | static::$wsapikey = $wsapikey; |
||
|
0 ignored issues
–
show
Since
$wsapikey is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $wsapikey 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.
}
}
Loading history...
|
|||
| 52 | 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.
}
}
Loading history...
|
|||
| 53 | } |
||
| 54 | /** |
||
| 55 | * Fetch the request from the API. |
||
| 56 | * |
||
| 57 | * @access private |
||
| 58 | * @param mixed $request Request URL. |
||
| 59 | * @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. Loading history...
|
|||
| 60 | */ |
||
| 61 | 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. Loading history...
|
|||
| 62 | $response = wp_remote_get( $request ); |
||
| 63 | $code = wp_remote_retrieve_response_code( $response ); |
||
| 64 | if ( 200 !== $code ) { |
||
| 65 | return new WP_Error( 'response-error', sprintf( __( 'Server response code: %d', 'text-domain' ), $code ) ); |
||
| 66 | } |
||
| 67 | $body = wp_remote_retrieve_body( $response ); |
||
| 68 | return json_decode( $body ); |
||
| 69 | } |
||
| 70 | /** |
||
| 71 | * Get Walkscore (https://www.walkscore.com/professional/api.php) |
||
| 72 | * |
||
| 73 | * @access public |
||
| 74 | * @param mixed $wsapikey Your Walk Score API Key. Contact us to get one. Required. |
||
|
0 ignored issues
–
show
There is no parameter named
$wsapikey. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
|||
| 75 | * @param mixed $latitude The latitude of the requested location. Required. |
||
| 76 | * @param mixed $longitude The longitude of the requested location. Required. |
||
| 77 | * @param mixed $address The URL encoded address. Required. |
||
| 78 | * @param mixed $format Return results in XML or JSON (defaults to XML). |
||
|
0 ignored issues
–
show
There is no parameter named
$format. Was it maybe removed?
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. Consider the following example. The parameter /**
* @param array $germany
* @param array $island
* @param array $italy
*/
function finale($germany, $island) {
return "2:1";
}
The most likely cause is that the parameter was removed, but the annotation was not. Loading history...
|
|||
| 79 | * @return void |
||
| 80 | */ |
||
| 81 | function get_walkscore( $latitude, $longitude, $address ) { |
||
|
0 ignored issues
–
show
|
|||
| 82 | View Code Duplication | if ( empty( $latitude ) || empty( $longitude ) || empty( $address ) ) { |
|
|
0 ignored issues
–
show
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...
|
|||
| 83 | return new WP_Error( 'required-fields', __( 'Required fields are empty.', 'text-domain' ) ); |
||
| 84 | } |
||
| 85 | $request = $this->base_uri . '/score?format=' . static::$output . '&wsapikey=' . static::$wsapikey . '&lat=' . $latitude . '&lon=' . $longitude . '&address=' . $address; |
||
|
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.
}
}
Loading history...
Since
$wsapikey is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $wsapikey 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.
}
}
Loading history...
|
|||
| 86 | return $this->fetch( $request ); |
||
| 87 | } |
||
| 88 | /** |
||
| 89 | * get_transit_score function. |
||
| 90 | * |
||
| 91 | * @access public |
||
| 92 | * @param mixed $latitude |
||
| 93 | * @param mixed $longitude |
||
| 94 | * @param mixed $city |
||
| 95 | * @param mixed $state |
||
| 96 | * @param mixed $country |
||
| 97 | * @param mixed $research |
||
| 98 | * @return void |
||
| 99 | */ |
||
| 100 | function get_transit_score( $latitude, $longitude, $city, $state, $country, $research ) { |
||
|
0 ignored issues
–
show
|
|||
| 101 | View Code Duplication | if ( empty( $latitude ) || empty( $longitude ) || empty( $city ) || empty( $state ) ) { |
|
|
0 ignored issues
–
show
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...
|
|||
| 102 | return new WP_Error( 'required-fields', __( 'Required fields are empty.', 'text-domain' ) ); |
||
| 103 | } |
||
| 104 | $request = $this->base_uri . '/transit/score/?wsapikey=' . static::$wsapikey . '&lat=' . $latitude . '&lon=' . $longitude . '&city=' . $city . '&state=' . $state . '&format=' . $output; |
||
|
0 ignored issues
–
show
Since
$wsapikey is declared private, accessing it with static will lead to errors in possible sub-classes; consider using self, or increasing the visibility of $wsapikey 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.
}
}
Loading history...
|
|||
| 105 | return $this->fetch( $request ); |
||
| 106 | } |
||
| 107 | function get_transit_stop_search() { |
||
|
0 ignored issues
–
show
|
|||
| 108 | } |
||
| 109 | function get_transit_network_search() { |
||
|
0 ignored issues
–
show
|
|||
| 110 | } |
||
| 111 | function get_transit_stop_details() { |
||
|
0 ignored issues
–
show
|
|||
| 112 | } |
||
| 113 | function get_transit_route_details() { |
||
|
0 ignored issues
–
show
|
|||
| 114 | } |
||
| 115 | function get_transit_supported_cities() { |
||
|
0 ignored issues
–
show
|
|||
| 116 | } |
||
| 117 | /** |
||
| 118 | * Response code message |
||
| 119 | * |
||
| 120 | * @param [String] $code : Response code to get message from. |
||
|
0 ignored issues
–
show
The doc-type
[String] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. Loading history...
|
|||
| 121 | * @return [String] : Message corresponding to response code sent in. |
||
|
0 ignored issues
–
show
The doc-type
[String] could not be parsed: Unknown type name "" at position 0. [(view supported doc-types)
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types. Loading history...
|
|||
| 122 | */ |
||
| 123 | public function response_code_msg( $code = '' ) { |
||
| 124 | switch ( $code ) { |
||
| 125 | case 1: |
||
| 126 | $msg = __( 'Walk Score successfully returned.', 'text-domain' ); |
||
| 127 | break; |
||
| 128 | case 2: |
||
| 129 | $msg = __( 'Score is being calculated and is not currently available.', 'text-domain' ); |
||
| 130 | break; |
||
| 131 | case 30: |
||
| 132 | $msg = __( 'Invalid latitude/longitude.', 'text-domain' ); |
||
| 133 | break; |
||
| 134 | case 31: |
||
| 135 | $msg = __( 'Walk Score API internal error.', 'text-domain' ); |
||
| 136 | break; |
||
| 137 | case 40: |
||
| 138 | $msg = __( 'Your WSAPIKEY is invalid.', 'text-domain' ); |
||
| 139 | break; |
||
| 140 | case 41: |
||
| 141 | $msg = __( 'Your daily API quota has been exceeded.', 'text-domain' ); |
||
| 142 | break; |
||
| 143 | case 42: |
||
| 144 | $msg = __( 'Your IP address has been blocked.', 'text-domain' ); |
||
| 145 | break; |
||
| 146 | default: |
||
| 147 | $msg = __( 'Sorry, response code is unknown.', 'text-domain' ); |
||
| 148 | break; |
||
| 149 | } |
||
| 150 | return $msg; |
||
| 151 | } |
||
| 152 | } |
||
| 153 | } |
||
| 154 |
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.