Skip to content

Commit 1a95a0e

Browse files
committed
SensioLabsInsight violations part 2
1 parent e5d7ad1 commit 1a95a0e

File tree

6 files changed

+77
-94
lines changed

6 files changed

+77
-94
lines changed

DevAAC/DevAAC.php

Lines changed: 66 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
//////////////////////// CREATE Slim APPLICATION //////////////////////////////////
3838
$DevAAC = new \Slim\Slim(
3939
[
40-
'debug' => ENABLE_DEBUG
40+
'debug' => ENABLE_DEBUG,
4141
]
4242
);
4343

@@ -57,12 +57,9 @@ function ($a) {
5757
); // Send blank 200 to every OPTIONS request
5858
}
5959

60-
$DevAAC->container->singleton(
61-
'request',
62-
function ($c) {
63-
return new DevAAC\Http\Request($c['environment']);
64-
}
65-
);
60+
$DevAAC->container->singleton('request', function ($c) {
61+
return new DevAAC\Http\Request($c['environment']);
62+
});
6663

6764
//////////////////// DEFINE AUTHENTICATION MIDDLEWARE ////////////////////////////
6865
// http://docs.slimframework.com/#Middleware-Overview
@@ -81,8 +78,7 @@ public function call()
8178
if (!$this->app->auth_account) {
8279
$this->app->auth_account = DevAAC\Models\Account::where('name', $auth_user)->where('password', sha1($auth_pass))->first();
8380
}
84-
//else
85-
// $res->header('WWW-Authenticate', sprintf('Basic realm="%s"', 'AAC'));
81+
8682
$this->next->call();
8783
}
8884
}
@@ -112,7 +108,7 @@ function ($e) use ($DevAAC) {
112108
json_encode(
113109
[
114110
'code' => $e->getCode(),
115-
'message' => 'Fatal error occured: ' . $e->getMessage() . ' at line ' . $e->getLine() . ' in file ' . $e->getFile()
111+
'message' => 'Fatal error occured: ' . $e->getMessage() . ' at line ' . $e->getLine() . ' in file ' . $e->getFile(),
116112
],
117113
JSON_PRETTY_PRINT
118114
)
@@ -123,20 +119,19 @@ function ($e) use ($DevAAC) {
123119

124120
//////////////////////////// LOAD TFS CONFIG ////////////////////////////////////
125121
// you need to define TFS_CONFIG to be an array with config.lua options or a path to config.lua
126-
$DevAAC->tfsConfigFile = is_file(TFS_CONFIG) ? parse_tfs_config(TFS_CONFIG) : unserialize(TFS_CONFIG) or die('TFS_CONFIG is not defined properly.');
122+
$DevAAC->tfsConfigFile = is_file(TFS_CONFIG) ? parse_tfs_config(TFS_CONFIG) : unserialize(TFS_CONFIG) || die('TFS_CONFIG is not defined properly.');
127123

128124
/////////////////////////// VOCATION PROVIDER///////////////////////////////////
129-
$DevAAC->container->singleton(
130-
'vocations',
131-
function ($c) {
132-
if (file_exists(TFS_ROOT . '/data/XML/vocations.xml')) {
133-
$xml = simplexml_load_file(TFS_ROOT . '/data/XML/vocations.xml');
134-
if (property_exists($xml, 'vocation')) {
135-
return $xml;
136-
}
125+
$DevAAC->container->singleton('vocations', function ($c) {
126+
if (file_exists(TFS_ROOT . '/data/XML/vocations.xml')) {
127+
$xml = simplexml_load_file(TFS_ROOT . '/data/XML/vocations.xml');
128+
if (property_exists($xml, 'vocation')) {
129+
return $xml;
137130
}
138131
}
139-
);
132+
133+
return null;
134+
});
140135

141136
////////////////////////// CONNECT TO DATABASE /////////////////////////////////
142137
// Bootstrap Eloquent ORM
@@ -173,19 +168,16 @@ function ($c) {
173168
// https://github.com/zircote/swagger-php/blob/master/library/Swagger/Swagger.php
174169
use Swagger\Swagger;
175170

176-
$DevAAC->get(
177-
ROUTES_API_PREFIX . '/docs(/:path)',
178-
function ($path = '/') use ($DevAAC) {
179-
$swagger = new Swagger('../', '../vendor');
180-
$DevAAC->response->headers->set('Access-Control-Allow-Origin', '*');
181-
$DevAAC->response->headers->set('Content-Type', 'application/json');
182-
if ($path != '/') {
183-
$DevAAC->response->setBody($swagger->getResource('/' . $path, ['output' => 'json']));
184-
} else {
185-
$DevAAC->response->setBody($swagger->getResourceList(['output' => 'json']));
186-
}
171+
$DevAAC->get(ROUTES_API_PREFIX . '/docs(/:path)', function ($path = '/') use ($DevAAC) {
172+
$swagger = new Swagger('../', '../vendor');
173+
$DevAAC->response->headers->set('Access-Control-Allow-Origin', '*');
174+
$DevAAC->response->headers->set('Content-Type', 'application/json');
175+
if ($path != '/') {
176+
$DevAAC->response->setBody($swagger->getResource('/' . $path, ['output' => 'json']));
177+
} else {
178+
$DevAAC->response->setBody($swagger->getResourceList(['output' => 'json']));
187179
}
188-
);
180+
});
189181

190182
//////////////////////////// DEFINE API ROUTES //////////////////////////////////
191183
require('routes/accounts.php');
@@ -195,56 +187,47 @@ function ($path = '/') use ($DevAAC) {
195187
require('routes/players.php');
196188
require('routes/server.php');
197189

198-
$DevAAC->get(
199-
ROUTES_API_PREFIX . '/news',
200-
function () use ($DevAAC) {
201-
$news = [];
202-
if (is_dir(PUBLIC_HTML_PATH . '/news')) {
203-
foreach (glob(PUBLIC_HTML_PATH . '/news/*.md') as $filename) {
204-
$date = new \DevAAC\Helpers\DateTime;
205-
$date->setTimestamp(filectime($filename));
206-
$news[] = [
207-
'title' => basename($filename, '.md'),
208-
'date' => $date,
209-
'content' => file_get_contents($filename)
210-
];
211-
}
190+
$DevAAC->get(ROUTES_API_PREFIX . '/news', function () use ($DevAAC) {
191+
$news = [];
192+
if (is_dir(PUBLIC_HTML_PATH . '/news')) {
193+
foreach (glob(PUBLIC_HTML_PATH . '/news/*.md') as $filename) {
194+
$date = new \DevAAC\Helpers\DateTime;
195+
$date->setTimestamp(filectime($filename));
196+
$news[] = [
197+
'title' => basename($filename, '.md'),
198+
'date' => $date,
199+
'content' => file_get_contents($filename),
200+
];
212201
}
213-
214-
$DevAAC->response->headers->set('Content-Type', 'application/json');
215-
$DevAAC->response->setBody(json_encode($news, JSON_PRETTY_PRINT));
216202
}
217-
);
218203

219-
if (ENABLE_DEBUG) {
220-
$DevAAC->get(
221-
ROUTES_PREFIX . '/debug',
222-
function () use ($DevAAC, $capsule) {
223-
$DevAAC->response->headers->set('Content-Type', 'text');
224-
/*
225-
var_dump($capsule->getConnection()->getPdo()->getAttribute(PDO::ATTR_CLIENT_VERSION));
226-
$date = new \DevAAC\Helpers\DateTime();
227-
$tmp = \DevAAC\Models\Player::find(2);
228-
foreach($tmp->toArray() as $key => $value)
229-
echo "'".$key."' => 0,". PHP_EOL;
230-
//echo '* @SWG\Property(name="'.$key.'", type="string")'. PHP_EOL;
231-
echo $date . PHP_EOL;
232-
echo json_encode($date) . PHP_EOL;
233-
echo serialize($date) . PHP_EOL;
234-
echo PHP_EOL . PHP_EOL . PHP_EOL;
235-
*/
236-
$a = (array)$DevAAC->vocations;
237-
var_dump(xml2array($DevAAC->vocations)['vocation']);
238-
json_encode($a['vocation'], JSON_PRETTY_PRINT);
239-
}
240-
);
204+
$DevAAC->response->headers->set('Content-Type', 'application/json');
205+
$DevAAC->response->setBody(json_encode($news, JSON_PRETTY_PRINT));
206+
});
241207

242-
$DevAAC->get(
243-
ROUTES_PREFIX . '/phpinfo',
244-
function () use ($DevAAC) {
245-
phpinfo();
246-
}
247-
);
208+
if (ENABLE_DEBUG) {
209+
$DevAAC->get(ROUTES_PREFIX . '/debug', function () use ($DevAAC) {
210+
$DevAAC->response->headers->set('Content-Type', 'text');
211+
/*
212+
var_dump($capsule->getConnection()->getPdo()->getAttribute(PDO::ATTR_CLIENT_VERSION));
213+
$date = new \DevAAC\Helpers\DateTime();
214+
$tmp = \DevAAC\Models\Player::find(2);
215+
foreach($tmp->toArray() as $key => $value)
216+
echo "'".$key."' => 0,". PHP_EOL;
217+
//echo '* @SWG\Property(name="'.$key.'", type="string")'. PHP_EOL;
218+
echo $date . PHP_EOL;
219+
echo json_encode($date) . PHP_EOL;
220+
echo serialize($date) . PHP_EOL;
221+
echo PHP_EOL . PHP_EOL . PHP_EOL;
222+
*/
223+
$a = (array)$DevAAC->vocations;
224+
var_dump(xml2array($DevAAC->vocations)['vocation']);
225+
json_encode($a['vocation'], JSON_PRETTY_PRINT);
226+
});
227+
228+
$DevAAC->get(ROUTES_PREFIX . '/phpinfo', function () {
229+
phpinfo();
230+
});
248231
}
249232

250233
////////////////////// PLUGINS SUPPORT ///////////////////////////////
@@ -283,13 +266,10 @@ function () use ($DevAAC) {
283266
* )
284267
* )
285268
*/
286-
$DevAAC->get(
287-
ROUTES_API_PREFIX . '/plugins',
288-
function () use ($DevAAC) {
289-
$DevAAC->response->setBody(json_encode($DevAAC->plugins), JSON_PRETTY_PRINT);
290-
$DevAAC->response->headers->set('Content-Type', 'application/json');
291-
}
292-
);
269+
$DevAAC->get(ROUTES_API_PREFIX . '/plugins', function () use ($DevAAC) {
270+
$DevAAC->response->setBody(json_encode($DevAAC->plugins), JSON_PRETTY_PRINT);
271+
$DevAAC->response->headers->set('Content-Type', 'application/json');
272+
});
293273

294274
//////////////////////////////////////////////////////////////////////
295275
// all done, any code after this call will not matter to the request
@@ -337,5 +317,6 @@ function parse_tfs_config($filename)
337317
}
338318
}
339319
$ini = implode("\n", $output);
320+
340321
return parse_ini_string($ini);
341322
}

DevAAC/Models/Player.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ public function online()
201201

202202
public function getIsOnlineAttribute()
203203
{
204-
return $this->online != null;
204+
return $this->online !== null;
205205
}
206206

207207
public function guildMembership()

DevAAC/routes/accounts.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,7 +466,7 @@
466466
if( ! $DevAAC->auth_account )
467467
throw new InputErrorException('You are not logged in.', 401);
468468

469-
if($account->id != $DevAAC->auth_account->id or !$DevAAC->auth_account->isGod())
469+
if($account->id != $DevAAC->auth_account->id || !$DevAAC->auth_account->isGod())
470470
throw new InputErrorException('You do not have permission to change this account.', 403);
471471

472472
if( !$DevAAC->auth_account->isGod() )
@@ -500,7 +500,7 @@
500500

501501
if($req->getAPIParam('email', false))
502502
{
503-
if( !filter_var($req->getAPIParam('email'), FILTER_VALIDATE_EMAIL) or !getmxrr(explode('@', $req->getAPIParam('email'))[1], $trash_) )
503+
if( !filter_var($req->getAPIParam('email'), FILTER_VALIDATE_EMAIL) || !getmxrr(explode('@', $req->getAPIParam('email'))[1], $trash_) )
504504
throw new InputErrorException('Email address is not valid.', 400);
505505

506506
$account->email = $req->getAPIParam('email');
@@ -611,7 +611,7 @@
611611
array("options" => array("regexp" => "/^(.{2,20}|.{40})$/"))) )
612612
throw new InputErrorException('Password must have 2-20 characters or be an SHA-1 hash (40 hexadecimal characters).', 400);
613613

614-
if( !filter_var($req->getAPIParam('email'), FILTER_VALIDATE_EMAIL) or !getmxrr(explode('@', $req->getAPIParam('email'))[1], $trash_) )
614+
if( !filter_var($req->getAPIParam('email'), FILTER_VALIDATE_EMAIL) || !getmxrr(explode('@', $req->getAPIParam('email'))[1], $trash_) )
615615
throw new InputErrorException('Email address is not valid.', 400);
616616

617617
$account = Account::where('name', $req->getAPIParam('name'))->first();

DevAAC/routes/players.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@
416416
$players->skip($req->get('offset'));
417417

418418
$limit = intval($req->get('limit'));
419-
if($limit && ($limit <= 100 or ( $DevAAC->auth_account && $DevAAC->auth_account->isGod() ) ) )
419+
if($limit && ($limit <= 100 || ($DevAAC->auth_account && $DevAAC->auth_account->isGod()) ))
420420
$players->take($limit);
421421
else
422422
$players->take(100);

composer.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
2+
"name": "DevAAC",
3+
"Description": "Automatic Account Creator for TFS 1.X",
24
"license": "MIT",
35
"require": {
46
"slim/slim": "^2.6",

plugins/ratelimiter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@
4040
return array_merge($meta, array('enabled' => false));
4141

4242
// THIS PLUGIN CURRENTLY SUPPORTS APC ONLY
43-
if(!extension_loaded('apc') or !ini_get('apc.enabled'))
43+
if(!extension_loaded('apc') || !ini_get('apc.enabled'))
4444
return array_merge($meta, array('enabled' => false));
4545

4646
// DEFAULT CONFIG
47-
defined('RATELIMITER_RULES') or define('RATELIMITER_RULES', serialize(array(
47+
defined('RATELIMITER_RULES') || define('RATELIMITER_RULES', serialize(array(
4848
// DEFINE RULES WITHOUT ROUTES_PREFIX OR ROUTES_API_PREFIX
4949
// PATH -> NUMBER OF SECONDS TO WAIT BETWEEN REQUESTS
5050
'GET' => array(
@@ -57,7 +57,7 @@
5757
)
5858
)));
5959
// SHOULD WE RESET THE TIMER ON EVERY ATTEMPT?
60-
defined('RATELIMITER_PENALIZE') or define('RATELIMITER_PENALIZE', false);
60+
defined('RATELIMITER_PENALIZE') || define('RATELIMITER_PENALIZE', false);
6161

6262
// http://docs.slimframework.com/#How-to-Use-Hooks
6363
$DevAAC->hook('slim.before.dispatch', function () use ($DevAAC) {
@@ -81,7 +81,7 @@
8181
$path = substr($path, strlen(ROUTES_PREFIX));
8282

8383
// DO WE HAVE A RULE?
84-
if( array_key_exists($method, $rules) && array_key_exists($path, $rules[$method]) ) {
84+
if (array_key_exists($method, $rules) && array_key_exists($path, $rules[$method])) {
8585
// every path for every IP is a separate object to be thread safe
8686
$objname = $req->getIp() . '_' . $path;
8787

0 commit comments

Comments
 (0)