Skip to content

Commit efd8f4c

Browse files
committed
Cleaned up code - some adjustments to selected files
The following adjustments were made: - Sections of code should not be commented out (PHP:S125) - Files should end with a newline (PHP:S113) - Mergeable "if" statements should be combined (PHP:S1066) - Redundant pairs of parentheses should be removed (PHP:1110) - Boolean literals should not be redundant (PHP:S1125) - Lines should not end with trailing whitespaces (PHP:S1131) - Use empty() to check whether the array is empty or not (PHP:S1155) - Unused local variables should be removed (PHP:S1481) - PHP keywords and constants "true", "false", "null" should be lower case (PHP:S1781) - Method visibility should be explicitly declared (PHP:S1784) - "elseif" keyword should be used in place of "else if" keywords (PHP:S1793) - Unused assignments should be removed (PHP:S1854) - "require_once" and "include_once" should be used instead of "require" and "include" (PHP:S2003)
1 parent 7d5c2b5 commit efd8f4c

11 files changed

Lines changed: 627 additions & 771 deletions

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

Lines changed: 98 additions & 101 deletions
Large diffs are not rendered by default.

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

Lines changed: 211 additions & 271 deletions
Large diffs are not rendered by default.

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

Lines changed: 268 additions & 315 deletions
Large diffs are not rendered by default.

lib/api/rest/v3/core/routes.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
// @20201124 - I do not understand this
1010
// $app->get('/',World::class . ':hello');
1111

12-
// using array(), was the way in Slim3 and
12+
// using array(), was the way in Slim3 and
1313
// still seems valid
1414
$app->get('/whoAmI',array($app->restApi,'whoAmI'));
1515

@@ -20,47 +20,47 @@
2020

2121
$app->get('/testprojects/{id}/testcases',
2222
array($app->restApi,'getProjectTestCases'));
23-
$app->get('/testprojects/{mixedID}/testplans',
23+
$app->get('/testprojects/{mixedID}/testplans',
2424
array($app->restApi,'getProjectTestPlans'));
2525

26-
$app->get('/testplans/{tplanApiKey}/builds',
26+
$app->get('/testplans/{tplanApiKey}/builds',
2727
array($app->restApi,'getPlanBuilds'));
2828

2929
/*
30-
$app->get('/builds/{id}',
30+
$app->get('/builds/{id}',
3131
array($app->restApi,'getBuild'));
3232
*/
3333

34-
$app->post('/executions',
34+
$app->post('/executions',
3535
array($app->restApi,'createTestCaseExecution'));
3636

3737
$app->post('/builds',
3838
array($app->restApi,'createBuild'));
3939

40-
$app->post('/keywords',
40+
$app->post('/keywords',
4141
array($app->restApi,'createKeyword'));
4242

43-
$app->post('/testcases',
43+
$app->post('/testcases',
4444
array($app->restApi,'createTestCase'));
4545

46-
$app->post('/testplans',
46+
$app->post('/testplans',
4747
array($app->restApi,'createTestPlan'));
4848

4949
$app->post('/testprojects',
5050
array($app->restApi,'createTestProject'));
5151

52-
$app->post('/testsuites',
52+
$app->post('/testsuites',
5353
array($app->restApi,'createTestSuite'));
5454

5555

5656
// Update Routes
5757
// Following advice from
5858
// https://restfulapi.net/rest-put-vs-post/
5959
//
60-
$app->put('/builds/{id}',
60+
$app->put('/builds/{id}',
6161
array($app->restApi,'updateBuild'));
6262

63-
$app->put('/testplans/{id}',
63+
$app->put('/testplans/{id}',
6464
array($app->restApi,'updateTestPlan'));
6565

6666
$app->put('/testplans/{tplan_id}/platforms',

lib/api/rest/v3/custom/api/RestApiCustomExample.class.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<?php
1+
<?php
22
/**
33
* @filesource RestApiCustomExample.class.php
44
*
@@ -23,28 +23,28 @@
2323

2424
/**
2525
* @author Francisco Mancardi <francisco.mancardi@gmail.com>
26-
* @package TestLink
26+
* @package TestLink
2727
*/
2828
class RestApiCustomExample extends RestApi
2929
{
3030
public static $version = "1.0";
3131

3232
/**
3333
*/
34-
public function __construct()
34+
public function __construct()
3535
{
3636
$this->db = new database(DB_TYPE);
3737
$this->db->db->SetFetchMode(ADODB_FETCH_ASSOC);
3838
doDBConnect($this->db,database::ONERROREXIT);
39-
}
39+
}
4040

4141

4242

4343
/**
4444
*
4545
*/
4646
public function whoAmI(Request $request, Response $response, $args)
47-
{
47+
{
4848
$msg = json_encode(array('name' => __CLASS__ . ' : You have called Get Route /whoAmI'));
4949
$response->getBody()->write($msg);
5050
return $response;

lib/api/rest/v3/custom/routes/routesCustomExample.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@
1313
$app->get('/CustomExample/whoAmI',
1414
array($app->restApiCustomExample,'whoAmI'));
1515

16-
};
16+
};

lib/api/rest/v3/index.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,13 @@
55
use Slim\Factory\AppFactory;
66

77
require_once '../../../../config.inc.php';
8-
require 'autoload.php';
9-
require 'RestApi.class.php';
8+
require_once 'autoload.php';
9+
require_once 'RestApi.class.php';
1010

1111
$app = AppFactory::create();
1212

13-
// CRITIC
14-
// This will work if your url to test link
13+
// CRITIC
14+
// This will work if your url to test link
1515
// is something like
1616
//
1717
// https://testlink.antartic.org/
@@ -21,15 +21,15 @@
2121
// You need to use:
2222
// $basePath = "/testlink/lib/api/rest/v3";
2323
//
24-
// The standard .htaccess provided with testlink,
24+
// The standard .htaccess provided with testlink,
2525
// that is similar to the .htaccess provided by MantisBT
2626
// it's ok!!!
2727
// No need to proceed as detailed in this documentation
28-
// - https://www.slimframework.com/docs/v4/start/web-servers.html
28+
// - https://www.slimframework.com/docs/v4/start/web-servers.html
2929
// Section: Running in a sub-directory
3030
//
3131
// - https://akrabat.com/running-slim-4-in-a-subdirectory/
32-
// BUT this is a good example to understand how to configure
32+
// BUT this is a good example to understand how to configure
3333
//
3434
$basePath = config_get('restAPI')->basePath;
3535
$app->setBasePath($basePath);
@@ -49,7 +49,7 @@
4949
foreach ($itera as $fileinfo) {
5050
if ($fileinfo->isFile()) {
5151
$who = $fileinfo->getFilename();
52-
require $where . $who;
52+
require_once $where . $who;
5353

5454
// generate class name
5555
$className = str_replace('.class.php', '', $who);
@@ -72,15 +72,15 @@
7272
foreach ($itera as $fileinfo) {
7373
if ($fileinfo->isFile()) {
7474
$who = $fileinfo->getFilename();
75-
$customRoutes = require $where . $who;
75+
$customRoutes = require_once $where . $who;
7676
$customRoutes($app);
7777
}
7878
}
7979
}
8080
// * Load Custom API - END
8181

8282
// Register Standard routes
83-
$routes = require './core/routes.php';
83+
$routes = require_once './core/routes.php';
8484
$routes($app);
8585

8686
// Middleware

lib/api/rest/v3/untitled.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

lib/attachments/attachmentdelete.php

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<?php
22
/**
3-
* TestLink Open Source Project - http://testlink.sourceforge.net/
4-
* This script is distributed under the GNU General Public License 2 or later.
3+
* TestLink Open Source Project - http://testlink.sourceforge.net/
4+
* This script is distributed under the GNU General Public License 2 or later.
55
*
66
* @filesource attachmentdelete.php
77
* Deletes an attachment by a given id
@@ -11,7 +11,7 @@
1111
require_once '../functions/attachments.inc.php';
1212
testlinkInitPage($db,false,false,"checkRights");
1313

14-
$args = init_args();
14+
$args = init_args();
1515
$deleteDone = false;
1616
if ($args->id)
1717
{
@@ -24,7 +24,7 @@
2424
{
2525
logAuditEvent(TLS("audit_attachment_deleted",
2626
$attachmentInfo['title']),"DELETE",$args->id,"attachments");
27-
}
27+
}
2828
}
2929
}
3030

@@ -50,13 +50,13 @@ function init_args()
5050

5151

5252
/**
53-
* @param $db resource the database connection handle
54-
* @param $user the current active user
55-
*
53+
* @param database $db resource the database connection handle
54+
* @param tlUser $user the current active user
55+
*
5656
* @return boolean returns true if the page can be accessed
5757
*/
5858
function checkRights(&$db,&$user)
5959
{
6060
return config_get("attachments")->enabled;
6161
}
62-
?>
62+
?>

lib/attachments/attachmentdownload.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ function init_args(&$dbHandler)
160160
}
161161

162162
/**
163-
* @param $db resource the database connection handle
164-
* @param $user the current active user
163+
* @param database $db resource the database connection handle
164+
* @param tlUser $user the current active user
165165
* @return boolean returns true if the page can be accessed
166166
*/
167167
function checkRights(&$db,&$user)

0 commit comments

Comments
 (0)