From 966e961c1bbd66ec06e2c455e80a967b3c252608 Mon Sep 17 00:00:00 2001 From: Alexis Date: Sun, 2 Apr 2023 13:33:24 +0200 Subject: [PATCH] Code smells and bugs resolve 10 --- Source/Model/ModelCandidate.php | 45 +++++++++++++++++---------------- 1 file changed, 23 insertions(+), 22 deletions(-) diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index 44eb14f..f84d67d 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -20,7 +20,8 @@ class ModelCandidate private Client $client; - public function __construct(){ + public function __construct() + { $this->client = new Client(['headers' => ['Content-Type' => 'application/json'], 'verify' => false]); } @@ -43,8 +44,8 @@ class ModelCandidate $category = []; $questionsId = []; foreach ($answersAndCategories as $answerAndCategory) { - $exploded = explode("||",$answerAndCategory); - if( count($exploded) == 3 ){ + $exploded = explode("||", $answerAndCategory); + if (count($exploded) == 3) { $questionsId[] = Clean::int($exploded[0]); $answer[] = Clean::simpleString($exploded[1]); $categs = Clean::simpleString($exploded[2]); @@ -60,7 +61,7 @@ class ModelCandidate } try { $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm'); - if ($res->getStatusCode()!=200){ + if ($res->getStatusCode() != 200) { throw new Exception('GetForm failed'); } $form = json_decode($res->getBody()); @@ -72,12 +73,12 @@ class ModelCandidate 'category='.$cate.'&'. 'titleForm='.$title ); - if ($res->getStatusCode()!=200){ + if ($res->getStatusCode() != 200) { throw new Exception('InsertListResponsesOfCandidate failed'); } - }catch (GuzzleException | ClientException $g){ - echo "Error : ".$g->getMessage(); - throw new Exception($g->getMessage(),$g->getCode(),$g); + } catch (GuzzleException | ClientException $g) { + echo "Error : " . $g->getMessage(); + throw new Exception($g->getMessage(), $g->getCode(), $g); } } @@ -94,7 +95,7 @@ class ModelCandidate { try { $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm'); - if ($res->getStatusCode()!=200){ + if ($res->getStatusCode() != 200) { throw new Exception('GetForm failed'); } $form = json_decode($res->getBody()); @@ -107,19 +108,19 @@ class ModelCandidate $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllQuestions?'. 'idForm='.$form[0]->id ); - if ($res->getStatusCode()!=200){ + if ($res->getStatusCode() != 200) { throw new Exception('GetAllQuestion failed'); } $questionsTab = json_decode($res->getBody()); - }catch (GuzzleException | ClientException $g){ - echo "Error : ".$g->getMessage(); - throw new Exception($g->getMessage(),$g->getCode(),$g); + } catch (GuzzleException | ClientException $g){ + echo "Error : " . $g->getMessage(); + throw new Exception($g->getMessage(), $g->getCode(), $g); } $questions = Factory::getBuiltObjects($questionsTab, "Question"); $nbQuestions = count($questions); - $time = round(($nbQuestions * 20)/60); + $time = round(($nbQuestions * 20) / 60); $html = "
@@ -132,11 +133,11 @@ class ModelCandidate $html.= "
"; foreach ($questions as $question) { - $html.= $question->printStrategy()."\n"; + $html .= $question->printStrategy() . "\n"; } if (count($questions) > 0) { - $html.= "
text-message + $html .= "
text-message

Souhaitez-vous envoyer vos réponses ? \n @@ -152,7 +153,7 @@ class ModelCandidate

"; } else { - $html.= "\t\t\n + $html .= "\t\t\n \t
\n"; } @@ -165,7 +166,7 @@ class ModelCandidate * @throws Exception */ public function login() :void { - global $rep,$views,$sel; + global $rep, $views, $sel; $password = Clean::simpleString($_REQUEST['password']); $identifiant = Clean::simpleString($_REQUEST['login']); try { @@ -173,7 +174,7 @@ class ModelCandidate $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getPasswordWithLogin?'. 'login='.$identifiant ); - if ($res->getStatusCode()!=200){ + if ($res->getStatusCode() != 200) { throw new Exception('GetPasswordWithLogin failed'); } $passwordbdd = json_decode($res->getBody()); @@ -188,9 +189,9 @@ class ModelCandidate } else { throw new InvalidLoginOrPasswordException(); } - }catch (GuzzleException | ClientException $g){ - echo "Error : ".$g->getMessage(); - throw new Exception($g->getMessage(),$g->getCode(),$g); + } catch (GuzzleException | ClientException $g) { + echo "Error : " . $g->getMessage(); + throw new Exception($g->getMessage(), $g->getCode(), $g); } } }