SonarQube code smells resolve #38
continuous-integration/drone/push Build is passing Details

LoginModification
Alexis 2 years ago
parent 087b91917b
commit 6ef521d1c3

@ -18,4 +18,4 @@ class ControllerCandidate
{ {
(new ModelCandidate())->submitForm(); (new ModelCandidate())->submitForm();
} }
} }

@ -9,27 +9,19 @@ class FrontController
{ {
public function __construct() public function __construct()
{ {
/* La liste de tous les Controller */
$listControllers = array("\\Controller\\ControllerCandidate", "\\Controller\\ControllerAdmin"); $listControllers = array("\\Controller\\ControllerCandidate", "\\Controller\\ControllerAdmin");
global $rep, $views; // Chemin d'accès + Vues global $rep, $views;
$dVueError = array(); // Vue d'erreur $dVueError = array();
try try {
{
/* Si l'action est NULL on appelle goToTestimony(), sinon on nettoie l'action */
$action = $_REQUEST['action'] ? $action = $_REQUEST['action'] : (new ControllerCandidate())->goToForm(); $action = $_REQUEST['action'] ? $action = $_REQUEST['action'] : (new ControllerCandidate())->goToForm();
foreach ($listControllers as $controller) {
foreach ($listControllers as $controller) // Pour chaque Controller if (method_exists($controller, $action)) {
{
/* On regarde s'il implémente une fonction du même nom que l'action reçue */
if(method_exists($controller, $action))
{
(new $controller)->$action(); // Si oui, on appelle cette fonction (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 $dVueError[] = "Erreur innatendue !"; // Ecriture du message d'erreur
echo "ERREUUUUUR"; echo "ERREUUUUUR";
} }

@ -6,11 +6,11 @@ use BusinessClass\Question;
abstract class Factory 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); return (new $type())->create($results);
} }
} }

@ -10,23 +10,15 @@ class FactoryQuestion extends Factory
public function create(array $results): array public function create(array $results): array
{ {
$questions = []; $questions = [];
if($results[0] != null) if ($results[0] != null) {
{ for ($i = 0; $i < count($results[0]); $i++) {
for($i = 0; $i < count($results[0]); $i++) if (strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0) {
{
if(strcmp($results[0][$i]['type'], "BusinessClass\TextQuestion") == 0)
{
$questions[] = new TextQuestion($results[0][$i]['content'], $results[0][$i]['id']); $questions[] = new TextQuestion($results[0][$i]['content'], $results[0][$i]['id']);
} } else {
else
{
$possiblesResponses = $results[1][$i]; $possiblesResponses = $results[1][$i];
$content = $results[0][$i]['content']; $content = $results[0][$i]['content'];
$categories = $results[2][$i]; $categories = $results[2][$i];
$id = $results[0][$i]['id']; $id = $results[0][$i]['id'];
$questions[] = new $results[0][$i]['type']($possiblesResponses, $content, $categories, $id); $questions[] = new $results[0][$i]['type']($possiblesResponses, $content, $categories, $id);
} }
} }

@ -22,34 +22,28 @@ class ModelAdmin
$categories = explode(";", $categories); $categories = explode(";", $categories);
$tmp = []; $tmp = [];
foreach($categories as $category) foreach ($categories as $category) {
{
$tmp[] = explode(",", $category); $tmp[] = explode(",", $category);
} }
$categories = $tmp; $categories = $tmp;
array_pop($categories); array_pop($categories);
if(strcmp($type,"BusinessClass\TextQuestion") == 0) if (strcmp($type,"BusinessClass\TextQuestion") == 0) {
{
$question = new $type($questionContent, 0); $question = new $type($questionContent, 0);
} } else {
else
{
$question = new $type($responses, $questionContent, $categories, 0); $question = new $type($responses, $questionContent, $categories, 0);
} }
$form = (new GatewayForm())->getForm(); $form = (new GatewayForm())->getForm();
if(!empty($form)) if (!empty($form)) {
{
(new GatewayQuestion())->insertQuestion($question, $form[0]['id']); (new GatewayQuestion())->insertQuestion($question, $form[0]['id']);
} }
} }
public function createForm(): void 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()); $form = new Form(0, "Votre avis nous intéresse !!!", "Description de notrer formulaire", array());
(new GatewayForm())->insertForm($form); (new GatewayForm())->insertForm($form);
} }

@ -15,13 +15,10 @@ class ModelCandidate
$id = []; $id = [];
$answer = []; $answer = [];
$category = []; $category = [];
foreach ($answersAndCategories as $answerAndCategory) {
foreach ($answersAndCategories as $answerAndCategory)
{
$idAndAnswer = explode("||", $answerAndCategory)[0]; $idAndAnswer = explode("||", $answerAndCategory)[0];
$id[] = explode("#", $idAndAnswer)[0]; $id[] = explode("#", $idAndAnswer)[0];
$answer[] = explode("#", $idAndAnswer)[1]; $answer[] = explode("#", $idAndAnswer)[1];
$categs = explode("||", $answerAndCategory)[1]; $categs = explode("||", $answerAndCategory)[1];
$categs = explode("_", $categs); $categs = explode("_", $categs);
array_pop($categs); array_pop($categs);
@ -35,8 +32,7 @@ class ModelCandidate
public function getForm(): string public function getForm(): string
{ {
$form = (new GatewayForm())->getForm(); $form = (new GatewayForm())->getForm();
if(empty($form)) if (empty($form)) {
{
return "PAS DE FORMULAIRE\n"; return "PAS DE FORMULAIRE\n";
} }
@ -52,24 +48,20 @@ class ModelCandidate
<div id='container_form'>\n <div id='container_form'>\n
<form method='post'>\n"; <form method='post'>\n";
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.= "\t\t\t<input type='submit'>\n $html.= "\t\t\t<input type='submit'>\n
\t\t\t<input type='hidden' name='action' value='submitForm'> \t\t\t<input type='hidden' name='action' value='submitForm'>
\t\t</form>\n \t\t</form>\n
\t</div>\n"; \t</div>\n";
} } else {
else
{
$html.= "\t\t</form>\n $html.= "\t\t</form>\n
\t</div>\n"; \t</div>\n";
} }
return $html; return $html;
} }
} }

Loading…
Cancel
Save