Skip to content

Commit 38d02b4

Browse files
committed
Cleaned up code - some files were refactored with refactor
The following adjustments were made: - Change array_key_exists() ternary to coalescing (ArrayKeyExistsTernaryThenValueToCoalescingRector) - Remove unnecessary ternary expressions (UnnecessaryTernaryExpressionRector) - Shortens if return false/true to direct return (SimplifyIfReturnBoolRector) - Changes if/else for same value as assign to ternary (SimplifyIfElseToTernaryRector) - Upgrade array callable to first class callable (FirstClassCallableRector) - Changes Closure to be static when possible (StaticClosureRector) - Upgrade string callback functions to first class callable (FunctionFirstClassCallableRector) - Use ===/!== over ==/!=, it values have the same type (UseIdenticalOverEqualWithSameTypeRector) - Change foreach() items assign to empty array to direct assign (ForeachItemsAssignToEmptyArrayToAssignRector) - Shorten else/if to elseif (ShortenElseIfRector) - Complete missing if/else brackets (CompleteMissingIfElseBracketRector) - Add missing dynamic properties (CompleteDynamicPropertiesRector)
1 parent b6594cf commit 38d02b4

168 files changed

Lines changed: 1709 additions & 1925 deletions

File tree

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
@@ -191,7 +191,7 @@ function notifyGlobalAdmins(&$dbHandler, &$userObj)
191191
$validator = new Zend_Validate_EmailAddress();
192192
foreach ($mail['to'] as $mm) {
193193
$ema = trim($mm);
194-
if ($ema == '') {
194+
if ($ema === '') {
195195
continue;
196196
}
197197
if (! $validator->isValid($ema)) {

install/installNewDB.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@
334334
// have not returned prefix.
335335
//
336336
$dbVersionTable = $tables['db_version'];
337-
if ($dbVersionTable == 'db_version' && trim($db_table_prefix) != '') {
337+
if ($dbVersionTable == 'db_version' && trim($db_table_prefix) !== '') {
338338
$dbVersionTable = $db_table_prefix . $dbVersionTable;
339339
}
340340
$sql = "SELECT * FROM {$dbVersionTable} ORDER BY upgrade_ts DESC";
@@ -458,7 +458,7 @@
458458
}
459459

460460
// Now data migration must be done if needed
461-
if ($migration_process != '') {
461+
if ($migration_process !== '') {
462462
require_once $migration_functions_file;
463463
$migration_process($db, $tables);
464464
}

install/installUtils.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ function getDirSqlFiles($dirPath, $add_dirpath = 0)
3636
// needed because is_dir() cached result. See PHP Manual
3737
clearstatcache();
3838

39-
if ($file != "." && $file != ".." && ! $is_folder) {
39+
if ($file !== "." && $file !== ".." && ! $is_folder) {
4040
// use only if extension is sql
4141
$file = trim($file);
4242
$path_parts = pathinfo($file);
@@ -254,7 +254,7 @@ function create_user_for_db($db_type, $db_name, $db_server, $db_admin_name,
254254

255255
if ($try_create_user == 1 && ! empty($user_list)) {
256256

257-
$user_list = array_map('strtolower', $user_list);
257+
$user_list = array_map(strtolower(...), $user_list);
258258
$user_exists = in_array($login_lc, $user_list);
259259
if (! $user_exists) {
260260
$msg = '';
@@ -389,7 +389,7 @@ function check_db_loaded_extension($db_type)
389389
// keep in mind this constant will contain
390390
// the operating system PHP was built on
391391
//
392-
if (PHP_OS == 'WINNT' || $isPHPGTE7) {
392+
if (PHP_OS === 'WINNT' || $isPHPGTE7) {
393393

394394
// First Time:
395395
//
@@ -677,7 +677,7 @@ function _mssql_make_user_with_grants($db, $the_host, $db_name, $login, $passwd)
677677

678678
// Check if has been created, because I'm not able to get return code.
679679
$user_list = getUserList($db, 'mssql');
680-
$user_list = array_map('strtolower', $user_list);
680+
$user_list = array_map(strtolower(...), $user_list);
681681
$user_exists = in_array(trim($login), $user_list);
682682
if (! $user_exists) {
683683
$op->status_ok = false;

install/sqlParser.class.php

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public function process($filename)
4242

4343
// part of this logic has been copied from the setup of EVENTUM
4444
$contents = file($filename);
45-
$do_replace = trim($this->db_table_prefix) != '';
45+
$do_replace = trim($this->db_table_prefix) !== '';
4646

4747
// From PHP Manual Notes on using a class function as Filter
4848
// This FAILS!!!
@@ -127,12 +127,10 @@ protected function only_good_sql($v, $comment_char = '-')
127127
$v_c = trim($v, "\r\n ");
128128
$pos = strpos($v_c, $findme);
129129

130-
if ($pos === false) {
131-
$use_v = true;
132-
} else {
133-
if ($pos == 0) {
134-
$use_v = false;
135-
}
130+
if ($pos === false) {
131+
$use_v = true;
132+
} elseif ($pos == 0) {
133+
$use_v = false;
136134
}
137135

138136
// Empty line must not be used

lib/ajax/gettestcasesummary.php

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,10 +38,6 @@
3838
$info = str_replace("<p>", "", $info);
3939
$info = str_replace("</p>", "<br>", $info);
4040

41-
if ($info == "") {
42-
$info = lang_get("empty_tc_summary");
43-
} else {
44-
$info = '<b>' . lang_get('summary') . '</b><br>' . $info;
45-
}
41+
$info = $info == "" ? lang_get("empty_tc_summary") : '<b>' . lang_get('summary') . '</b><br>' . $info;
4642
}
4743
echo $info;

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

Lines changed: 30 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@
4141
class tlRestApi
4242
{
4343

44+
public $app;
45+
4446
public static $version = "1.0";
4547

4648
/**
@@ -125,92 +127,34 @@ public function __construct()
125127

126128
// test route with anonymous function
127129
$this->app->get('/who',
128-
function (): void {
130+
static function (): void {
129131
echo __CLASS__ . ' : Get Route /who';
130132
});
131133

132-
$this->app->get('/whoAmI', [
133-
$this,
134-
'authenticate'
135-
], [
136-
$this,
137-
'whoAmI'
138-
]);
139-
$this->app->get('/testprojects', [
140-
$this,
141-
'authenticate'
142-
], [
143-
$this,
144-
'getProjects'
145-
]);
146-
147-
$this->app->get('/testprojects/:id', [
148-
$this,
149-
'authenticate'
150-
], [
151-
$this,
152-
'getProjects'
153-
]);
154-
$this->app->get('/testprojects/:id/testcases',
155-
[
156-
$this,
157-
'authenticate'
158-
], [
159-
$this,
160-
'getProjectTestCases'
161-
]);
162-
$this->app->get('/testprojects/:id/testplans',
163-
[
164-
$this,
165-
'authenticate'
166-
], [
167-
$this,
168-
'getProjectTestPlans'
169-
]);
170-
171-
$this->app->post('/testprojects', [
172-
$this,
173-
'authenticate'
174-
], [
175-
$this,
176-
'createTestProject'
177-
]);
178-
$this->app->post('/executions', [
179-
$this,
180-
'authenticate'
181-
], [
182-
$this,
183-
'createTestCaseExecution'
184-
]);
185-
$this->app->post('/testplans', [
186-
$this,
187-
'authenticate'
188-
], [
189-
$this,
190-
'createTestPlan'
191-
]);
192-
$this->app->post('/testplans/:id', [
193-
$this,
194-
'authenticate'
195-
], [
196-
$this,
197-
'updateTestPlan'
198-
]);
199-
200-
$this->app->post('/testsuites', [
201-
$this,
202-
'authenticate'
203-
], [
204-
$this,
205-
'createTestSuite'
206-
]);
207-
$this->app->post('/testcases', [
208-
$this,
209-
'authenticate'
210-
], [
211-
$this,
212-
'createTestCase'
213-
]);
134+
$this->app->get('/whoAmI', $this->authenticate(...), $this->whoAmI(...));
135+
$this->app->get('/testprojects', $this->authenticate(...),
136+
$this->getProjects(...));
137+
138+
$this->app->get('/testprojects/:id', $this->authenticate(...),
139+
$this->getProjects(...));
140+
$this->app->get('/testprojects/:id/testcases', $this->authenticate(...),
141+
$this->getProjectTestCases(...));
142+
$this->app->get('/testprojects/:id/testplans', $this->authenticate(...),
143+
$this->getProjectTestPlans(...));
144+
145+
$this->app->post('/testprojects', $this->authenticate(...),
146+
$this->createTestProject(...));
147+
$this->app->post('/executions', $this->authenticate(...),
148+
$this->createTestCaseExecution(...));
149+
$this->app->post('/testplans', $this->authenticate(...),
150+
$this->createTestPlan(...));
151+
$this->app->post('/testplans/:id', $this->authenticate(...),
152+
$this->updateTestPlan(...));
153+
154+
$this->app->post('/testsuites', $this->authenticate(...),
155+
$this->createTestSuite(...));
156+
$this->app->post('/testcases', $this->authenticate(...),
157+
$this->createTestCase(...));
214158

215159
$this->db = new database(DB_TYPE);
216160
$this->db->db->SetFetchMode(ADODB_FETCH_ASSOC);
@@ -437,10 +381,9 @@ public function createTestProject()
437381
try {
438382
$request = $this->app->request();
439383
$item = json_decode($request->getBody());
440-
$op['id'] = $this->tprojectMgr->create($item,
441-
[
442-
'doChecks' => true
443-
]);
384+
$op['id'] = $this->tprojectMgr->create($item, [
385+
'doChecks' => true
386+
]);
444387
$op = [
445388
'status' => 'ok',
446389
'message' => 'ok'

0 commit comments

Comments
 (0)