Maelstromeous /
ps2alerts-api
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 | // @todo Go over this ENTIRE file again as there's been major refactors since and it's likely broken! |
||
| 4 | |||
| 5 | namespace Ps2alerts\Api\Controller\Endpoint\Leaderboards; |
||
| 6 | |||
| 7 | use Ps2alerts\Api\Controller\Endpoint\AbstractEndpointController; |
||
| 8 | use Psr\Http\Message\ServerRequestInterface; |
||
| 9 | use Psr\Http\Message\ResponseInterface; |
||
| 10 | |||
| 11 | class LeaderboardLadderEndpointController extends AbstractEndpointController |
||
| 12 | { |
||
| 13 | public function playerLadder(ServerRequestInterface $request, ResponseInterface $response, array $args) |
||
|
0 ignored issues
–
show
|
|||
| 14 | { |
||
| 15 | $redis = $this->getRedisDriver(); |
||
|
0 ignored issues
–
show
The method
getRedisDriver() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.
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. Loading history...
|
|||
| 16 | $metric = $args['metric']; |
||
| 17 | $server = $args['server']; |
||
| 18 | |||
| 19 | $list = "ps2alerts:api:leaderboards:players:{$metric}:listById-{$server}"; |
||
| 20 | |||
| 21 | var_dump($list); |
||
|
0 ignored issues
–
show
|
|||
| 22 | |||
| 23 | $entries = $redis->get($list); |
||
| 24 | |||
| 25 | var_dump($entries); |
||
| 26 | } |
||
| 27 | |||
| 28 | /** |
||
| 29 | * Prompts the Leaderboard:Check command to resync the leaderboards |
||
| 30 | * |
||
| 31 | * @param ServerRequestInterface $request |
||
| 32 | * @param ResponseInterface $response |
||
| 33 | * |
||
| 34 | * @return ResponseInterface |
||
| 35 | */ |
||
| 36 | public function update(ServerRequestInterface $request, ResponseInterface $response) |
||
|
0 ignored issues
–
show
update 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);
}
}
Loading history...
update 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);
}
}
Loading history...
|
|||
| 37 | { |
||
| 38 | $config = $this->getConfig(); |
||
|
0 ignored issues
–
show
$config 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 Loading history...
|
|||
| 39 | |||
| 40 | // Only accept commands from internal IP |
||
| 41 | $ip = $request->getClientIp(); |
||
|
0 ignored issues
–
show
The method
getClientIp() does not seem to exist on object<Psr\Http\Message\ServerRequestInterface>.
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. Loading history...
|
|||
| 42 | |||
| 43 | if ($ip !== $_SERVER['SERVER_ADDR']) { |
||
| 44 | $response->setStatusCode(404); |
||
|
0 ignored issues
–
show
It seems like you code against a concrete implementation and not the interface
Psr\Http\Message\ResponseInterface as the method setStatusCode() does only exist in the following implementations of said interface: Zend\Diactoros\Response, Zend\Diactoros\Response\EmptyResponse, Zend\Diactoros\Response\HtmlResponse, Zend\Diactoros\Response\JsonResponse, Zend\Diactoros\Response\RedirectResponse, Zend\Diactoros\Response\TextResponse.
Let’s take a look at an example: interface User
{
/** @return string */
public function getPassword();
}
class MyUser implements User
{
public function getPassword()
{
// return something
}
public function getDisplayName()
{
// return some name.
}
}
class AuthSystem
{
public function authenticate(User $user)
{
$this->logger->info(sprintf('Authenticating %s.', $user->getDisplayName()));
// do something.
}
}
In the above example, the authenticate() method works fine as long as you just pass instances of MyUser. However, if you now also want to pass a different implementation of User which does not have a getDisplayName() method, the code will break. Available Fixes
Note: PHP Analyzer uses reverse abstract interpretation to narrow down the types
inside the if block in such a case.
Loading history...
|
|||
| 45 | return $response; |
||
| 46 | } |
||
| 47 | |||
| 48 | $server = $_GET['server']; |
||
| 49 | |||
| 50 | $redis = $this->getRedisDriver(); |
||
|
0 ignored issues
–
show
The method
getRedisDriver() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.
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. Loading history...
|
|||
| 51 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
||
| 52 | |||
| 53 | // If we have a key, change the flag to force exists so the cronjob can run |
||
| 54 | if ($redis->exists($key)) { |
||
| 55 | $data = json_decode($redis->get($key)); |
||
| 56 | |||
| 57 | // Ignore if already flagged as being updated |
||
| 58 | if ($data->beingUpdated == 0) { |
||
| 59 | $data->forceUpdate = 1; |
||
| 60 | $redis->set($key, json_encode($data)); |
||
| 61 | } |
||
| 62 | } 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. Loading history...
|
|||
| 63 | // Panic. |
||
| 64 | } |
||
| 65 | |||
| 66 | $response = $response->withStatus(202); |
||
| 67 | return $response; |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * Returns a list of times that a server leaderboard has been updated |
||
| 72 | * |
||
| 73 | * @param ServerRequestInterface $request |
||
| 74 | * @param ResponseInterface $response |
||
| 75 | * |
||
| 76 | * @return ResponseInterface |
||
| 77 | */ |
||
| 78 | public function lastUpdate(ServerRequestInterface $request, ResponseInterface $response) |
||
|
0 ignored issues
–
show
|
|||
| 79 | { |
||
| 80 | $config = $this->getConfig(); |
||
| 81 | $redis = $this->getRedisDriver(); |
||
|
0 ignored issues
–
show
The method
getRedisDriver() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.
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. Loading history...
|
|||
| 82 | |||
| 83 | $data = []; |
||
| 84 | |||
| 85 | foreach($config['servers'] as $server) { |
||
| 86 | $key = "ps2alerts:api:leaderboards:status:{$server}"; |
||
| 87 | |||
| 88 | if ($redis->exists($key)) { |
||
| 89 | $entry = json_decode($redis->get($key)); |
||
| 90 | $data[$server] = $this->createItem($entry, new LeaderboardUpdatedTransformer); |
||
|
0 ignored issues
–
show
The method
createItem() does not seem to exist on object<Ps2alerts\Api\Con...dderEndpointController>.
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. Loading history...
|
|||
| 91 | } |
||
| 92 | } |
||
| 93 | |||
| 94 | return $this->respondWithData($data); |
||
| 95 | } |
||
| 96 | } |
||
| 97 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.