Passed
Push — master ( a47f7f...7f5395 )
by Anthony
02:41
created

RelationFaction   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 74
Duplicated Lines 31.08 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 7
c 1
b 0
f 1
lcom 1
cbo 2
dl 23
loc 74
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getListeRelation() 23 23 3
A getAllRelationsPossible() 0 15 2
A setAjouterRelation() 0 13 2

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\HTML\flashmessage\FlashMessage;
7
	
8
	class RelationFaction extends Faction {
9
		//-------------------------- GETTER ----------------------------------------------------------------------------//
10
		/**
11
		 * renvoi la liste des relations d'une faction
12
		 */
13 View Code Duplication
		public function getListeRelation() {
0 ignored issues
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...
14
			$dbc = App::getDb();
15
			
16
			$query = $dbc->select()->from("_bataille_faction_relation")
17
				->from("_bataille_faction")
18
				->where("_bataille_faction_relation.ID_faction", "=", $this->id_faction, "AND")
19
				->where("_bataille_faction_relation.ID_autre_faction", "=", "_bataille_faction.ID_faction", "", true)
20
				->get();
21
			
22
			$relations = [];
23
			if (count($query) > 0) {
24
				foreach ($query as $obj) {
25
					$relations[] = [
26
						"id_relation" => $obj->ID_faction_relation,
27
						"relation" => $obj->relation,
28
						"id_autre_faction" => $obj->ID_autre_faction,
29
						"nom_autre_faction" => $obj->nom_faction
30
					];
31
				}
32
			}
33
			
34
			Bataille::setValues(["relations" => $relations]);
35
		}
36
		
37
		/**
38
		 * fonction qui récupère la liste des relations qu'il sera possible
39
		 * de mettre dans le select
40
		 */
41
		public function getAllRelationsPossible() {
42
			$dbc1 = Bataille::getDb();
43
			
44
			$query = $dbc1->select()->from("faction_relations");
45
			
46
			$relations = [];
47
			foreach ($query as $obj) {
48
				$relations[] = [
49
					"relation" => $obj->relation
50
				];
51
			}
52
			
53
			Bataille::setValues(["liste_relations" => $relations]);
54
			return $relations;
55
		}
56
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
57
		
58
		
59
		//-------------------------- SETTER ----------------------------------------------------------------------------//
60
		/**
61
		 * @param $nom_faction
62
		 * @param $relation
63
		 * @return bool
64
		 * fonction qui permet d'ajouter une relation
65
		 */
66
		public function setAjouterRelation($nom_faction, $relation) {
67
			$dbc = App::getDb();
68
			
69
			if ($this->getFactionExist($nom_faction) == false) {
0 ignored issues
show
Coding Style Best Practice introduced by
It seems like you are loosely comparing two booleans. Considering using the strict comparison === instead.

When comparing two booleans, it is generally considered safer to use the strict comparison operator.

Loading history...
70
				FlashMessage::setFlash("Cette faction n'existe pas, vérifiez que vous avez correctement écrit son nom");
71
				return false;
72
			}
73
			
74
			$dbc->insert("relation", $relation)
75
				->insert("ID_faction", $this->id_faction)
76
				->insert("ID_autre_faction", $this->id_autre_faction)
77
				->into("_bataille_faction_relation")->set();
78
		}
79
		
80
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
81
	}