Code smells and bugs resolve 10
continuous-integration/drone/push Build is passing Details

master
Alexis 2 years ago
parent 071b3f4fd4
commit 966e961c1b

@ -20,7 +20,8 @@ class ModelCandidate
private Client $client; private Client $client;
public function __construct(){ public function __construct()
{
$this->client = new Client(['headers' => ['Content-Type' => 'application/json'], 'verify' => false]); $this->client = new Client(['headers' => ['Content-Type' => 'application/json'], 'verify' => false]);
} }
@ -43,8 +44,8 @@ class ModelCandidate
$category = []; $category = [];
$questionsId = []; $questionsId = [];
foreach ($answersAndCategories as $answerAndCategory) { foreach ($answersAndCategories as $answerAndCategory) {
$exploded = explode("||",$answerAndCategory); $exploded = explode("||", $answerAndCategory);
if( count($exploded) == 3 ){ if (count($exploded) == 3) {
$questionsId[] = Clean::int($exploded[0]); $questionsId[] = Clean::int($exploded[0]);
$answer[] = Clean::simpleString($exploded[1]); $answer[] = Clean::simpleString($exploded[1]);
$categs = Clean::simpleString($exploded[2]); $categs = Clean::simpleString($exploded[2]);
@ -60,7 +61,7 @@ class ModelCandidate
} }
try { try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm'); $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'); throw new Exception('GetForm failed');
} }
$form = json_decode($res->getBody()); $form = json_decode($res->getBody());
@ -72,12 +73,12 @@ class ModelCandidate
'category='.$cate.'&'. 'category='.$cate.'&'.
'titleForm='.$title 'titleForm='.$title
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('InsertListResponsesOfCandidate failed'); throw new Exception('InsertListResponsesOfCandidate failed');
} }
}catch (GuzzleException | ClientException $g){ } catch (GuzzleException | ClientException $g) {
echo "Error : ".$g->getMessage(); echo "Error : " . $g->getMessage();
throw new Exception($g->getMessage(),$g->getCode(),$g); throw new Exception($g->getMessage(), $g->getCode(), $g);
} }
} }
@ -94,7 +95,7 @@ class ModelCandidate
{ {
try { try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getForm'); $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'); throw new Exception('GetForm failed');
} }
$form = json_decode($res->getBody()); $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?'. $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllQuestions?'.
'idForm='.$form[0]->id 'idForm='.$form[0]->id
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('GetAllQuestion failed'); throw new Exception('GetAllQuestion failed');
} }
$questionsTab = json_decode($res->getBody()); $questionsTab = json_decode($res->getBody());
}catch (GuzzleException | ClientException $g){ } catch (GuzzleException | ClientException $g){
echo "Error : ".$g->getMessage(); echo "Error : " . $g->getMessage();
throw new Exception($g->getMessage(),$g->getCode(),$g); throw new Exception($g->getMessage(), $g->getCode(), $g);
} }
$questions = Factory::getBuiltObjects($questionsTab, "Question"); $questions = Factory::getBuiltObjects($questionsTab, "Question");
$nbQuestions = count($questions); $nbQuestions = count($questions);
$time = round(($nbQuestions * 20)/60); $time = round(($nbQuestions * 20) / 60);
$html = "<div class='container mt-5'> $html = "<div class='container mt-5'>
<div class='row d-flex justify-content-center align-items-center'> <div class='row d-flex justify-content-center align-items-center'>
@ -132,11 +133,11 @@ class ModelCandidate
$html.= "</div>"; $html.= "</div>";
foreach ($questions as $question) { foreach ($questions as $question) {
$html.= $question->printStrategy()."\n"; $html .= $question->printStrategy() . "\n";
} }
if (count($questions) > 0) { if (count($questions) > 0) {
$html.= "<div class='thanks-message text-center' id='text-message'> <img src='https://i.imgur.com/O18mJ1K.png' alt='text-message' width='100' class='mb-4' > $html .= "<div class='thanks-message text-center' id='text-message'> <img src='https://i.imgur.com/O18mJ1K.png' alt='text-message' width='100' class='mb-4' >
<h3>Souhaitez-vous envoyer vos réponses ?</span> <h3>Souhaitez-vous envoyer vos réponses ?</span>
<input type='hidden' name='data_ids' value=''> <input type='hidden' name='data_ids' value=''>
<input type='submit' value='Envoyer' id='button'>\n <input type='submit' value='Envoyer' id='button'>\n
@ -152,7 +153,7 @@ class ModelCandidate
</div> </div>
</div>"; </div>";
} else { } else {
$html.= "\t\t</form>\n $html .= "\t\t</form>\n
\t</div>\n"; \t</div>\n";
} }
@ -165,7 +166,7 @@ class ModelCandidate
* @throws Exception * @throws Exception
*/ */
public function login() :void { public function login() :void {
global $rep,$views,$sel; global $rep, $views, $sel;
$password = Clean::simpleString($_REQUEST['password']); $password = Clean::simpleString($_REQUEST['password']);
$identifiant = Clean::simpleString($_REQUEST['login']); $identifiant = Clean::simpleString($_REQUEST['login']);
try { try {
@ -173,7 +174,7 @@ class ModelCandidate
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getPasswordWithLogin?'. $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getPasswordWithLogin?'.
'login='.$identifiant 'login='.$identifiant
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('GetPasswordWithLogin failed'); throw new Exception('GetPasswordWithLogin failed');
} }
$passwordbdd = json_decode($res->getBody()); $passwordbdd = json_decode($res->getBody());
@ -188,9 +189,9 @@ class ModelCandidate
} else { } else {
throw new InvalidLoginOrPasswordException(); throw new InvalidLoginOrPasswordException();
} }
}catch (GuzzleException | ClientException $g){ } catch (GuzzleException | ClientException $g) {
echo "Error : ".$g->getMessage(); echo "Error : " . $g->getMessage();
throw new Exception($g->getMessage(),$g->getCode(),$g); throw new Exception($g->getMessage(), $g->getCode(), $g);
} }
} }
} }

Loading…
Cancel
Save