Skip to content

Commit b6594cf

Browse files
committed
Cleaned up code - some files were refactored with refactor
The following adjustments were made: - Change switch with only 1 check to if (SingularSwitchToIfRector) - Merge nested if statements (CombineIfRector) - Simplify empty() functions calls on empty arrays (SimplifyEmptyCheckOnEmptyArrayRector) - Remove unneeded $value = $value assigns (SimplifyMirrorAssignRector)
1 parent 46806e8 commit b6594cf

56 files changed

Lines changed: 363 additions & 477 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

firstLogin.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ function notifyGlobalAdmins(&$dbHandler, &$userObj)
201201
}
202202

203203
// silence errors
204-
if (! empty($dest)) {
204+
if ($dest !== []) {
205205
$mail['to'] = implode(',', $dest); // email_api uses ',' as list separator
206206
$mail['subject'] = lang_get('new_account');
207207
$mail['body'] = lang_get('new_account') . "\n";

lib/api/rest/v1/tlRestApi.class.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public function getProjectTestCases($idCard)
395395
$tcaseIDSet = [];
396396
$this->tprojectMgr->get_all_testcases_id($tproject[0]['id'],
397397
$tcaseIDSet);
398-
if (! empty($tcaseIDSet)) {
398+
if ($tcaseIDSet !== []) {
399399
$op['items'] = [];
400400
foreach ($tcaseIDSet as $tcaseID) {
401401
$item = $this->tcaseMgr->getLastVersionInfo($tcaseID);

lib/api/rest/v2/tlRestApi.class.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -514,7 +514,7 @@ public function getProjectTestCases($idCard)
514514
$this->tprojectMgr->get_all_testcases_id($tproject['id'],
515515
$tcaseIDSet);
516516

517-
if (! empty($tcaseIDSet)) {
517+
if ($tcaseIDSet !== []) {
518518
$op['items'] = [];
519519
foreach ($tcaseIDSet as $tcaseID) {
520520
$item = $this->tcaseMgr->getLastVersionInfo($tcaseID);
@@ -1811,7 +1811,7 @@ public function addPlatformsToTestPlan($tplan_id)
18111811
$p2link[$plat_id] = $plat_id;
18121812
}
18131813
}
1814-
if (! empty($p2link)) {
1814+
if ($p2link !== []) {
18151815
$platMgr->linkToTestplan($p2link, $tplan_id);
18161816
}
18171817
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ public function getProjectTestCases(Response $response, $idCard)
347347
$this->tprojectMgr->get_all_testcases_id($tproject['id'],
348348
$tcaseIDSet);
349349

350-
if (! empty($tcaseIDSet)) {
350+
if ($tcaseIDSet !== []) {
351351
$op['items'] = [];
352352
foreach ($tcaseIDSet as $tcaseID) {
353353
$item = $this->tcaseMgr->getLastVersionInfo($tcaseID);
@@ -1148,7 +1148,7 @@ public function addPlatformsToTestPlan(Request $request, Response $response,
11481148
$p2link[$plat_id] = $plat_id;
11491149
}
11501150
}
1151-
if (! empty($p2link)) {
1151+
if ($p2link !== []) {
11521152
$platMgr->linkToTestplan($p2link, $tplan_id);
11531153
}
11541154
}

lib/api/xmlrpc/v1/xmlrpc.class.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,7 @@ public function reportTCResult($args)
29902990
]);
29912991
$targetPlatform = null;
29922992

2993-
if (! empty($platformSet)) {
2993+
if ($platformSet !== []) {
29942994
$status_ok = $this->checkPlatformIdentity(
29952995
$this->args[self::$testPlanIDParamName], $platformSet,
29962996
$msg_prefix);
@@ -3937,7 +3937,7 @@ public function addTestCaseToTestPlan($args)
39373937
'outputFormat' => 'mapAccessByID'
39383938
];
39393939
$platformSet = (array) $this->tplanMgr->getPlatforms($tplan_id, $opt);
3940-
$hasPlatforms = (! empty($platformSet));
3940+
$hasPlatforms = ($platformSet !== []);
39413941
$hasPlatformIDArgs = $this->_isParamPresent(
39423942
self::$platformIDParamName);
39433943

@@ -8196,7 +8196,7 @@ public function getTestCaseBugs($args)
81968196
$targetIDs[] = $execContext['execution_id'];
81978197
}
81988198

8199-
if (! empty($targetIDs)) {
8199+
if ($targetIDs !== []) {
82008200
$resultInfo[0]['bugs'] = [];
82018201
$sql = " SELECT DISTINCT bug_id FROM {$this->tables['execution_bugs']} " .
82028202
" WHERE execution_id in(" . implode(',', $targetIDs) . ")";

lib/attachments/attachmentdownload.php

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -43,27 +43,25 @@
4343
// What kind of attachments I've got ?
4444
$doIt = false;
4545
$attContext = $attachInfo['fk_table'];
46-
switch ($attContext) {
47-
case 'executions':
48-
// check apikey
49-
// 1. has to be a test plan key
50-
// 2. execution must belong to the test plan.
51-
$item = getEntityByAPIKey($db, $args->apikey, 'testplan');
52-
if (! is_null($item)) {
53-
$tables = tlObjectWithDB::getDBTables(
54-
[
55-
'executions'
56-
]);
57-
$sql = "SELECT testplan_id FROM {$tables['executions']} " .
58-
"WHERE id = " . intval($attachInfo['fk_id']);
59-
60-
$rs = $db->get_recordset($sql);
61-
if (! is_null($rs) &&
62-
$rs['0']['testplan_id'] == $item['id']) {
63-
$doIt = true;
64-
}
46+
if ($attContext === 'executions') {
47+
// check apikey
48+
// 1. has to be a test plan key
49+
// 2. execution must belong to the test plan.
50+
$item = getEntityByAPIKey($db, $args->apikey, 'testplan');
51+
if (! is_null($item)) {
52+
$tables = tlObjectWithDB::getDBTables(
53+
[
54+
'executions'
55+
]);
56+
$sql = "SELECT testplan_id FROM {$tables['executions']} " .
57+
"WHERE id = " . intval($attachInfo['fk_id']);
58+
59+
$rs = $db->get_recordset($sql);
60+
if (! is_null($rs) &&
61+
$rs['0']['testplan_id'] == $item['id']) {
62+
$doIt = true;
6563
}
66-
break;
64+
}
6765
}
6866
break;
6967

lib/execute/execHistory.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ function getCustomFields(&$tcaseMgr, &$execSet)
162162
$tplan_id = $execSet[$tcvid][$idx]['testplan_id'];
163163
$dummy = (array) $tcaseMgr->html_table_of_custom_field_values(
164164
$tcvid, 'execution', null, $exec_id, $tplan_id);
165-
$cf[$exec_id] = (empty($dummy)) ? '' : $dummy;
165+
$cf[$exec_id] = ($dummy === []) ? '' : $dummy;
166166
}
167167
}
168168
return $cf;

lib/execute/execSetResults.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@
427427
}
428428
}
429429

430-
if (! empty($stepSet)) {
430+
if ($stepSet !== []) {
431431
// test case version under exec has steps
432432
$ctx = new stdClass();
433433
$ctx->testplan_id = $args->tplan_id;
@@ -941,7 +941,7 @@ function getTestsuiteNameDetails(&$db, $tcase_id)
941941
{$tables['nodes_hierarchy']} NHB
942942
WHERE TS.id=NHA.parent_id
943943
AND NHB.id=NHA.parent_id ";
944-
if (is_array($tcase_id) && ! empty($tcase_id)) {
944+
if (is_array($tcase_id) && $tcase_id !== []) {
945945
$in_list = implode(",", $tcase_id);
946946
$sql .= "AND NHA.id IN (" . $in_list . ")";
947947
} elseif (! is_null($tcase_id)) {
@@ -1040,7 +1040,7 @@ function smartyAssignTestsuiteInfo(&$smarty, &$tree_mgr, $tcase_id, $tproject_id
10401040
$ts_cf_smarty[$tc_id] = $cached_cf[$tsuite_id];
10411041
}
10421042

1043-
if (! empty($a_tsval)) {
1043+
if ($a_tsval !== []) {
10441044
$ckObj->value = $a_tsval[0];
10451045
tlSetCookie($ckObj);
10461046
}

lib/functions/database.class.php

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -416,15 +416,12 @@ private function prepare_bool($p_bool)
416416
# return current timestamp for DB
417417
public function db_now()
418418
{
419-
switch ($this->db->databaseType) {
420-
/*
421-
* @todo: maybe we should use this?
422-
* case 'odbc_mssql':
423-
* return "GETDATE()";
424-
*/
425-
default:
426-
return $this->db->DBTimeStamp(time());
427-
}
419+
/*
420+
* @todo: maybe we should use this?
421+
* case 'odbc_mssql':
422+
* return "GETDATE()";
423+
*/
424+
return $this->db->DBTimeStamp(time());
428425
}
429426

430427
# generate a unixtimestamp of a date
@@ -882,16 +879,11 @@ public function build_sql_create_db($db_name)
882879
*/
883880
public function db_null_timestamp()
884881
{
885-
$db_type = $this->db->databaseType;
886-
$nullValue = null;
887-
888-
switch ($db_type) {
889-
case 'mysql':
890-
// is not an error i put single quote on value
891-
$nullValue = " '0000-00-00 00:00:00' ";
892-
break;
882+
$db_type = $this->db->databaseType;
883+
if ($db_type === 'mysql') {
884+
return " '0000-00-00 00:00:00' ";
893885
}
894-
return $nullValue;
886+
return null;
895887
}
896888

897889
/**

lib/functions/exec.inc.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ function write_execution(&$db, &$execSign, &$exec_data, &$issueTracker)
172172
$execSet[$tcversion_id] = $execution_id;
173173

174174
$tcvRelations = (array) $tcaseMgr->getTCVRelationsRaw($tcversion_id);
175-
if (! empty($tcvRelations)) {
175+
if ($tcvRelations !== []) {
176176
$itemSet = array_keys($tcvRelations);
177177
$tcaseMgr->closeOpenTCVRelation($itemSet,
178178
LINK_TC_RELATION_CLOSED_BY_EXEC);

0 commit comments

Comments
 (0)