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 |
||
2 | |||
3 | class JodelAccount |
||
0 ignored issues
–
show
|
|||
4 | { |
||
5 | public $accessToken; |
||
6 | public $expirationDate; |
||
7 | public $refreshToken; |
||
8 | public $distinctId; |
||
9 | public $deviceUid; |
||
10 | |||
11 | //is the Account a Bot or Spider? |
||
12 | public $isBot; |
||
13 | |||
14 | // array of voted Jodels |
||
15 | public $votes; |
||
16 | |||
17 | //Location of the Account |
||
18 | public $location; |
||
19 | |||
20 | function __construct($deviceUid = NULL, $isBot = FALSE) |
||
0 ignored issues
–
show
|
|||
21 | { |
||
22 | if($deviceUid == NULL) |
||
23 | { |
||
24 | $this->deviceUid = $this->createAccount(); |
||
25 | } |
||
26 | else |
||
27 | { |
||
28 | $this->deviceUid = $deviceUid; |
||
29 | } |
||
30 | |||
31 | $this->isBot = $isBot; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 8 spaces
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
32 | $this->location = $this->getLocation(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 1 space but found 5 spaces
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
33 | |||
34 | if(!$this->isTokenFresh()) |
||
35 | { |
||
36 | $this->refreshToken(); |
||
37 | } |
||
38 | $this->accessToken = $this->getAccessToken(); |
||
0 ignored issues
–
show
Equals sign not aligned correctly; expected 1 space but found 2 spaces
This check looks for improperly formatted assignments. Every assignment must have exactly one space before and one space after the equals operator. To illustrate: $a = "a";
$ab = "ab";
$abc = "abc";
will have no issues, while $a = "a";
$ab = "ab";
$abc = "abc";
will report issues in lines 1 and 2. ![]() |
|||
39 | |||
40 | /* if($this->isAccountVerified() != 1) |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
66% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
41 | { |
||
42 | $this->showCaptcha(); |
||
43 | //$this->verifyCaptcha(); |
||
44 | }*/ |
||
45 | } |
||
46 | |||
47 | /* |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
54% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
48 | function showCaptcha() |
||
49 | { |
||
50 | $accountCreator = new GetCaptcha(); |
||
51 | $accountCreator->setAccessToken($this->accessToken); |
||
52 | $captcha = $accountCreator->execute(); |
||
53 | |||
54 | echo $captcha['image_url']; |
||
55 | echo('<br><img width="100%" src="' . $captcha['image_url'] . '">'); |
||
56 | echo "<br>Key: " . $captcha['key']; |
||
57 | echo "<br>"; |
||
58 | |||
59 | //Form |
||
60 | |||
61 | echo '<form method="get">'; |
||
62 | echo '<p>Enter Key (copy pasta from top): <input type="text" value="' . $captcha['key'] . '" name="key" /></p>'; |
||
0 ignored issues
–
show
|
|||
63 | echo '<p>Find the Coons (example: they are on picture 3, 4 and 5. You enter 2-3-4. Becouse we start counting at 0): <input type="text" name="solution" /></p>'; |
||
0 ignored issues
–
show
|
|||
64 | echo '<input type="hidden" name="deviceUid" value="' . $this->deviceUid . '">'; |
||
65 | echo '<input type="hidden" name="pw" value="">'; |
||
66 | echo '<p><input type="submit" /></p>'; |
||
67 | echo '</form>'; |
||
68 | |||
69 | die(); |
||
70 | |||
71 | } |
||
72 | */ |
||
73 | |||
74 | function getCaptcha() |
||
0 ignored issues
–
show
|
|||
75 | { |
||
76 | $accountCreator = new GetCaptcha(); |
||
77 | $accountCreator->setAccessToken($this->accessToken); |
||
78 | $captcha = $accountCreator->execute(); |
||
79 | |||
80 | return array("image_url" => $captcha['image_url'], "key" => $captcha['key']); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
image_url does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
key does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
81 | } |
||
82 | |||
83 | function isAccountVerified() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
84 | { |
||
85 | $accountCreator = new GetUserConfig(); |
||
86 | $accountCreator->setAccessToken($this->accessToken); |
||
87 | $data = $accountCreator->execute(); |
||
88 | |||
89 | //error_log(print_r($data, true)); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
73% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
90 | |||
91 | return $data['verified']; |
||
92 | } |
||
93 | |||
94 | function getGeocodingToken() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
95 | { |
||
96 | $config = parse_ini_file('config/config.ini.php'); |
||
97 | if(!isset($config['geocodingToken']) || |
||
98 | $config['geocodingToken'] == NULL || |
||
99 | $config['geocodingToken'] == '' || |
||
100 | $config['geocodingToken'] == 'xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx') |
||
101 | { |
||
102 | error_log("Please set a Google Maps Geocoding Token!"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Please set a Google Maps Geocoding Token! does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
103 | } |
||
104 | else |
||
105 | { |
||
106 | return $config['geocodingToken']; |
||
107 | } |
||
108 | } |
||
109 | |||
110 | function locationEquals($city) |
||
0 ignored issues
–
show
|
|||
111 | { |
||
112 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
113 | $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
||
114 | |||
115 | $location = new Location(); |
||
116 | |||
117 | View Code Duplication | if ($result->num_rows > 0) |
|
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. ![]() |
|||
118 | { |
||
119 | // output data of each row |
||
120 | while($row = $result->fetch_assoc()) |
||
121 | { |
||
122 | $location->setLat($row['lat']); |
||
123 | $location->setLng($row['lng']); |
||
124 | $location->setCityName($row['name']); |
||
125 | } |
||
126 | } |
||
127 | else |
||
128 | { |
||
129 | error_log("Error no Location found - getLocation"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Error no Location found - getLocation does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
130 | } |
||
131 | |||
132 | if($location->getCityName() == $city) |
||
0 ignored issues
–
show
|
|||
133 | { |
||
134 | return TRUE; |
||
135 | } |
||
136 | else |
||
137 | { |
||
138 | return FALSE; |
||
139 | } |
||
140 | } |
||
141 | |||
142 | function setLocation() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() setLocation uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() setLocation uses the super-global variable $_SERVER which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
143 | { |
||
144 | //Is Channel or City |
||
145 | if(substr($_GET['city'], 0, 1) === '#') |
||
146 | { |
||
147 | return htmlspecialchars($_GET['city']) . " " . $this->location->cityName; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
148 | } |
||
149 | else |
||
150 | { |
||
151 | $url = 'https://maps.googleapis.com/maps/api/geocode/json?address=' . htmlspecialchars($_GET['city']) . '&key=' . $this->getGeocodingToken(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
152 | $result = Requests::post($url); |
||
153 | if(json_decode($result->body, true)['status'] == 'ZERO_RESULTS' || json_decode($result->body, true)['status'] == 'INVALID_REQUEST') |
||
0 ignored issues
–
show
|
|||
154 | { |
||
155 | return "0 results"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
0 results does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
156 | } |
||
157 | else |
||
158 | { |
||
159 | $name = json_decode($result->body, true)['results']['0']['address_components']['0']['long_name']; |
||
160 | $lat = json_decode($result->body, true)['results']['0']['geometry']['location']['lat']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
161 | $lng = json_decode($result->body, true)['results']['0']['geometry']['location']['lng']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
162 | |||
163 | $location = new Location(); |
||
164 | $location->setLat($lat); |
||
165 | $location->setLng($lng); |
||
166 | $location->setCityName($name); |
||
167 | $accountCreator = new UpdateLocation(); |
||
168 | $accountCreator->setLocation($location); |
||
169 | $accountCreator->setAccessToken($this->accessToken); |
||
170 | $data = $accountCreator->execute(); |
||
171 | |||
172 | //safe location to db |
||
173 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
|
|||
174 | |||
175 | if($data == 'Success') |
||
176 | { |
||
177 | $result = $db->query("UPDATE accounts |
||
178 | SET name='" . $name . "', |
||
179 | lat='" . $lat . "', |
||
180 | lng='" . $lng . "' |
||
181 | WHERE access_token='" . $this->accessToken . "'"); |
||
182 | |||
183 | if($result === false) |
||
184 | { |
||
185 | echo "Updating location failed: (" . $db->errno . ") " . $db->error; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Updating location failed: ( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
) does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
186 | } |
||
187 | else |
||
188 | { |
||
189 | user_log('User with JodelDeviceId:' . $this->deviceUid . ' [' . $_SERVER['REMOTE_ADDR'] . '][' . $_SERVER ['HTTP_USER_AGENT'] . '] changed to Location: ' . $name); |
||
0 ignored issues
–
show
|
|||
190 | } |
||
191 | } |
||
192 | |||
193 | return $name; |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | |||
198 | function getLocation() |
||
0 ignored issues
–
show
|
|||
199 | { |
||
200 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
201 | $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
||
202 | |||
203 | $location = new Location(); |
||
204 | |||
205 | View Code Duplication | if ($result->num_rows > 0) |
|
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. ![]() |
|||
206 | { |
||
207 | // output data of each row |
||
208 | while($row = $result->fetch_assoc()) |
||
209 | { |
||
210 | $location->setLat($row['lat']); |
||
211 | $location->setLng($row['lng']); |
||
212 | $location->setCityName($row['name']); |
||
213 | } |
||
214 | } |
||
215 | else |
||
216 | { |
||
217 | echo "Error: 0 results"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Error: 0 results does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
218 | error_log("Error no Location found - getLocation"); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Error no Location found - getLocation does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
219 | } |
||
220 | |||
221 | return $location; |
||
222 | } |
||
223 | |||
224 | function verifyCaptcha() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() verifyCaptcha uses the super-global variable $_GET which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() verifyCaptcha uses the super-global variable $_POST which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
225 | { |
||
226 | if(isset($_GET['deviceUid'])) |
||
227 | { |
||
228 | $deviceUid = $_GET['deviceUid']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
229 | $jodelAccountForVerify = new JodelAccount($deviceUid); |
||
0 ignored issues
–
show
|
|||
230 | } |
||
231 | else if(isset($_POST['deviceUid'])) |
||
232 | { |
||
233 | $deviceUid = $_POST['deviceUid']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
234 | $jodelAccountForVerify = new JodelAccount($deviceUid); |
||
235 | } |
||
236 | else |
||
237 | { |
||
238 | $deviceUid = $this->deviceUid; |
||
0 ignored issues
–
show
$deviceUid 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 ![]() Equals sign not aligned with surrounding assignments; expected 13 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
239 | $jodelAccountForVerify = $this; |
||
240 | } |
||
241 | |||
242 | $solution = $_GET['solution']; |
||
243 | $solution = array_map('intval', explode('-', $solution)); |
||
244 | |||
245 | $accountCreator = new PostCaptcha(); |
||
246 | $accountCreator->setAccessToken($jodelAccountForVerify->accessToken); |
||
247 | $accountCreator->captchaKey = $_GET['key']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
248 | $accountCreator->captchaSolution = $solution; |
||
249 | $verified = $accountCreator->execute(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 24 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
250 | |||
251 | if(isset($verified->status_code)) |
||
252 | { |
||
253 | return $verified->status_code; |
||
254 | } |
||
255 | return $verified['verified']; |
||
256 | } |
||
257 | |||
258 | //ToDo Spider Check |
||
0 ignored issues
–
show
|
|||
259 | function votePostId($postId, $vote) |
||
0 ignored issues
–
show
|
|||
260 | { |
||
261 | if(!$this->isBot) |
||
262 | { |
||
263 | if(!$this->isAccountVerified()) |
||
264 | { |
||
265 | error_log('Account is not Verified! jodelAccount.php Line 279'); |
||
266 | return FALSE; |
||
267 | } |
||
268 | else |
||
0 ignored issues
–
show
This
else statement is empty and can be removed.
This check looks for the These if (rand(1, 6) > 3) {
print "Check failed";
} else {
//print "Check succeeded";
}
could be turned into if (rand(1, 6) > 3) {
print "Check failed";
}
This is much more concise to read. ![]() |
|||
269 | { |
||
270 | |||
271 | } |
||
272 | |||
273 | if(!$this->hasVoted($postId)) |
||
274 | { |
||
275 | if($vote == "up") |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
up does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
276 | { |
||
277 | $accountCreator = new Upvote(); |
||
278 | } |
||
279 | else if($vote == "down") |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
down does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
280 | { |
||
281 | $accountCreator = new Downvote(); |
||
282 | } |
||
283 | |||
284 | $accountCreator->setAccessToken($this->accessToken); |
||
0 ignored issues
–
show
The variable
$accountCreator 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
![]() |
|||
285 | $accountCreator->postId = htmlspecialchars($postId); |
||
286 | $data = $accountCreator->execute(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 19 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
287 | |||
288 | user_log('User voted: ' . print_r($data, true)); |
||
289 | |||
290 | if(array_key_exists('post', $data)) |
||
291 | { |
||
292 | $this->addVoteWithPostIdAndType($postId, $vote); |
||
293 | return TRUE; |
||
294 | } |
||
295 | else if(array_key_exists('error', $data)) |
||
296 | { |
||
297 | error_log('Could not vote - Error: ' . $data['error']); |
||
298 | return FALSE; |
||
299 | } |
||
300 | else |
||
301 | { |
||
302 | error_log('Could not vote: ' . print_r($data, true)); |
||
303 | return FALSE; |
||
304 | } |
||
305 | } |
||
306 | else |
||
307 | { |
||
308 | return FALSE; |
||
309 | } |
||
310 | } |
||
311 | else |
||
312 | { |
||
313 | return FALSE; |
||
314 | } |
||
315 | } |
||
316 | |||
317 | //ToDo Spider Check |
||
0 ignored issues
–
show
|
|||
318 | function sendJodel($location, $view) |
||
0 ignored issues
–
show
sendJodel uses the super-global variable $_POST which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() sendJodel uses the super-global variable $_FILES which is generally not recommended.
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: // Bad
class Router
{
public function generate($path)
{
return $_SERVER['HOST'].$path;
}
}
// Better
class Router
{
private $host;
public function __construct($host)
{
$this->host = $host;
}
public function generate($path)
{
return $this->host.$path;
}
}
class Controller
{
public function myAction(Request $request)
{
// Instead of
$page = isset($_GET['page']) ? intval($_GET['page']) : 1;
// Better (assuming you use the Symfony2 request)
$page = $request->query->get('page', 1);
}
}
![]() |
|||
319 | { |
||
320 | if($this->isAccountVerified() != 1) |
||
321 | { |
||
322 | $this->showCaptcha(); |
||
0 ignored issues
–
show
The method
showCaptcha() does not seem to exist on object<JodelAccount> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
323 | //$this->verifyCaptcha(); |
||
0 ignored issues
–
show
Unused Code
Comprehensibility
introduced
by
84% of this comment could be valid code. Did you maybe forget this after debugging?
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it. The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production. This check looks for comments that seem to be mostly valid code and reports them. ![]() |
|||
324 | } |
||
325 | |||
326 | $accountCreator = new SendJodel(); |
||
327 | |||
328 | if(isset($_POST['ancestor'])) |
||
329 | { |
||
330 | $ancestor = $_POST['ancestor']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 17 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
331 | $accountCreator->ancestor = $ancestor; |
||
332 | } |
||
333 | if(isset($_POST['color'])) |
||
334 | { |
||
335 | $color = $_POST['color']; |
||
336 | switch ($color) { |
||
337 | case '8ABDB0': |
||
338 | $color = '8ABDB0'; |
||
339 | break; |
||
340 | case '9EC41C': |
||
341 | $color = '9EC41C'; |
||
342 | break; |
||
343 | case '06A3CB': |
||
344 | $color = '06A3CB'; |
||
345 | break; |
||
346 | case 'FFBA00': |
||
347 | $color = 'FFBA00'; |
||
348 | break; |
||
349 | case 'DD5F5F': |
||
350 | $color = 'DD5F5F'; |
||
351 | break; |
||
352 | case 'FF9908': |
||
353 | $color = 'FF9908'; |
||
354 | break; |
||
355 | default: |
||
356 | $color = '8ABDB0'; |
||
357 | break; |
||
358 | } |
||
359 | $accountCreator->color = $color; |
||
360 | } |
||
361 | |||
362 | $accountCreatorLocation = new UpdateLocation(); |
||
0 ignored issues
–
show
|
|||
363 | $accountCreatorLocation->setLocation($location); |
||
364 | $accountCreatorLocation->setAccessToken($this->accessToken); |
||
365 | $data = $accountCreatorLocation->execute(); |
||
366 | |||
367 | if($data != 'Success') |
||
368 | { |
||
369 | error_log('Could not set location befor Post: ' . print_r($data, true)); |
||
370 | } |
||
371 | |||
372 | $accountCreator->location = $this->location; |
||
373 | |||
374 | $image = ''; |
||
375 | if(isset($_FILES['image']) && $_FILES['image']['size'] > 0) |
||
376 | { |
||
377 | $image = file_get_contents($_FILES['image']['tmp_name']); |
||
378 | } |
||
379 | |||
380 | $accountCreator->image = $image; |
||
381 | |||
382 | $accountCreator->setAccessToken($this->accessToken); |
||
383 | $data = $accountCreator->execute(); |
||
384 | |||
385 | if(isset($data['error']) && $data['error'] == 'length') |
||
386 | { |
||
387 | $errorMsg = 'Error: The input was to long'; |
||
388 | return $errorMsg; |
||
389 | } |
||
390 | |||
391 | user_log('User posted: ' . print_r($data, true)); |
||
392 | |||
393 | if(isset($_POST['ancestor'])) |
||
394 | { |
||
395 | header('Location: ' . $view->toUrl()); |
||
396 | exit; |
||
0 ignored issues
–
show
The method
sendJodel() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
397 | } |
||
398 | else |
||
399 | { |
||
400 | header('Location: ' . $view->baseUrl); |
||
401 | exit; |
||
0 ignored issues
–
show
The method
sendJodel() contains an exit expression.
An exit expression should only be used in rare cases. For example, if you write a short command line script. In most cases however, using an ![]() |
|||
402 | } |
||
403 | } |
||
404 | |||
405 | function isTokenFresh() |
||
0 ignored issues
–
show
|
|||
406 | { |
||
407 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
408 | $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
||
409 | |||
410 | if ($result->num_rows > 0) |
||
411 | { |
||
412 | // output data of each row |
||
413 | while($row = $result->fetch_assoc()) |
||
414 | { |
||
415 | $expiration_date = $row["expiration_date"]; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
expiration_date does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
416 | } |
||
417 | } |
||
418 | else |
||
419 | { |
||
420 | error_log('0 results'); |
||
421 | } |
||
422 | |||
423 | if($expiration_date <= time()) |
||
0 ignored issues
–
show
The variable
$expiration_date 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
![]() |
|||
424 | { |
||
425 | return FALSE; |
||
426 | } |
||
427 | |||
428 | return TRUE; |
||
429 | } |
||
430 | |||
431 | function refreshToken() |
||
0 ignored issues
–
show
|
|||
432 | { |
||
433 | $accountCreator = new CreateUser(); |
||
434 | $accountCreator->setAccessToken($this->accessToken); |
||
435 | $accountCreator->setDeviceUid($this->deviceUid); |
||
436 | $accountCreator->setLocation($this->location); |
||
437 | $data = $accountCreator->execute(); |
||
438 | |||
439 | $access_token = (string)$data[0]['access_token']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
440 | $expiration_date = $data[0]['expiration_date']; |
||
441 | $device_uid = (string)$data[1]; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
442 | |||
443 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
444 | $result = $db->query("UPDATE accounts |
||
445 | SET access_token='" . $access_token . "', |
||
446 | expiration_date='" . $expiration_date . "' |
||
447 | WHERE device_uid='" . $device_uid . "'"); |
||
448 | |||
449 | View Code Duplication | if($result === false){ |
|
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. ![]() |
|||
450 | error_log("Adding account failed: (" . $db->errno . ") " . $db->error); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Adding account failed: ( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
) does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
451 | } |
||
452 | } |
||
453 | |||
454 | |||
455 | |||
456 | function getAccessToken() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
457 | { |
||
458 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
459 | $result = $db->query("SELECT * FROM accounts WHERE device_uid='" . $this->deviceUid . "'"); |
||
460 | |||
461 | $accessToken; |
||
0 ignored issues
–
show
The variable
$accessToken seems only to be defined at a later point. Did you maybe move this code here without moving the variable definition?
This error can happen if you refactor code and forget to move the variable initialization. Let’s take a look at a simple example: function someFunction() {
$x = 5;
echo $x;
}
The above code is perfectly fine. Now imagine that we re-order the statements: function someFunction() {
echo $x;
$x = 5;
}
In that case, ![]() |
|||
462 | |||
463 | if ($result->num_rows > 0) |
||
464 | { |
||
465 | // output data of each row |
||
466 | while($row = $result->fetch_assoc()) |
||
467 | { |
||
468 | $accessToken = $row['access_token']; |
||
469 | } |
||
470 | } |
||
471 | else |
||
472 | { |
||
473 | error_log('Error: 0 results'); |
||
474 | } |
||
475 | |||
476 | return $accessToken; |
||
0 ignored issues
–
show
The variable
$accessToken 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
![]() |
|||
477 | } |
||
478 | |||
479 | |||
480 | function getKarma() |
||
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
481 | { |
||
482 | $accountCreator = new GetKarma(); |
||
483 | $accountCreator->setAccessToken($this->accessToken); |
||
484 | $data = $accountCreator->execute(); |
||
485 | |||
486 | return $data['karma']; |
||
487 | } |
||
488 | |||
489 | function hasVoted($postId) |
||
0 ignored issues
–
show
|
|||
490 | { |
||
491 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
|
|||
492 | |||
493 | $postId = $db->real_escape_string($postId); |
||
0 ignored issues
–
show
|
|||
494 | |||
495 | $result = $db->query("SELECT id FROM votes WHERE (postId = '" . $postId . "' AND device_uid = '" . $this->deviceUid . "')"); |
||
0 ignored issues
–
show
|
|||
496 | |||
497 | View Code Duplication | if($result === false) |
|
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. ![]() |
|||
498 | { |
||
499 | $error = db_error(); |
||
500 | echo $error; |
||
501 | error_log("Adding Vote failed: (" . $result->errno . ") " . $result->error); |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Adding Vote failed: ( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
) does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
502 | } |
||
503 | |||
504 | if($result->num_rows == 0) |
||
0 ignored issues
–
show
|
|||
505 | { |
||
506 | return FALSE; |
||
507 | } |
||
508 | else |
||
509 | { |
||
510 | return TRUE; |
||
511 | } |
||
512 | } |
||
513 | |||
514 | function addVoteWithPostIdAndType($postId, $voteType) |
||
0 ignored issues
–
show
|
|||
515 | { |
||
516 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
|
|||
517 | |||
518 | $postId = $db->real_escape_string($postId); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
519 | $voteType = $db->real_escape_string($voteType); |
||
0 ignored issues
–
show
|
|||
520 | |||
521 | if($this->hasVoted($postId)) |
||
522 | { |
||
523 | return "Already voted"; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Already voted does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
524 | } |
||
525 | |||
526 | $result = $db->query("INSERT INTO votes (device_uid, postId, type) |
||
527 | VALUES ('" . $this->deviceUid . "','" . $postId . "','" . $voteType . "')"); |
||
528 | |||
529 | View Code Duplication | if($result === false){ |
|
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. ![]() |
|||
530 | $error = db_error(); |
||
531 | echo $error; |
||
532 | echo "Adding Vote failed: (" . $result->errno . ") " . $result->error; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Adding Vote failed: ( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
) does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
533 | } |
||
534 | } |
||
535 | |||
536 | function registerAccount($location) { |
||
0 ignored issues
–
show
|
|||
537 | $accountCreator = new CreateUser(); |
||
538 | $accountCreator->setLocation($location); |
||
539 | $data = $accountCreator->execute(); |
||
540 | |||
541 | $access_token = (string)$data[0]['access_token']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 4 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
542 | $refresh_token = (string)$data[0]['refresh_token']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
543 | $token_type = (string)$data[0]['token_type']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
544 | $expires_in = $data[0]['expires_in']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
545 | $expiration_date = $data[0]['expiration_date']; |
||
546 | $distinct_id = (string)$data[0]['distinct_id']; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
547 | $device_uid = (string)$data[1]; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 6 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
548 | |||
549 | $name = $location->cityName; |
||
550 | $lat = $location->lat; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
551 | $lng = $location->lng; |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 2 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
552 | |||
553 | $db = new DatabaseConnect(); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 5 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
554 | $result = $db->query("INSERT INTO accounts (access_token, refresh_token, token_type, |
||
555 | expires_in, expiration_date, distinct_id, device_uid, name, lat, lng) |
||
556 | VALUES ('" . $access_token . "','" . $refresh_token . "','" . $token_type . |
||
557 | "','" . $expires_in . "','" . $expiration_date . "','" . $distinct_id . |
||
558 | "','" . $device_uid . "','" . $name . "','" . $lat . "','" . $lng . "') "); |
||
559 | |||
560 | $success = TRUE; |
||
0 ignored issues
–
show
$success 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 ![]() |
|||
561 | View Code Duplication | if($result === false){ |
|
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. ![]() |
|||
562 | $error = $db->error(); |
||
0 ignored issues
–
show
The method
error() does not seem to exist on object<DatabaseConnect> .
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces. This is most likely a typographical error or the method has been renamed. ![]() |
|||
563 | echo $error; |
||
564 | echo "Adding account failed: (" . $result->errno . ") " . $result->error; |
||
0 ignored issues
–
show
Coding Style
Comprehensibility
introduced
by
The string literal
Adding account failed: ( does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() Coding Style
Comprehensibility
introduced
by
The string literal
) does not require double quotes, as per coding-style, please use single quotes.
PHP provides two ways to mark string literals. Either with single quotes String literals in single quotes on the other hand are evaluated very literally and the only two
characters that needs escaping in the literal are the single quote itself ( Double quoted string literals may contain other variables or more complex escape sequences. <?php
$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";
print $doubleQuoted;
will print an indented: If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear. For more information on PHP string literals and available escape sequences see the PHP core documentation. ![]() |
|||
565 | $success = FALSE; |
||
0 ignored issues
–
show
$success 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 ![]() |
|||
566 | } |
||
567 | |||
568 | return $device_uid; |
||
569 | } |
||
570 | |||
571 | function createAccount() |
||
0 ignored issues
–
show
|
|||
572 | { |
||
573 | $config = parse_ini_file('config/config.ini.php'); |
||
0 ignored issues
–
show
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space
This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line. To visualize $a = "a";
$ab = "ab";
$abc = "abc";
will produce issues in the first and second line, while this second example $a = "a";
$ab = "ab";
$abc = "abc";
will produce no issues. ![]() |
|||
574 | $location = new Location(); |
||
575 | $location->setLat($config['default_lat']); |
||
576 | $location->setLng($config['default_lng']); |
||
577 | $location->setCityName($config['default_location']); |
||
578 | |||
579 | $deviceUid = $this->registerAccount($location); |
||
580 | |||
581 | return $deviceUid; |
||
582 | } |
||
583 | } |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.