Skip to content

Commit 5b41b0e

Browse files
committed
Cleaned up and formatted code - some adjustments to selected files
The following adjustments were made: - Formate source code - Permissions revised - Minor corrections - Switch cases should end with an unconditional "break" statement (PHP:128) - "switch" statements should have "default" clauses (PHP:131) - "switch" statements should have at least 3 "case" clauses (PHP:1301)
1 parent 9a324a4 commit 5b41b0e

62 files changed

Lines changed: 609 additions & 627 deletions

Some content is hidden

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

install/installNewDB.php

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@
200200
// do some database checks
201201
echo "<br /><b>Creating connection to Database Server:</b>";
202202

203-
// --------------------------------------------------------------------------
204203
// Connect to DB Server without choosing an specific database
205204
switch ($db_type) {
206205
case 'mssql':
@@ -231,7 +230,6 @@
231230
$db->close();
232231
$db = null;
233232

234-
// -------------------------------------------------------------------------
235233
// Connect to the Database (if Succesful -> database exists)
236234
$db = new database($dbDriverName);
237235

@@ -255,9 +253,7 @@
255253
echo "<br />Connecting to database `" . $db_name . "`:";
256254
echo "<span class='ok'>OK!</span>";
257255
}
258-
// -------------------
259256

260-
// -------------------
261257
if ($create) {
262258
// check database name for invalid characters (now only for MySQL)
263259
$db->close();
@@ -318,7 +314,6 @@
318314
close_html_and_exit();
319315
}
320316
}
321-
// -------------------------------------------------------------
322317

323318
$a_sql_upd_dir = array();
324319
$a_sql_data_dir = array();
@@ -399,7 +394,6 @@
399394
$a_sql_data = getDirSqlFiles($a_sql_data_dir, ADD_DIR);
400395
}
401396

402-
// ------------------------------------------------------------------------
403397
// Now proceed with user checks and user creation (if needed)
404398
//
405399
// Added support for different types of architecture/installations:
@@ -422,7 +416,6 @@
422416
echo "<span class='ok'>OK! ($msg) </span>";
423417
}
424418

425-
// ------------------------------------------------------------------------
426419
// Schema Operations (CREATE, ALTER, ecc).
427420
// Important:
428421
// Postgres: do it as tl_login NOT as db_admin
@@ -450,13 +443,11 @@
450443
break;
451444
}
452445

453-
// ------------------------------------------------------------------------------------
454446
if ($install && $conn_result['status'] != 0) {
455447
drop_views($db, $db_table_prefix, $db_type);
456448
drop_tables($db, $db_table_prefix, $db_type);
457449
}
458450

459-
// -------------------------------------------------------------------------------
460451
$sqlParser = new SqlParser($db, $db_type, $db_table_prefix);
461452
foreach ($a_sql_schema as $sql_schema) {
462453
foreach ($sql_schema as $sql_file) {
@@ -472,19 +463,17 @@
472463
$migration_process($db, $tables);
473464
}
474465

475-
// -------------------------------------------------
476466
// Data Operations
477467
if (! empty($a_sql_data)) {
478468
foreach ($a_sql_data as $sql_data) {
479-
if (count($sql_data) > 0) {
469+
if (! empty($sql_data)) {
480470
foreach ($sql_data as $sql_file) {
481471
$sqlParser->process($sql_file);
482472
}
483473
}
484474
}
485475
}
486476

487-
// -------------------------------------------------
488477
if ($update_pwd) {
489478
echo "Password Conversion ...";
490479
// @author Francisco Mancardi - 20050918
@@ -513,7 +502,6 @@
513502
echo "<span class='ok'>OK!</span>";
514503
}
515504

516-
// -----------------------------------------------------------------------------
517505
echo "<br />Writing configuration file:";
518506
$data['db_host'] = $db_server;
519507
$data['db_login'] = $user_host[0];
@@ -524,7 +512,6 @@
524512

525513
$cfg_file = "../config_db.inc.php";
526514
$yy = write_config_db($cfg_file, $data);
527-
// -----------------------------------------------------------------------------
528515

529516
if (strcasecmp('ko', $yy['status']) == 0) {
530517
echo "<span class='notok'>Failed!</span></b>";
@@ -576,7 +563,6 @@ function manual_operations($dbType)
576563
echo '</h1><br><h1>THANKS A LOT </b></h1>';
577564
}
578565

579-
// -----------------------------------------------------------
580566
function write_config_db($filename, $data)
581567
{
582568
$ret = array(
@@ -600,8 +586,8 @@ function write_config_db($filename, $data)
600586

601587
// write config.inc.php
602588
$configString = "<?php" . "\n" .
603-
"// Automatically Generated by TestLink Installer - " .
604-
date(DATE_RFC822) . "\n";
589+
"// Automatically Generated by TestLink Installer - " . date(
590+
DATE_RFC822) . "\n";
605591
$configString .= "define('DB_TYPE', '" . $db_type . "');\n";
606592
$configString .= "define('DB_USER', '" . $db_login . "');\n";
607593
$configString .= "define('DB_PASS', '" . $db_passwd . "');\n";

install/installUtils.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ function create_user_for_db($db_type, $db_name, $db_server, $db_admin_name,
252252
$msg = "ko - fatal error - can't get db server user list !!!";
253253
}
254254

255-
if ($try_create_user == 1 && ! is_null($user_list) && count($user_list) > 0) {
255+
if ($try_create_user == 1 && ! empty($user_list)) {
256256

257257
$user_list = array_map('strtolower', $user_list);
258258
$user_exists = in_array($login_lc, $user_list);

lib/ajax/gettestcasesummary.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,20 @@
1616
// take care of proper escaping when magic_quotes_gpc is enabled
1717
$_REQUEST = strings_stripSlashes($_REQUEST);
1818

19-
$tcase_mgr = new testcase($db);
19+
$tcaseMgr = new testcase($db);
2020
$tcase_id = intval(isset($_REQUEST['tcase_id']) ? $_REQUEST['tcase_id'] : 0);
2121
$tcversion_id = intval(
2222
isset($_REQUEST['tcversion_id']) ? $_REQUEST['tcversion_id'] : 0);
2323

2424
$info = '';
2525
if ($tcase_id > 0) {
2626
if ($tcversion_id > 0) {
27-
$tcase = $tcase_mgr->get_by_id($tcase_id, $tcversion_id);
27+
$tcase = $tcaseMgr->get_by_id($tcase_id, $tcversion_id);
2828
if (! is_null($tcase)) {
2929
$tcase = $tcase[0];
3030
}
3131
} else {
32-
$tcase = $tcase_mgr->get_last_version_info($tcase_id);
32+
$tcase = $tcaseMgr->getLastVersionInfo($tcase_id);
3333
}
3434
$info = $tcase['summary'];
3535

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -362,7 +362,7 @@ public function getProjectTestPlans($idCard)
362362

363363
if (! is_null($tproject)) {
364364
$items = $this->tprojectMgr->get_all_testplans($tproject[0]['id']);
365-
$op['items'] = (! is_null($items) && count($items) > 0) ? $items : null;
365+
$op['items'] = (! empty($items)) ? $items : null;
366366
} else {
367367
$op['message'] = "No Test Project identified by '" . $idCard . "'!";
368368
$op['status'] = 'error';
@@ -395,10 +395,10 @@ public function getProjectTestCases($idCard)
395395
$tcaseIDSet = array();
396396
$this->tprojectMgr->get_all_testcases_id($tproject[0]['id'],
397397
$tcaseIDSet);
398-
if (! is_null($tcaseIDSet) && count($tcaseIDSet) > 0) {
398+
if (! empty($tcaseIDSet)) {
399399
$op['items'] = array();
400400
foreach ($tcaseIDSet as $key => $tcaseID) {
401-
$item = $this->tcaseMgr->get_last_version_info($tcaseID);
401+
$item = $this->tcaseMgr->getLastVersionInfo($tcaseID);
402402
$item['keywords'] = $this->tcaseMgr->get_keywords_map(
403403
$tcaseID);
404404
$item['customfields'] = $this->tcaseMgr->get_linked_cfields_at_design(

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,7 +479,7 @@ public function getProjectTestPlans($idCard)
479479

480480
if (! is_null($tproject)) {
481481
$items = $this->tprojectMgr->get_all_testplans($tproject['id']);
482-
$op['items'] = (! is_null($items) && count($items) > 0) ? $items : null;
482+
$op['items'] = (! empty($items)) ? $items : null;
483483
} else {
484484
$op['message'] = "No Test Project identified by '" . $idCard . "'!";
485485
$op['status'] = 'error';
@@ -514,10 +514,10 @@ public function getProjectTestCases($idCard)
514514
$this->tprojectMgr->get_all_testcases_id($tproject['id'],
515515
$tcaseIDSet);
516516

517-
if (! is_null($tcaseIDSet) && count($tcaseIDSet) > 0) {
517+
if (! empty($tcaseIDSet)) {
518518
$op['items'] = array();
519519
foreach ($tcaseIDSet as $key => $tcaseID) {
520-
$item = $this->tcaseMgr->get_last_version_info($tcaseID);
520+
$item = $this->tcaseMgr->getLastVersionInfo($tcaseID);
521521
$item['keywords'] = $this->tcaseMgr->get_keywords_map(
522522
$tcaseID, $item['tcversion_id']);
523523
$item['customfields'] = $this->tcaseMgr->get_linked_cfields_at_design(
@@ -1513,7 +1513,7 @@ public function getPlanBuilds($idCard)
15131513

15141514
if (! is_null($tplan)) {
15151515
$items = $this->tplanMgr->get_builds($tplan['id']);
1516-
$op['items'] = (! is_null($items) && count($items) > 0) ? $items : null;
1516+
$op['items'] = (! empty($items)) ? $items : null;
15171517
} else {
15181518
$op['message'] = "No Test Plan identified by '" . $idCard . "'!";
15191519
$op['status'] = 'error';

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

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

350-
if (! is_null($tcaseIDSet) && count($tcaseIDSet) > 0) {
350+
if (! empty($tcaseIDSet)) {
351351
$op['items'] = array();
352352
foreach ($tcaseIDSet as $key => $tcaseID) {
353-
$item = $this->tcaseMgr->get_last_version_info($tcaseID);
353+
$item = $this->tcaseMgr->getLastVersionInfo($tcaseID);
354354
$item['keywords'] = $this->tcaseMgr->get_keywords_map(
355355
$tcaseID, $item['tcversion_id']);
356356
$item['customfields'] = $this->tcaseMgr->get_linked_cfields_at_design(
@@ -440,7 +440,7 @@ public function getProjectTestPlans(Response $response, $idCard)
440440

441441
if (! is_null($tproj)) {
442442
$items = $this->tprojectMgr->get_all_testplans($tproj['id']);
443-
$op['items'] = (! is_null($items) && count($items) > 0) ? $items : null;
443+
$op['items'] = (! empty($items)) ? $items : null;
444444
} else {
445445
$op['message'] = "No Test Project identified by '" . $idCard . "'!";
446446
$op['status'] = 'error';
@@ -466,7 +466,7 @@ public function getPlanBuilds(Response $response, $idCard)
466466

467467
if (! is_null($tplan)) {
468468
$items = $this->tplanMgr->get_builds($tplan['id']);
469-
$op['items'] = (! is_null($items) && count($items) > 0) ? $items : null;
469+
$op['items'] = (! empty($items)) ? $items : null;
470470
} else {
471471
$op['message'] = "No Test Plan identified by API KEY:" .
472472
$idCard['tplanApiKey'] . "";

lib/api/xmlrpc/v1/sample_clients/php/clientTestSuiteTestCaseStepsManagement.php

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@
4242
'expected_results' => $expected_results
4343
);
4444
}
45-
// ---------------------------------------------------------------------------------
4645

47-
// ---------------------------------------------------------------------------------
4846
// Get existent Test Case
4947
$additionalInfo = '';
5048
$tcCounter ++;
@@ -95,7 +93,6 @@
9593
new dBug($ret);
9694
exit();
9795
}
98-
// ----------------------------------------------------------------------------------------------------
9996

10097
// Now Create a Fake Step to PUSH
10198
$alienStartPos = intval($qtySteps / 3);
@@ -115,9 +112,7 @@
115112
new dBug($ret);
116113
exit();
117114
}
118-
// ----------------------------------------------------------------------------------------------------
119115

120-
// ----------------------------------------------------------------------------------------------------
121116
// Now TRY TO Create EXISTENT STEP
122117
$alienStartPos = intval($qtySteps / 3);
123118
$aliens[] = array(
@@ -136,9 +131,7 @@
136131
new dBug($ret);
137132
exit();
138133
}
139-
// ----------------------------------------------------------------------------------------------------
140134

141-
// ----------------------------------------------------------------------------------------------------
142135
// Now TRY TO UPDATE a NON EXISTENT STEP
143136
$hint = 'You have requested UPDATE of NON EXISTENT Step => we will CREATE it';
144137
$alienStartPos = 1000;
@@ -158,6 +151,5 @@
158151
new dBug($ret);
159152
exit();
160153
}
161-
// ----------------------------------------------------------------------------------------------------
162154

163155
?>

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

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@
2323
/**
2424
* IXR is the class used for the XML-RPC server
2525
*/
26+
use const Collator\OFF;
27+
use function testcase\getTCVersionIDFromVersion;
28+
2629
define("TL_APICALL", 'XML-RPC');
2730

2831
require_once '../../../../config.inc.php';
@@ -577,8 +580,8 @@ protected function userHasRight($rightToCheck,
577580
$tprojectid = intval(
578581
isset($context[self::$testProjectIDParamName]) ? $context[self::$testProjectIDParamName] : 0);
579582

580-
if ($tprojectid == 0 &&
581-
isset($this->args[self::$testProjectIDParamName])) {
583+
if ($tprojectid == 0 && isset(
584+
$this->args[self::$testProjectIDParamName])) {
582585
$tprojectid = $this->args[self::$testProjectIDParamName];
583586
}
584587

@@ -606,8 +609,8 @@ protected function userHasRight($rightToCheck,
606609
// Try using TestSuiteID to get TestProjectID
607610
$tsuiteid = intval(
608611
isset($context[self::$testSuiteIDParamName]) ? $context[self::$testSuiteIDParamName] : 0);
609-
if ($tsuiteid == 0 &&
610-
isset($this->args[self::$testSuiteIDParamName])) {
612+
if ($tsuiteid == 0 && isset(
613+
$this->args[self::$testSuiteIDParamName])) {
611614
$tsuiteid = intval($this->args[self::$testSuiteIDParamName]);
612615
}
613616
if ($tsuiteid > 0) {
@@ -2314,7 +2317,7 @@ public function getProjectTestPlans($args)
23142317
if ($status_ok) {
23152318
$testProjectID = $this->args[self::$testProjectIDParamName];
23162319
$info = $this->tprojectMgr->get_all_testplans($testProjectID);
2317-
if (! is_null($info) && count($info) > 0) {
2320+
if (! empty($info)) {
23182321
$info = array_values($info);
23192322
}
23202323
return $info;
@@ -4672,8 +4675,8 @@ public function getTestCaseAttachments($args)
46724675
return $this->errors;
46734676
}
46744677

4675-
if ($status_ok &&
4676-
! $this->_isParamPresent(self::$versionNumberParamName)) {
4678+
if ($status_ok && ! $this->_isParamPresent(
4679+
self::$versionNumberParamName)) {
46774680
try {
46784681
$tc = $this->getTestCase($args, self::THROW_ON_ERROR);
46794682
$this->args[self::$versionNumberParamName] = $tc[0][self::$versionNumberParamName];
@@ -6931,7 +6934,7 @@ public function createTestCaseSteps($args)
69316934
$item = $this->tcaseMgr->get_last_active_version($tcaseID);
69326935
if (is_null($item)) {
69336936
// get last version no matter if is active
6934-
$dummy = $this->tcaseMgr->get_last_version_info($tcaseID);
6937+
$dummy = $this->tcaseMgr->getLastVersionInfo($tcaseID);
69356938
$dummy['tcversion_id'] = $dummy['id'];
69366939
$item[0] = $dummy;
69376940
}
@@ -7241,8 +7244,8 @@ public function setTestCaseExecutionType($args)
72417244
'checkTestCaseVersionNumber'
72427245
);
72437246
$status_ok = $this->_runChecks($checkFunctions, $msg_prefix);
7244-
if ($status_ok && ! $this->_isParamPresent(
7245-
self::$executionTypeParamName)) {
7247+
if ($status_ok &&
7248+
! $this->_isParamPresent(self::$executionTypeParamName)) {
72467249
$status_ok = false;
72477250
$msg = sprintf(MISSING_REQUIRED_PARAMETER_STR,
72487251
self::$customFieldsParamName);
@@ -7869,7 +7872,7 @@ private function updateTestCaseGetTCVID($tcaseID)
78697872
}
78707873
} else {
78717874
// get latest version info
7872-
$dummy = $this->tcaseMgr->get_last_version_info($tcaseID);
7875+
$dummy = $this->tcaseMgr->getLastVersionInfo($tcaseID);
78737876
$dummy['tcversion_id'] = $dummy['id'];
78747877
$tcversion_id = $dummy['tcversion_id'];
78757878
}
@@ -8190,8 +8193,8 @@ public function getTestCaseBugs($args)
81908193
" WHERE parent_id = {$this->args[self::$testCaseIDParamName]})";
81918194

81928195
if (! is_null($execContext['build_id'])) {
8193-
$sql .= " AND build_id = " .
8194-
intval($execContext['build_id']);
8196+
$sql .= " AND build_id = " . intval(
8197+
$execContext['build_id']);
81958198
}
81968199

81978200
if (! is_null($execContext['platform_id'])) {
@@ -9193,7 +9196,8 @@ public function getTestSuite($args)
91939196
$items = $tprojectMgr->get_subtree($tproj['id'], $filters, $opt);
91949197

91959198
$ni = array();
9196-
if (! is_null($items) && ($l2d = count($items)) > 0) {
9199+
if (! empty($items)) {
9200+
$l2d = count($items);
91979201
$tg = $this->args[self::$testSuiteNameParamName];
91989202
for ($ydx = 0; $ydx <= $l2d; $ydx ++) {
91999203
if (strcmp($items[$ydx]['name'], $tg) == 0) {

0 commit comments

Comments
 (0)