Skip to content

Commit 2665d47

Browse files
committed
Code Cleanup
1 parent 71b6214 commit 2665d47

File tree

9 files changed

+41
-34
lines changed

9 files changed

+41
-34
lines changed

FoodScanAppService.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434
}
3535
}
3636
switch ($_REQUEST['Service']) {
37-
/********************* User Functions *********************/
37+
/********** User Functions **********/
3838
case User::REGISTRATION_ACTION:
3939
case User::LOGIN_ACTION:
4040
case User::CHANGE_PASSWORD_ACTION:
@@ -88,7 +88,7 @@
8888
$secret_key = addslashes($secret_key);
8989

9090
$isSecure = (new Security($db))->checkForSecurityNew($access_key, $secret_key);
91-
$isSecure = YES;
91+
$isSecure = YES;
9292

9393
if ($isSecure === NO) {
9494
$data['status'] = FAILED;
@@ -99,7 +99,7 @@
9999
} else {
100100
$product = new Product($db);
101101
$data = $product->callService($_REQUEST['Service'], $postData);
102-
if ($isSecure !== YES || $isSecure !== YES) {
102+
if ($isSecure !== YES || $isSecure !== YES) {
103103
if ($isSecure['key'] === 'Temp') {
104104
$data['TempToken'] = $isSecure['value'];
105105
} else {
@@ -119,6 +119,6 @@
119119
$data['message'] = $_REQUEST['Service'];
120120
}
121121
}
122-
//(new AllowCors)->init(); // Set CORS headers
122+
// (new AllowCors)->init(); // Set CORS headers
123123
header('Content-type: application/json');
124124
echo json_encode($data);

src/AllowCors.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ class AllowCors
1313
const ALLOW_CORS_METHOD_KEY = 'Access-Control-Allow-Methods';
1414
const ALLOW_CORS_ORIGIN_VALUE = '*';
1515
const ALLOW_CORS_METHOD_VALUE = 'GET, POST, PUT, DELETE, PATCH, OPTIONS';
16+
1617
/**
1718
* Initialize the Cross-Origin Resource Sharing (CORS) headers.
1819
*

src/Database.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,9 @@
66
*/
77

88
declare(strict_types=1);
9+
910
namespace Lifyzer\Api;
11+
1012
use PDO;
1113

1214
class Database extends PDO

src/HelperFunctions.php

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
<?php
22

33
declare(strict_types=1);
4-
namespace Lifyzer\Api;
54

6-
use function foo\func;
5+
namespace Lifyzer\Api;
76

87
function errorLogFunction(string $errorMessage): void
98
{
@@ -53,19 +52,21 @@ function generateRandomString(int $length = 10): string
5352
}
5453
return $randomString;
5554
}
56-
function curlRequestLoad($url,$isParam = false,$params=""){
55+
56+
function curlRequestLoad($url, $isParam = false, $params = "")
57+
{
5758
$ch = curl_init();
58-
curl_setopt_array($ch, array(
59+
curl_setopt_array($ch, [
5960
CURLOPT_URL => $url,
6061
CURLOPT_RETURNTRANSFER => true,
6162
CURLOPT_SSL_VERIFYPEER => false,
6263
CURLOPT_SSL_VERIFYHOST => 0,
63-
));
64-
if ($isParam){
65-
curl_setopt_array(CURLOPT_POSTFIELDS,$params);
64+
]);
65+
if ($isParam) {
66+
curl_setopt_array(CURLOPT_POSTFIELDS, $params);
6667
}
6768
$result = curl_exec($ch);
6869
curl_close($ch);
6970
$tempArr = json_decode($result, true);
7071
return $tempArr;
71-
}
72+
}

src/Logger.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
declare(strict_types=1);
4+
45
namespace Lifyzer\Api;
56

67
class Logger
@@ -14,7 +15,7 @@ public function __construct()
1415
ini_set('error_log', self::LOG_PATH . self::LOG_FILENAME);
1516
ini_set('ignore_repeated_errors', 'On');
1617
}
17-
18+
1819
public function showErrors(): void
1920
{
2021
error_reporting(E_ALL); // Since PHP 5.4 E_STRICT became part of E_ALL

src/PdoFunctions.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace Lifyzer\Api;
4+
45
use PDO;
56
use PDOException;
67

@@ -106,6 +107,7 @@ function editData(PDO $connection, $function_name = '', $table_name, $dataArray,
106107
$data['sql'] = $sql;
107108
return $data;
108109
}
110+
109111
function getSingleTableData(PDO $connection, $table, $sql, $columns, $customCondition, $dataArray)
110112
{
111113
try {
@@ -250,4 +252,4 @@ function getMultipleTableData(PDO $connection, $table, $sql, $columns, $customCo
250252
return $error_message;
251253
}
252254
return $statement;
253-
}
255+
}

src/Product.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ public function getUSAFoodDetails($product_name)
468468
$product_array['sodium'] = $key['value'];
469469
break;
470470
case 'Total lipid (fat)':
471-
$product_array['fat_amount'] = $key['value'];;
471+
$product_array['fat_amount'] = $key['value'];
472472
break;
473473
}
474474
}
@@ -481,20 +481,20 @@ public function getUSAFoodDetails($product_name)
481481
public function getSwissFoodDetails($product_name)
482482
{
483483
$ch = curl_init();
484-
curl_setopt_array($ch, array(
484+
curl_setopt_array($ch, [
485485
CURLOPT_URL => getenv('URL_SWISS_FOOD_API'),
486486
CURLOPT_RETURNTRANSFER => true,
487487
CURLOPT_SSL_VERIFYPEER => false,
488488
CURLOPT_SSL_VERIFYHOST => 0,
489489
CURLOPT_CUSTOMREQUEST => "POST",
490490
CURLOPT_POSTFIELDS => "{\"query\":{\"query_string\":{\"query\":\"" . $product_name . "\"}}}",
491-
CURLOPT_HTTPHEADER => array(
491+
CURLOPT_HTTPHEADER => [
492492
"Authorization: Token token=" . getenv('SWISS_FOOD_KEY'),
493493
"Content-ApiProviders: application/vnd.api+json",
494494
"Accept: application/json",
495495
"Content-ApiProviders: application/json"
496-
),
497-
));
496+
],
497+
]);
498498
$result = curl_exec($ch);
499499
curl_close($ch);
500500
$tempArr = json_decode($result, true);

src/Security.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22

33
namespace Lifyzer\Api;
4+
45
use PDO;
56

67
class Security

src/User.php

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@
33
namespace Lifyzer\Api;
44

55
use PDO;
6-
use stdClass;
76
use PHPMailer\PHPMailer\Exception;
8-
use PHPMailer\PHPMailer\PHPMailer;
7+
use stdClass;
98

109
class User
1110
{
@@ -62,32 +61,32 @@ public function callService($service, $postData)
6261
}
6362
}
6463

65-
private function addLogs($userData) {
64+
private function addLogs($userData)
65+
{
6666

6767
$connection = $this->connection;
6868

6969
$user_id = validateObject($userData, 'user_id', "");
7070
$user_id = addslashes($user_id);
7171

7272
$api = validateObject($userData, 'api', "");
73-
$api = addslashes($api);
73+
$api = addslashes($api);
7474

7575
$response = validateObject($userData, 'response', "");
76-
$response = addslashes($response);
76+
$response = addslashes($response);
7777

7878
$user_array = [
79-
'api' => $api,
80-
'response' => $response,
81-
'user_id' => $user_id
82-
];
79+
'api' => $api,
80+
'response' => $response,
81+
'user_id' => $user_id
82+
];
8383

8484
$user_response = addData($connection, 'Registration', TABLE_LOGS, $user_array);
8585

86-
if ($user_response[STATUS_KEY] === SUCCESS) {
86+
if ($user_response[STATUS_KEY] === SUCCESS) {
8787
$status = SUCCESS;
8888
$message = "successfully loged";
89-
}
90-
else{
89+
} else {
9190
$status = FAILED;
9291
$message = SOMETHING_WENT_WRONG_TRY_AGAIN_LATER;
9392
}
@@ -186,7 +185,7 @@ private function registration($userData)
186185
],
187186
new Email()
188187
);
189-
} catch (\PHPMailer\PHPMailer\Exception $e) {
188+
} catch (Exception $e) {
190189
$status = FAILED;
191190
$message = SOMETHING_WENT_WRONG_TRY_AGAIN_LATER;
192191
}
@@ -456,7 +455,7 @@ private function forgotPassword($userData)
456455
* @param array $data
457456
* @param Email $email
458457
*
459-
* @throws \PHPMailer\PHPMailer\Exception
458+
* @throws Exception
460459
*/
461460
private function sendWelcomeEmail(array $data, Email $email)
462461
{
@@ -489,7 +488,7 @@ private function sendWelcomeEmail(array $data, Email $email)
489488
* @param array $data
490489
* @param Email $email
491490
*
492-
* @throws \PHPMailer\PHPMailer\Exception
491+
* @throws Exception
493492
*/
494493
private function sendForgotPassword(array $data, Email $email)
495494
{

0 commit comments

Comments
 (0)