Aide   A
last analyzed

Complexity

Total Complexity 14

Size/Duplication

Total Lines 119
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getTable() 0 5 2
B __construct() 0 56 8
B getPourConstruire() 0 26 4
1
<?php
2
	namespace modules\bataille\app\controller;
3
	
4
	
5
	class Aide {
6
		public static $parametre_router;
7
8
9
10
		//-------------------------- BUILDER ----------------------------------------------------------------------------//
11
		/**
12
		 * recupere la liste des batiments constructibles dans la catégorie spécifiée
13
		 */
14
		public function __construct() {
15
			$dbc1 = Bataille::getDb();
16
17
			$parametre = explode("-", self::$parametre_router);
18
			Bataille::setValues(["batiments" => $parametre[0], "type_batiments" => $parametre[1]]);
19
20
			//recuperation de tous les batiments du type
21
			$query = $dbc1->select()->from($this->getTable($parametre[0]))->where("actif", "=", 1, "AND")->where("type", "=", $parametre[1])->get();
22
23
			if ((is_array($query)) && (count($query) > 0)) {
24
				$batiments = [];
25
				
26
				foreach ($query as $obj) {
27
					$nom_batiment = $obj->nom;
28
					$nom_batiment_sql = $obj->nom_table;
29
30
					//on recupere les infos concernant le temps de construction et les batiment qu'il faudra pour construire
31
					$query = $dbc1->select()->from($obj->nom_table)->where("ID_".$obj->nom_table, "=", 1)->get();
32
33
					if ((is_array($query)) && (count($query) == 1)) {
34
						$pour_construire = [];
35
						
36
						foreach ($query as $obj) {
37
							$ressource_tmp = explode(", ", $obj->ressource_construire);
38
39
							$ressource = [
40
								"fer" => $ressource_tmp[0],
41
								"fuel" => $ressource_tmp[1],
42
								"eau" => $ressource_tmp[2],
43
								"electricite" => $ressource_tmp[3]
44
							];
45
46
							if ($obj->pour_construire != null) {
47
								$pour_construire[] = unserialize($obj->pour_construire);
48
49
								$pour_construire = $this->getPourConstruire($pour_construire);
50
							}
51
							else {
52
								$pour_construire = [];
53
							}
54
55
							$batiments[] = [
56
								"nom_batiment" => $nom_batiment,
57
								"nom_batiment_sql" => $nom_batiment_sql,
58
								"niveau_batiment" => 1,
59
								"temps_construction" => gmdate("H:i:s", $obj->temps_construction),
60
								"ressource" => $ressource,
61
								"pour_construire" => $pour_construire
62
							];
63
						}
64
					}
65
				}
66
67
				Bataille::setValues(["liste_batiments" => $batiments]);
68
			}
69
		}
70
		//-------------------------- END BUILDER ----------------------------------------------------------------------------//
71
72
73
74
		//-------------------------- GETTER ----------------------------------------------------------------------------//
75
		/**
76
		 * renvoi la table dans laquelle il faut aller chercher les infos
77
		 * @param $param
78
		 * @return string
79
		 */
80
		private function getTable($param) {
81
			if ($param == "batiment") {
82
				return  "liste_batiment";
83
			}
84
		}
85
86
		/**
87
		 * @param $pour_construire
88
		 * @return array
89
		 * renvoi le ou les batiments nécéssaires pour la construction du batiment spécifié
90
		 */
91
		private function getPourConstruire($pour_construire) {
92
			$count = count($pour_construire);
93
			$batiment = [];
94
			for ($i = 0 ; $i < $count ; $i++) {
0 ignored issues
show
Unused Code introduced by
$i++; does not seem to be reachable.

This check looks for unreachable code. It uses sophisticated control flow analysis techniques to find statements which will never be executed.

Unreachable code is most often the result of return, die or exit statements that have been added for debug purposes.

function fx() {
    try {
        doSomething();
        return true;
    }
    catch (\Exception $e) {
        return false;
    }

    return false;
}

In the above example, the last return false will never be executed, because a return statement has already been met in every possible execution path.

Loading history...
95
				//si plusieur batiment pour construire le batiment en question
96
				$count = count($pour_construire[$i]);
97
				if ($count > 1) {
98
					for ($j = 0 ; $j < $count ; $j++) {
99
						$batiment[] =  [
100
							"nom_batiment" => $pour_construire[$i][$j][0],
101
							"niveau_batiment" => $pour_construire[$i][$j][2]
102
						];
103
					}
104
105
					return ["batiments" => $batiment];
106
				}
107
				else {
108
					$batiment[] =  [
109
						"nom_batiment" => $pour_construire[$i][0][0],
110
						"niveau_batiment" => $pour_construire[$i][0][2]
111
					];
112
113
					return ["batiments" => $batiment];
114
				}
115
			}
116
		}
117
		//-------------------------- END GETTER ----------------------------------------------------------------------------//
118
119
120
121
		//-------------------------- SETTER ----------------------------------------------------------------------------//
122
		//-------------------------- END SETTER ----------------------------------------------------------------------------//
123
	}