Issues (557)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

modules/walkscore/wp-walkscore-api.php (26 issues)

Upgrade to new PHP Analysis Engine

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

1
<?php
0 ignored issues
show
Coding Style Compatibility introduced by
For compatibility and reusability of your code, PSR1 recommends that a file should introduce either new symbols (like classes, functions, etc.) or have side-effects (like outputting something, or including other files), but not both at the same time. The first symbol is defined on line 24 and the first side effect is on line 18.

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.

Loading history...
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
Coding Style Compatibility introduced by
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 @return annotation to a constructor is not recommended, since a constructor does not have a meaningful return value.

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 getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

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 getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

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 $italy is not defined by the method finale(...).

/**
 * @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 $italy is not defined by the method finale(...).

/**
 * @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
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...
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 getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

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 getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

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
The parameter $country 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...
The parameter $research 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...
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...
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 getSomeVariable() on that sub-class, you will receive a runtime error:

class YourSubClass extends YourClass { }

YourSubClass::getSomeVariable(); // Will cause an access error.

In the case above, it makes sense to update SomeClass to use self instead:

class SomeClass
{
    private static $someVariable;

    public static function getSomeVariable()
    {
        return self::$someVariable; // self works fine with private.
    }
}
Loading history...
The variable $output 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...
105
			return $this->fetch( $request );
106
		}
107
		function get_transit_stop_search() {
0 ignored issues
show
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...
108
		}
109
		function get_transit_network_search() {
0 ignored issues
show
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...
110
		}
111
		function get_transit_stop_details() {
0 ignored issues
show
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...
112
		}
113
		function get_transit_route_details() {
0 ignored issues
show
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...
114
		}
115
		function get_transit_supported_cities() {
0 ignored issues
show
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...
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