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

master
Alexis 2 years ago
parent 321c3b9ee9
commit 071b3f4fd4

@ -19,14 +19,15 @@ class ModelAdmin
{ {
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]);
} }
public function goToAdmin(): void public function goToAdmin(): void
{ {
global $rep, $views; global $rep, $views;
try{ try {
require_once($rep . $views['admin']); require_once($rep . $views['admin']);
} catch (PDOException $e) { } catch (PDOException $e) {
$error = $e->getMessage(); $error = $e->getMessage();
@ -61,7 +62,7 @@ class ModelAdmin
'classQuestion='.get_class($question).'&'. 'classQuestion='.get_class($question).'&'.
'idForm='.$form[0]['id'] 'idForm='.$form[0]['id']
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('AddQuestion failed'); throw new Exception('AddQuestion failed');
} }
return json_decode($res->getBody()); return json_decode($res->getBody());
@ -69,9 +70,9 @@ class ModelAdmin
} else { } else {
throw new Exception('Type de question invalide'); throw new Exception('Type de question invalide');
} }
}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);
} }
return -1; return -1;
} }
@ -94,12 +95,12 @@ class ModelAdmin
'classQuestion='.$type.'&'. 'classQuestion='.$type.'&'.
'id='.$idQuestion 'id='.$idQuestion
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('DeleteQuestion failed'); throw new Exception('DeleteQuestion 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);
} }
} }
@ -118,7 +119,7 @@ class ModelAdmin
$categories = []; $categories = [];
} }
try { try {
if(!validate::categories($categories)){ if (!validate::categories($categories)) {
throw new Exception('Categories invalides'); throw new Exception('Categories invalides');
} }
$res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertResponseInQuestion?'. $res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertResponseInQuestion?'.
@ -126,12 +127,12 @@ class ModelAdmin
'categories='.json_encode($categories).'&'. 'categories='.json_encode($categories).'&'.
'idQuestion='.$idQuestion 'idQuestion='.$idQuestion
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('InsertResponseInQuestion failed'); throw new Exception('InsertResponseInQuestion 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);
} }
} }
@ -147,12 +148,12 @@ class ModelAdmin
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deletePossibleResponse?'. $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deletePossibleResponse?'.
'id='.$_POST["possibleResponse"] 'id='.$_POST["possibleResponse"]
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('DeletePossibleResponse failed'); throw new Exception('DeletePossibleResponse failed');
} }
}catch (GuzzleException $g){ } catch (GuzzleException $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);
} }
} }
@ -176,13 +177,13 @@ class ModelAdmin
'title='.$form->getTitle().'&'. 'title='.$form->getTitle().'&'.
'description='.$form->getDescription() 'description='.$form->getDescription()
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('InsertForm failed'); throw new Exception('InsertForm failed');
} }
} }
}catch (GuzzleException $g){ } catch (GuzzleException $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);
} }
} }
@ -197,18 +198,18 @@ class ModelAdmin
{ {
$keyword = Clean::simpleString($_POST['keyword']); $keyword = Clean::simpleString($_POST['keyword']);
try { try {
if(!validate::keyword($keyword)){ if (!validate::keyword($keyword)) {
throw new Exception('Mot-clef invalide'); throw new Exception('Mot-clef invalide');
} }
$res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertKeyword?'. $res = $this->client->request('POST', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/insertKeyword?'.
'keyword='.$keyword 'keyword='.$keyword
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('InsertKeyword failed'); throw new Exception('InsertKeyword 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);
} }
} }
@ -224,12 +225,12 @@ class ModelAdmin
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteKeyword?'. $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteKeyword?'.
'keyword='.$_POST["idCateg"] 'keyword='.$_POST["idCateg"]
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('DeleteKeyword failed'); throw new Exception('DeleteKeyword 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);
} }
} }
@ -244,16 +245,16 @@ class ModelAdmin
$categories = []; $categories = [];
try { try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllKeyword'); $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllKeyword');
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('GetAllKeyword failed'); throw new Exception('GetAllKeyword failed');
} }
$res = json_decode($res->getBody()); $res = json_decode($res->getBody());
foreach ($res as $category) { foreach ($res as $category) {
$categories[] = $category["word"]; $categories[] = $category["word"];
} }
}catch (GuzzleException $g){ } catch (GuzzleException $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);
} }
return $categories; return $categories;
@ -270,28 +271,28 @@ class ModelAdmin
{ {
try { try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/existsForm'); $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/existsForm');
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('Exists failed'); throw new Exception('Exists failed');
} }
if (json_decode($res->getBody())){ if (json_decode($res->getBody())) {
$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');
} }
$idForm = json_decode($res->getBody())[0]->id; $idForm = json_decode($res->getBody())[0]->id;
$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='.$idForm); 'idForm='.$idForm);
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('GetAllQuestions failed'); throw new Exception('GetAllQuestions failed');
} }
$questionsArray = json_decode($res->getBody()); $questionsArray = json_decode($res->getBody());
return Factory::getBuiltObjects($questionsArray, "Question"); return Factory::getBuiltObjects($questionsArray, "Question");
}else{ } else {
return array(); return array();
} }
}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);
} }
} }
@ -306,7 +307,7 @@ class ModelAdmin
{ {
try { try {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllListResponseOfCandidate'); $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getAllListResponseOfCandidate');
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('GetAllListResponsesOfCandidate failed'); throw new Exception('GetAllListResponsesOfCandidate failed');
} }
$responsesCandidate = json_decode($res->getBody()); $responsesCandidate = json_decode($res->getBody());
@ -314,15 +315,15 @@ class ModelAdmin
foreach ($responsesCandidate as $response) { foreach ($responsesCandidate as $response) {
$res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getDetailsListResponseOfCandidate?'. $res = $this->client->request('GET', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/getDetailsListResponseOfCandidate?'.
'id='.$response->id); 'id='.$response->id);
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('GetDetailsListResponsesOfCandidate failed'); throw new Exception('GetDetailsListResponsesOfCandidate failed');
} }
$results[] =json_decode($res->getBody()); $results[] =json_decode($res->getBody());
} }
return $results; return $results;
}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);
} }
} }
@ -338,12 +339,12 @@ class ModelAdmin
$res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteListResponseOfCandidate?'. $res = $this->client->request('DELETE', 'https://codefirst.iut.uca.fr/containers/Temoignages-deploy_api_form/deleteListResponseOfCandidate?'.
'id='.Clean::int($_POST["idResponseCandidate"]) 'id='.Clean::int($_POST["idResponseCandidate"])
); );
if ($res->getStatusCode()!=200){ if ($res->getStatusCode() != 200) {
throw new Exception('DeleteListResponseOfCandidate failed'); throw new Exception('DeleteListResponseOfCandidate 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);
} }
} }
} }

Loading…
Cancel
Save