Passed
Push — master ( 247527...612e6f )
by Anthony
02:56
created

ForumFaction   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 100
Duplicated Lines 14 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 14
loc 100
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getListeForum() 0 21 3
A getForumExist() 14 14 2
B setCreerForum() 0 23 4
A setSupprimerForum() 0 6 1

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

1
<?php
2
	namespace modules\bataille\app\controller;
3
	
4
	
5
	use core\App;
6
	use core\functions\ChaineCaractere;
7
	use core\HTML\flashmessage\FlashMessage;
8
	
9
	class ForumFaction extends Faction {
10
		
11
		
12
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
13
		public function __construct() {
14
			
15
		}
16
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
17
		
18
		
19
		//-------------------------- GETTER ----------------------------------------------------------------------------//
20
		/**
21
		 * fonction qui récupère les forums de la faction
22
		 */
23
		public function getListeForum() {
24
			$dbc = App::getDb();
25
			echo $this->id_faction."dg";
26
			
27
			$query = $dbc->select()->from("_bataille_faction_forum")->where("ID_faction", "=", $this->id_faction)->get();
28
			
29
			$forums = [];
30
			if ((count($query) > 0)) {
31
				foreach ($query as $obj) {
32
					$forums[] = [
33
						"id_forum" => $obj->ID_faction_forum,
34
						"titre" => $obj->titre,
35
						"url" => $obj->url,
36
						"texte" => $obj->texte,
37
						"date_creation" => $obj->date_creation
38
					];
39
				}
40
			}
41
			
42
			Bataille::setValues(["forums" => $forums]);
43
		}
44
		
45
		/**
46
		 * @param $titre
47
		 * @return bool
48
		 * fonction qui test si un forum aec ce titre existe déjà
49
		 */
50 View Code Duplication
		private function getForumExist($titre) {
1 ignored issue
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
51
			$dbc = App::getDb();
52
			
53
			$query = $dbc->select("titre")->from("_bataille_faction_forum")
54
				->where("titre", "=", $titre, "AND")
55
				->where("ID_faction", "=", $this->id_faction)
56
				->get();
57
			
58
			if (count($query) > 0) {
59
				return true;
60
			}
61
			
62
			return false;
63
		}
64
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
65
		
66
		
67
		//-------------------------- SETTER ----------------------------------------------------------------------------//
68
		/**
69
		 * @param $titre
70
		 * @param $texte
71
		 * @return bool
72
		 */
73
		public function setCreerForum($titre, $texte) {
74
			$dbc = App::getDb();
75
			
76
			if ((strlen($titre) < 3) || (strlen($texte) < 3)) {
77
				FlashMessage::setFlash("Le tittre et le texte de votre forum doivent faire plus de 2 caractères");
78
				return false;
79
			}
80
			
81
			if ($this->getForumExist($titre) === true) {
82
				FlashMessage::setFlash("Un forum portant ce nom existe déjà, merci d'en choisir un autre");
83
				return false;
84
			}
85
			
86
			$dbc->insert("titre", $titre)
87
				->insert("url", ChaineCaractere::setUrl($titre))
88
				->insert("texte", $texte)
89
				->insert("date_creation", date("Y-m-d H:i:s"))
90
				->insert("ID_faction", $this->id_faction)
91
				->into("_bataille_faction_forum")
92
				->set();
93
			
94
			return true;
95
		}
96
		
97
		/**
98
		 * @param $url
99
		 * fonction qui supprime un forum
100
		 */
101
		public function setSupprimerForum($id_forum) {
102
			$dbc = App::getDb();
103
			
104
			$dbc->delete()->from("_bataille_faction_forum")->where("ID_faction_forum", "=", $id_forum, "AND")->where("ID_faction", "=", $this->id_faction)->del();
105
			$dbc->delete()->from("_bataille_faction_forum_commentaire")->where("ID_faction_forum", "=", $id_forum)->del();
106
		}
107
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
108
	}