Passed
Push — master ( 05f68d...e2f2cb )
by Anthony
02:50
created

Faction::getInfosFaction()   B

Complexity

Conditions 4
Paths 6

Size

Total Lines 28
Code Lines 20

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 28
rs 8.5806
c 1
b 0
f 0
cc 4
eloc 20
nc 6
nop 1
1
<?php
2
	namespace modules\bataille\app\controller;
3
	
4
	
5
	use core\App;
6
	
7
	class Faction {
8
		private $id_faction;
9
		
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		public function __construct() {
12
			
13
		}
14
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
15
		
16
		
17
		//-------------------------- GETTER ----------------------------------------------------------------------------//
18
		/**
19
		 * @return mixed
20
		 * fonction qui renvoi l'ID de la faction du joueur
21
		 */
22
		public function getFactionPlayer() {
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...
23
			$dbc = App::getDb();
24
			
25
			$query = $dbc->select("ID_faction")->from("_bataille_infos_player")
26
				->where("ID_identite", "=", Bataille::getIdIdentite(), "AND")
27
				->where("ID_faction", ">", 0)
28
				->get();
29
			
30
			if ((count($query) > 0)) {
31
				foreach ($query as $obj) {
32
					$this->id_faction = $obj->ID_faction;
33
					$this->getInfosFaction();
34
				}
35
			}
36
		}
37
		
38
		/**
39
		 * @param null $id_faction
40
		 * fonction qui récupère les infos de la faction
41
		 */
42
		public function getInfosFaction($id_faction = null) {
43
			$dbc = App::getDb();
44
			
45
			if ($id_faction === null) {
46
				$id_faction = $this->id_faction;
47
			}
48
			
49
			$query = $dbc->select("identite.pseudo")
50
				->select("_bataille_faction.nom_faction")
51
				->select("_bataille_faction.img_profil")
52
				->select("_bataille_faction.description")
53
				->from("_bataille_faction")
54
				->from("identite")
55
				->where("_bataille_faction.ID_faction", "=", $id_faction, "AND")
56
				->where("_bataille_faction.ID_identite", "=", "identite.ID_identite", "", true)
57
				->get();
58
			
59
			if ((count($query) == 1)) {
60
				foreach ($query as $obj) {
61
					Bataille::setValues(["faction" => [
62
						"nom" => $obj->nom_faction,
63
						"description" => $obj->description,
64
						"url_img" => $obj->img_profil,
65
						"pseudo_chef" => $obj->pseudo
66
					]]);
67
				}
68
			}
69
		}
70
		
71
		/**
72
		 * fonction qui récupère les membres d'un faction
73
		 */
74
		public function getMembreFaction() {
75
			$dbc = App::getDb();
76
			
77
			$query = $dbc->select()
78
				->from("_bataille_infos_player")
79
				->from("identite")
80
				->where("_bataille_infos_player.ID_faction", "=", $this->id_faction)
81
				->where("_bataille_infos_player.ID_identite", "=", "identite.ID_identite", "", true)
82
				->get();
83
			
84
			$membre = [];
85
			foreach ($query as $obj) {
86
				$memebre[] = [
0 ignored issues
show
Coding Style Comprehensibility introduced by
$memebre was never initialized. Although not strictly required by PHP, it is generally a good practice to add $memebre = array(); before regardless.

Adding an explicit array definition is generally preferable to implicit array definition as it guarantees a stable state of the code.

Let’s take a look at an example:

foreach ($collection as $item) {
    $myArray['foo'] = $item->getFoo();

    if ($item->hasBar()) {
        $myArray['bar'] = $item->getBar();
    }

    // do something with $myArray
}

As you can see in this example, the array $myArray is initialized the first time when the foreach loop is entered. You can also see that the value of the bar key is only written conditionally; thus, its value might result from a previous iteration.

This might or might not be intended. To make your intention clear, your code more readible and to avoid accidental bugs, we recommend to add an explicit initialization $myArray = array() either outside or inside the foreach loop.

Loading history...
87
					"pseudo" => $obj->pseudo,
88
					"points" => $obj->points
89
				];
90
			}
91
			
92
			Bataille::setValues(["faction" => $membre]);
93
		}
94
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
95
		
96
		
97
		//-------------------------- SETTER ----------------------------------------------------------------------------//
98
		//-------------------------- END SETTER ----------------------------------------------------------------------------//    
99
	}