Skip to content

Commit

Permalink
Code Cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
pH-7 committed Jul 4, 2021
1 parent 71b6214 commit 2665d47
Show file tree
Hide file tree
Showing 9 changed files with 41 additions and 34 deletions.
8 changes: 4 additions & 4 deletions FoodScanAppService.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
}
}
switch ($_REQUEST['Service']) {
/********************* User Functions *********************/
/********** User Functions **********/
case User::REGISTRATION_ACTION:
case User::LOGIN_ACTION:
case User::CHANGE_PASSWORD_ACTION:
Expand Down Expand Up @@ -88,7 +88,7 @@
$secret_key = addslashes($secret_key);

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

if ($isSecure === NO) {
$data['status'] = FAILED;
Expand All @@ -99,7 +99,7 @@
} else {
$product = new Product($db);
$data = $product->callService($_REQUEST['Service'], $postData);
if ($isSecure !== YES || $isSecure !== YES) {
if ($isSecure !== YES || $isSecure !== YES) {
if ($isSecure['key'] === 'Temp') {
$data['TempToken'] = $isSecure['value'];
} else {
Expand All @@ -119,6 +119,6 @@
$data['message'] = $_REQUEST['Service'];
}
}
//(new AllowCors)->init(); // Set CORS headers
// (new AllowCors)->init(); // Set CORS headers
header('Content-type: application/json');
echo json_encode($data);
1 change: 1 addition & 0 deletions src/AllowCors.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ class AllowCors
const ALLOW_CORS_METHOD_KEY = 'Access-Control-Allow-Methods';
const ALLOW_CORS_ORIGIN_VALUE = '*';
const ALLOW_CORS_METHOD_VALUE = 'GET, POST, PUT, DELETE, PATCH, OPTIONS';

/**
* Initialize the Cross-Origin Resource Sharing (CORS) headers.
*
Expand Down
2 changes: 2 additions & 0 deletions src/Database.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
*/

declare(strict_types=1);

namespace Lifyzer\Api;

use PDO;

class Database extends PDO
Expand Down
17 changes: 9 additions & 8 deletions src/HelperFunctions.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
<?php

declare(strict_types=1);
namespace Lifyzer\Api;

use function foo\func;
namespace Lifyzer\Api;

function errorLogFunction(string $errorMessage): void
{
Expand Down Expand Up @@ -53,19 +52,21 @@ function generateRandomString(int $length = 10): string
}
return $randomString;
}
function curlRequestLoad($url,$isParam = false,$params=""){

function curlRequestLoad($url, $isParam = false, $params = "")
{
$ch = curl_init();
curl_setopt_array($ch, array(
curl_setopt_array($ch, [
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 0,
));
if ($isParam){
curl_setopt_array(CURLOPT_POSTFIELDS,$params);
]);
if ($isParam) {
curl_setopt_array(CURLOPT_POSTFIELDS, $params);
}
$result = curl_exec($ch);
curl_close($ch);
$tempArr = json_decode($result, true);
return $tempArr;
}
}
3 changes: 2 additions & 1 deletion src/Logger.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

declare(strict_types=1);

namespace Lifyzer\Api;

class Logger
Expand All @@ -14,7 +15,7 @@ public function __construct()
ini_set('error_log', self::LOG_PATH . self::LOG_FILENAME);
ini_set('ignore_repeated_errors', 'On');
}

public function showErrors(): void
{
error_reporting(E_ALL); // Since PHP 5.4 E_STRICT became part of E_ALL
Expand Down
4 changes: 3 additions & 1 deletion src/PdoFunctions.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Lifyzer\Api;

use PDO;
use PDOException;

Expand Down Expand Up @@ -106,6 +107,7 @@ function editData(PDO $connection, $function_name = '', $table_name, $dataArray,
$data['sql'] = $sql;
return $data;
}

function getSingleTableData(PDO $connection, $table, $sql, $columns, $customCondition, $dataArray)
{
try {
Expand Down Expand Up @@ -250,4 +252,4 @@ function getMultipleTableData(PDO $connection, $table, $sql, $columns, $customCo
return $error_message;
}
return $statement;
}
}
10 changes: 5 additions & 5 deletions src/Product.php
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,7 @@ public function getUSAFoodDetails($product_name)
$product_array['sodium'] = $key['value'];
break;
case 'Total lipid (fat)':
$product_array['fat_amount'] = $key['value'];;
$product_array['fat_amount'] = $key['value'];
break;
}
}
Expand All @@ -481,20 +481,20 @@ public function getUSAFoodDetails($product_name)
public function getSwissFoodDetails($product_name)
{
$ch = curl_init();
curl_setopt_array($ch, array(
curl_setopt_array($ch, [
CURLOPT_URL => getenv('URL_SWISS_FOOD_API'),
CURLOPT_RETURNTRANSFER => true,
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_SSL_VERIFYHOST => 0,
CURLOPT_CUSTOMREQUEST => "POST",
CURLOPT_POSTFIELDS => "{\"query\":{\"query_string\":{\"query\":\"" . $product_name . "\"}}}",
CURLOPT_HTTPHEADER => array(
CURLOPT_HTTPHEADER => [
"Authorization: Token token=" . getenv('SWISS_FOOD_KEY'),
"Content-ApiProviders: application/vnd.api+json",
"Accept: application/json",
"Content-ApiProviders: application/json"
),
));
],
]);
$result = curl_exec($ch);
curl_close($ch);
$tempArr = json_decode($result, true);
Expand Down
1 change: 1 addition & 0 deletions src/Security.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php

namespace Lifyzer\Api;

use PDO;

class Security
Expand Down
29 changes: 14 additions & 15 deletions src/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@
namespace Lifyzer\Api;

use PDO;
use stdClass;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\PHPMailer;
use stdClass;

class User
{
Expand Down Expand Up @@ -62,32 +61,32 @@ public function callService($service, $postData)
}
}

private function addLogs($userData) {
private function addLogs($userData)
{

$connection = $this->connection;

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

$api = validateObject($userData, 'api', "");
$api = addslashes($api);
$api = addslashes($api);

$response = validateObject($userData, 'response', "");
$response = addslashes($response);
$response = addslashes($response);

$user_array = [
'api' => $api,
'response' => $response,
'user_id' => $user_id
];
'api' => $api,
'response' => $response,
'user_id' => $user_id
];

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

if ($user_response[STATUS_KEY] === SUCCESS) {
if ($user_response[STATUS_KEY] === SUCCESS) {
$status = SUCCESS;
$message = "successfully loged";
}
else{
} else {
$status = FAILED;
$message = SOMETHING_WENT_WRONG_TRY_AGAIN_LATER;
}
Expand Down Expand Up @@ -186,7 +185,7 @@ private function registration($userData)
],
new Email()
);
} catch (\PHPMailer\PHPMailer\Exception $e) {
} catch (Exception $e) {
$status = FAILED;
$message = SOMETHING_WENT_WRONG_TRY_AGAIN_LATER;
}
Expand Down Expand Up @@ -456,7 +455,7 @@ private function forgotPassword($userData)
* @param array $data
* @param Email $email
*
* @throws \PHPMailer\PHPMailer\Exception
* @throws Exception
*/
private function sendWelcomeEmail(array $data, Email $email)
{
Expand Down Expand Up @@ -489,7 +488,7 @@ private function sendWelcomeEmail(array $data, Email $email)
* @param array $data
* @param Email $email
*
* @throws \PHPMailer\PHPMailer\Exception
* @throws Exception
*/
private function sendForgotPassword(array $data, Email $email)
{
Expand Down

0 comments on commit 2665d47

Please sign in to comment.