Skip to content

Commit 9a324a4

Browse files
committed
Cleaned up and formatted code - some adjustments to selected files
The following adjustments were made: - Formate source code - Permissions revised - Local variable and function parameter names should comply with a naming convention (PHP:117) - Unused function parameters should be removed (PHP:S1172)
1 parent 364432d commit 9a324a4

31 files changed

Lines changed: 269 additions & 178 deletions

lib/api/rest/v3/RestApi.class.php

Lines changed: 17 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ public function setContentTypeJSON(Request $request, RequestHandler $handler)
232232

233233
/**
234234
*/
235-
public function whoAmI(Request $request, Response $response, $args)
235+
public function whoAmI(Response $response)
236236
{
237237
$msg = json_encode(
238238
array(
@@ -254,16 +254,10 @@ public function whoAmI(Request $request, Response $response, $args)
254254
* }
255255
*
256256
*/
257-
public function testprojects(Request $request, Response $response, $args)
257+
public function testprojects(Response $response, $args)
258258
{
259259
$itemSet = $this->getProjects($args);
260260

261-
// $data = array('name' => 'Bob', 'age' => 40);
262-
// $payload = json_encode($data)//////;
263-
//
264-
// $response->getBody()->write($payload);
265-
// return $response
266-
// ->withHeader('Content-Type', 'application/json');
267261
$payload = json_encode($itemSet);
268262
$response->getBody()->write($payload);
269263
return $response;
@@ -279,14 +273,14 @@ public function testprojects(Request $request, Response $response, $args)
279273
*
280274
*
281275
*/
282-
private function getProjects($idCard = null, $opt = null)
276+
private function getProjects($idCard = null)
283277
{
284278
$op = array(
285279
'status' => 'ok',
286280
'message' => 'ok',
287281
'item' => null
288282
);
289-
if (is_null($idCard) || empty($idCard)) {
283+
if (empty($idCard)) {
290284
$opOptions = array(
291285
'output' => 'array_of_map',
292286
'order_by' => " ORDER BY name ",
@@ -339,17 +333,14 @@ private function getProjects($idCard = null, $opt = null)
339333
* 'name' ->
340334
* 'prefix' ->
341335
*/
342-
public function getProjectTestCases(Request $request, Response $response,
343-
$idCard)
336+
public function getProjectTestCases(Response $response, $idCard)
344337
{
345338
$op = array(
346339
'status' => 'ok',
347340
'message' => 'ok',
348341
'items' => null
349342
);
350-
$tproject = $this->getProjects($idCard, array(
351-
'output' => 'internal'
352-
));
343+
$tproject = $this->getProjects($idCard);
353344

354345
if (! is_null($tproject)) {
355346
$tcaseIDSet = array();
@@ -390,8 +381,7 @@ public function getProjectTestCases(Request $request, Response $response,
390381
* $item->options->automationEnabled
391382
* $item->options->inventoryEnabled
392383
*/
393-
public function createTestProject(Request $request, Response $response,
394-
$args)
384+
public function createTestProject(Request $request, Response $response)
395385
{
396386
$op = array(
397387
'status' => 'ko',
@@ -438,18 +428,15 @@ public function createTestProject(Request $request, Response $response,
438428
* 'name' ->
439429
* 'prefix' ->
440430
*/
441-
public function getProjectTestPlans(Request $request, Response $response,
442-
$idCard)
431+
public function getProjectTestPlans(Response $response, $idCard)
443432
{
444433
$op = [
445434
'status' => 'ok',
446435
'message' => 'ok',
447436
'items' => null
448437
];
449438

450-
$tproj = $this->getProjects($idCard, array(
451-
'output' => 'internal'
452-
));
439+
$tproj = $this->getProjects($idCard);
453440

454441
if (! is_null($tproj)) {
455442
$items = $this->tprojectMgr->get_all_testplans($tproj['id']);
@@ -472,7 +459,7 @@ public function getProjectTestPlans(Request $request, Response $response,
472459
* map idCard[tplanApiKey]
473460
*
474461
*/
475-
public function getPlanBuilds(Request $request, Response $response, $idCard)
462+
public function getPlanBuilds(Response $response, $idCard)
476463
{
477464
$op = $this->getStdOp();
478465
$tplan = $this->tplanMgr->getByAPIKey($idCard['tplanApiKey']);
@@ -531,7 +518,7 @@ public function getPlanBuilds(Request $request, Response $response, $idCard)
531518
* if check is OK, tester assignments will be copied.
532519
*
533520
*/
534-
public function createBuild(Request $request, Response $response, $args)
521+
public function createBuild(Request $request, Response $response)
535522
{
536523
$op = array(
537524
'status' => 'ko',
@@ -872,7 +859,7 @@ public function updateBuild(Request $request, Response $response, $args)
872859
* 'active'
873860
* 'is_public'
874861
*/
875-
public function createTestPlan(Request $request, Response $response, $args)
862+
public function createTestPlan(Request $request, Response $response)
876863
{
877864
$op = $this->getStdIDKO();
878865
try {
@@ -982,8 +969,7 @@ public function updateTestPlan(Request $request, Response $response, $args)
982969
* We are not going to check for other mandatory info
983970
* like: mandatory custom fields. (if we will be able in future to manage it)
984971
*/
985-
public function createTestCaseExecution(Request $request, Response $response,
986-
$args)
972+
public function createTestCaseExecution(Request $request, Response $response)
987973
{
988974
$op = $this->getStdIDKO();
989975

@@ -1030,7 +1016,7 @@ public function createTestCaseExecution(Request $request, Response $response,
10301016
* 'notes'
10311017
* 'order'
10321018
*/
1033-
public function createTestSuite(Request $request, Response $response, $args)
1019+
public function createTestSuite(Request $request, Response $response)
10341020
{
10351021
$op = $this->getStdIDKO();
10361022
try {
@@ -1218,7 +1204,7 @@ public function addPlatformsToTestPlan(Request $request, Response $response,
12181204
* }
12191205
* ]
12201206
*/
1221-
public function createTestCase(Request $request, Response $response, $args)
1207+
public function createTestCase(Request $request, Response $response)
12221208
{
12231209
$op = $this->getStdIDKO();
12241210
try {
@@ -1269,7 +1255,7 @@ public function createTestCase(Request $request, Response $response, $args)
12691255
* "notes"
12701256
* "testProject": {"prefix":"APR"}
12711257
*/
1272-
public function createKeyword(Request $request, Response $response, $args)
1258+
public function createKeyword(Request $request, Response $response)
12731259
{
12741260
$op = $this->getStdIDKO();
12751261

@@ -1773,4 +1759,4 @@ private function msgFromException($e)
17731759
{
17741760
return $e->getMessage() . ' - offending line number: ' . $e->getLine();
17751761
}
1776-
} // class end
1762+
}

lib/attachments/attachmentdownload.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@
100100
// is SVG?
101101
if (strripos($content, "<!DOCTYPE svg") !== false ||
102102
strripos($content, "<svg") !== false &&
103-
! XSS_StringScriptSafe($content)) {
103+
! xssStringScriptSafe($content)) {
104104
$what2do = "Content-Disposition: attachment;";
105105
}
106106

lib/functions/common.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,7 @@ function to_boolean($alt_boolean)
633633
*
634634
* @todo havlatm: remove as obsolete or move to inputparam.inc.php
635635
*/
636-
function check_string($str2check, $regexp_forbidden_chars)
636+
function checkString($str2check, $regexp_forbidden_chars)
637637
{
638638
$status_ok = 1;
639639

@@ -690,7 +690,7 @@ function config_get($config_id, $default = null)
690690
* containing only whitespace, false otherwise
691691
* @author Copyright (C) 2000 - 2004 Mantis Team, Kenzaburo Ito
692692
*/
693-
function is_blank($p_var)
693+
function isBlank($p_var)
694694
{
695695
$p_var = trim($p_var);
696696
$str_len = strlen($p_var);
@@ -799,7 +799,7 @@ function ini_get_bool($p_name)
799799
*
800800
* @author Francisco Mancardi - 20050905 - refactoring
801801
*/
802-
function trim_and_limit($s, $len = 100)
802+
function trimAndLimit($s, $len = 100)
803803
{
804804
$s = trim($s);
805805
if (tlStringLen($s) > $len) {
@@ -912,13 +912,13 @@ function templateConfiguration($template2get = null)
912912
* Check if an string is a valid ISO date/time
913913
* accepted format: YYYY-MM-DD HH:MM:SS
914914
*
915-
* @param string $ISODateTime
915+
* @param string $isoDateTime
916916
* datetime to check
917917
* @return boolean True if string has correct format
918918
*
919919
* @internal rev: 20080907 - franciscom - Code taked form PHP manual
920920
*/
921-
function isValidISODateTime($ISODateTime)
921+
function isValidISODateTime($isoDateTime)
922922
{
923923
$dateParts = array(
924924
'YEAR' => 1,
@@ -930,7 +930,7 @@ function isValidISODateTime($ISODateTime)
930930
$status_ok = false;
931931
if (preg_match(
932932
"/^(\d{4})-(\d{2})-(\d{2}) ([01]\d|2[0-3]):([0-5]\d):([0-5]\d)$/",
933-
$ISODateTime, $matches)) {
933+
$isoDateTime, $matches)) {
934934
$status_ok = checkdate($matches[$dateParts['MONTH']],
935935
$matches[$dateParts['DAY']], $matches[$dateParts['YEAR']]);
936936
}
@@ -2169,7 +2169,7 @@ function pageAccessCheck(&$db, &$user, $context)
21692169

21702170
/**
21712171
*/
2172-
function XSS_StringScriptSafe($content)
2172+
function xssStringScriptSafe($content)
21732173
{
21742174
$needle = [];
21752175
$needle[] = "<script";

lib/functions/email_api.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ function email_send($p_from, $p_recipient, $p_subject, $p_message, $p_cc = '',
7676

7777
// Check fatal Error
7878
$smtp_host = config_get('smtp_host');
79-
if (is_blank($smtp_host)) {
79+
if (isBlank($smtp_host)) {
8080
$op->status_ok = false;
8181
$op->msg = lang_get('stmp_host_unconfigured');
8282
return $op; // >>>---->
@@ -119,14 +119,14 @@ function email_send($p_from, $p_recipient, $p_subject, $p_message, $p_cc = '',
119119
$mail->SMTPKeepAlive = true;
120120

121121
# Copied from last mantis version
122-
if (! is_blank(config_get('smtp_username'))) {
122+
if (! isBlank(config_get('smtp_username'))) {
123123
# Use SMTP Authentication
124124
$mail->SMTPAuth = true;
125125
$mail->Username = config_get('smtp_username');
126126
$mail->Password = config_get('smtp_password');
127127
}
128128

129-
if (! is_blank(config_get('smtp_connection_mode'))) {
129+
if (! isBlank(config_get('smtp_connection_mode'))) {
130130
$mail->SMTPSecure = config_get('smtp_connection_mode');
131131
}
132132

@@ -154,22 +154,22 @@ function email_send($p_from, $p_recipient, $p_subject, $p_message, $p_cc = '',
154154
$mail->FromName = '';
155155

156156
$mail->From = config_get('from_email');
157-
if (! is_blank($p_from)) {
157+
if (! isBlank($p_from)) {
158158
$mail->From = $p_from;
159159
}
160160

161161
# add to the Recipient list
162162
$t_recipient_list = explode(',', $ot->recipient);
163163

164164
foreach ($t_recipient_list as $t_recipient) {
165-
if (! is_blank($t_recipient)) {
165+
if (! isBlank($t_recipient)) {
166166
$mail->AddAddress($t_recipient, '');
167167
}
168168
}
169169

170170
$t_cc_list = explode(',', $p_cc);
171171
foreach ($t_cc_list as $t_cc) {
172-
if (! is_blank($t_cc)) {
172+
if (! isBlank($t_cc)) {
173173
$mail->AddCC($t_cc, '');
174174
}
175175
}
@@ -227,7 +227,7 @@ function make_lf_crlf($p_string)
227227
function email_append_domain($p_email)
228228
{
229229
$t_limit_email_domain = config_get('limit_email_domain');
230-
if ($t_limit_email_domain && ! is_blank($p_email)) {
230+
if ($t_limit_email_domain && ! isBlank($p_email)) {
231231
$p_email = "$p_email@$t_limit_email_domain";
232232
}
233233

lib/functions/ldap_api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ function ldap_connect_bind($authCfg, $p_binddn = '', $p_password = '')
6666

6767
# If no Bind DN and Password is set, attempt to login as the configured
6868
# Bind DN.
69-
if (is_blank($p_binddn) && is_blank($p_password)) {
69+
if (isBlank($p_binddn) && isBlank($p_password)) {
7070
$p_binddn = $authCfg['ldap_bind_dn'];
7171
$p_password = $authCfg['ldap_bind_passwd'];
7272
}
7373

74-
if (! is_blank($p_binddn) && ! is_blank($p_password)) {
74+
if (! isBlank($p_binddn) && ! isBlank($p_password)) {
7575
$t_br = ldap_bind($t_ds, $p_binddn, $p_password);
7676
} else {
7777
# Either the Bind DN or the Password are empty, so attempt an anonymous bind.
@@ -116,7 +116,7 @@ function ldap_authenticate($p_login_name, $p_password)
116116
# if password is empty and ldap allows anonymous login, then
117117
# the user will be able to login, hence, we need to check
118118
# for this special case.
119-
if (is_blank($p_password)) {
119+
if (isBlank($p_password)) {
120120
return false;
121121
}
122122

lib/functions/logger.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1260,7 +1260,7 @@ public function __construct(&$db)
12601260
foreach ($key2check as $emailKey) {
12611261
$matches = array();
12621262
$this->$emailKey = trim($this->$emailKey);
1263-
if (is_blank($this->$emailKey) ||
1263+
if (isBlank($this->$emailKey) ||
12641264
! preg_match($regex2match, $this->$emailKey, $matches)) {
12651265
$this->configIsOK = false;
12661266
break;

lib/functions/oauth_api.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
*/
1212

1313
// Create correct link for oauth
14-
function oauth_link($oauthCfg)
14+
function oauthLink($oauthCfg)
1515
{
1616
$oap = array();
1717

@@ -44,8 +44,8 @@ function oauth_link($oauthCfg)
4444
*/
4545
function getOAuthProviderCfg($provider)
4646
{
47-
$OAuthProviders = config_get('OAuthServers');
48-
foreach ($OAuthProviders as $providerCfg) {
47+
$oAuthProviders = config_get('OAuthServers');
48+
foreach ($oAuthProviders as $providerCfg) {
4949
if ($provider == trim($providerCfg['oauth_name'])) {
5050
return $providerCfg;
5151
}

0 commit comments

Comments
 (0)