From 6ef521d1c39facfba3ac073e448eb9b5c612bf48 Mon Sep 17 00:00:00 2001 From: Alexis Date: Tue, 7 Feb 2023 15:14:53 +0100 Subject: [PATCH] SonarQube code smells resolve #38 --- Source/Controller/ControllerCandidate.php | 2 +- Source/Controller/FrontController.php | 20 ++++++-------------- Source/Model/Factory.php | 8 ++++---- Source/Model/FactoryQuestion.php | 16 ++++------------ Source/Model/ModelAdmin.php | 16 +++++----------- Source/Model/ModelCandidate.php | 20 ++++++-------------- 6 files changed, 26 insertions(+), 56 deletions(-) diff --git a/Source/Controller/ControllerCandidate.php b/Source/Controller/ControllerCandidate.php index 00035bb..016a017 100644 --- a/Source/Controller/ControllerCandidate.php +++ b/Source/Controller/ControllerCandidate.php @@ -18,4 +18,4 @@ class ControllerCandidate { (new ModelCandidate())->submitForm(); } -} \ No newline at end of file +} diff --git a/Source/Controller/FrontController.php b/Source/Controller/FrontController.php index f3dea21..b85279c 100644 --- a/Source/Controller/FrontController.php +++ b/Source/Controller/FrontController.php @@ -9,27 +9,19 @@ class FrontController { public function __construct() { - /* La liste de tous les Controller */ $listControllers = array("\\Controller\\ControllerCandidate", "\\Controller\\ControllerAdmin"); - global $rep, $views; // Chemin d'accès + Vues - $dVueError = array(); // Vue d'erreur + global $rep, $views; + $dVueError = array(); - try - { - /* Si l'action est NULL on appelle goToTestimony(), sinon on nettoie l'action */ + try { $action = $_REQUEST['action'] ? $action = $_REQUEST['action'] : (new ControllerCandidate())->goToForm(); - - foreach ($listControllers as $controller) // Pour chaque Controller - { - /* On regarde s'il implémente une fonction du même nom que l'action reçue */ - if(method_exists($controller, $action)) - { + foreach ($listControllers as $controller) { + if (method_exists($controller, $action)) { (new $controller)->$action(); // Si oui, on appelle cette fonction } } - } catch (PDOException|Exception $e) - { + } catch (PDOException|Exception $e) { $dVueError[] = "Erreur innatendue !"; // Ecriture du message d'erreur echo "ERREUUUUUR"; } diff --git a/Source/Model/Factory.php b/Source/Model/Factory.php index 1b38731..738afae 100644 --- a/Source/Model/Factory.php +++ b/Source/Model/Factory.php @@ -6,11 +6,11 @@ use BusinessClass\Question; abstract class Factory { - public abstract function create(array $results): array; + abstract public function create(array $results): array; - public static function getBuiltObjects(array $results, string $type): array + static public function getBuiltObjects(array $results, string $type): array { - $type = "\\Model\\Factory".$type; + $type = "\\Model\\Factory" . $type; return (new $type())->create($results); } -} \ No newline at end of file +} diff --git a/Source/Model/FactoryQuestion.php b/Source/Model/FactoryQuestion.php index 1e54e4b..f91326f 100644 --- a/Source/Model/FactoryQuestion.php +++ b/Source/Model/FactoryQuestion.php @@ -10,23 +10,15 @@ class FactoryQuestion extends Factory public function create(array $results): array { $questions = []; - if($results[0] != null) - { - for($i = 0; $i < count($results[0]); $i++) - { - if(strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0) - { + if ($results[0] != null) { + for ($i = 0; $i < count($results[0]); $i++) { + if (strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0) { $questions[] = new TextQuestion($results[0][$i]['content'], $results[0][$i]['id']); - } - else - { + } else { $possiblesResponses = $results[1][$i]; $content = $results[0][$i]['content']; - $categories = $results[2][$i]; - $id = $results[0][$i]['id']; - $questions[] = new $results[0][$i]['type']($possiblesResponses, $content, $categories, $id); } } diff --git a/Source/Model/ModelAdmin.php b/Source/Model/ModelAdmin.php index 4c2934e..440ea97 100644 --- a/Source/Model/ModelAdmin.php +++ b/Source/Model/ModelAdmin.php @@ -22,34 +22,28 @@ class ModelAdmin $categories = explode(";", $categories); $tmp = []; - foreach($categories as $category) - { + foreach ($categories as $category) { $tmp[] = explode(",", $category); } $categories = $tmp; array_pop($categories); - if(strcmp($type,"BusinessClass\TextQuestion") == 0) - { + if (strcmp($type,"BusinessClass\TextQuestion") == 0) { $question = new $type($questionContent, 0); - } - else - { + } else { $question = new $type($responses, $questionContent, $categories, 0); } $form = (new GatewayForm())->getForm(); - if(!empty($form)) - { + if (!empty($form)) { (new GatewayQuestion())->insertQuestion($question, $form[0]['id']); } } public function createForm(): void { - if(empty((new GatewayForm())->getForm())) - { + if (empty((new GatewayForm())->getForm())) { $form = new Form(0, "Votre avis nous intéresse !!!", "Description de notrer formulaire", array()); (new GatewayForm())->insertForm($form); } diff --git a/Source/Model/ModelCandidate.php b/Source/Model/ModelCandidate.php index d4de148..1f8ab2c 100644 --- a/Source/Model/ModelCandidate.php +++ b/Source/Model/ModelCandidate.php @@ -15,13 +15,10 @@ class ModelCandidate $id = []; $answer = []; $category = []; - - foreach ($answersAndCategories as $answerAndCategory) - { + foreach ($answersAndCategories as $answerAndCategory) { $idAndAnswer = explode("||", $answerAndCategory)[0]; $id[] = explode("#", $idAndAnswer)[0]; $answer[] = explode("#", $idAndAnswer)[1]; - $categs = explode("||", $answerAndCategory)[1]; $categs = explode("_", $categs); array_pop($categs); @@ -35,8 +32,7 @@ class ModelCandidate public function getForm(): string { $form = (new GatewayForm())->getForm(); - if(empty($form)) - { + if (empty($form)) { return "PAS DE FORMULAIRE\n"; } @@ -52,24 +48,20 @@ class ModelCandidate
\n
\n"; - foreach ($questions as $question) - { + foreach ($questions as $question) { $html.= $question->printStrategy()."\n"; } - if(count($questions) > 0) - { + if (count($questions) > 0) { $html.= "\t\t\t\n \t\t\t \t\t
\n \t
\n"; - } - else - { + } else { $html.= "\t\t\n \t\n"; } return $html; } -} \ No newline at end of file +}