Conditions | 13 |
Paths | 101 |
Total Lines | 101 |
Code Lines | 77 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php |
||
21 | public function __construct($id_base = null, $install_base = null) { |
||
22 | $dbc = App::getDb(); |
||
23 | $temps_trajet = ""; |
||
24 | $map = []; |
||
25 | |||
26 | if ($install_base != null) { |
||
27 | return true; |
||
|
|||
28 | } |
||
29 | |||
30 | if ($id_base == null) { |
||
31 | $this->getParametres(); |
||
32 | |||
33 | $query = $dbc->select("_bataille_base.nom_base") |
||
34 | ->select("_bataille_base.points") |
||
35 | ->select("_bataille_base.posx") |
||
36 | ->select("_bataille_base.posy") |
||
37 | ->select("_bataille_base.ID_base") |
||
38 | ->select("identite.pseudo") |
||
39 | ->select("identite.ID_identite") |
||
40 | ->from("identite") |
||
41 | ->from("_bataille_base") |
||
42 | ->where("_bataille_base.ID_identite", "=", "identite.ID_identite", "", true) |
||
43 | ->get(); |
||
44 | } |
||
45 | else { |
||
46 | $query = $dbc->select("_bataille_base.nom_base") |
||
47 | ->select("_bataille_base.points") |
||
48 | ->select("_bataille_base.posx") |
||
49 | ->select("_bataille_base.posy") |
||
50 | ->select("_bataille_base.ID_base") |
||
51 | ->select("identite.ID_identite") |
||
52 | ->select("identite.pseudo") |
||
53 | ->from("identite") |
||
54 | ->from("_bataille_base") |
||
55 | ->where("_bataille_base.ID_base", "=", $id_base, "AND") |
||
56 | ->where("_bataille_base.ID_identite", "=", "identite.ID_identite", "", true) |
||
57 | ->get(); |
||
58 | |||
59 | $temps_trajet = DateHeure::Secondeenheure(Bataille::getDureeTrajet($id_base)); |
||
60 | } |
||
61 | |||
62 | if ((is_array($query)) && (count($query) > 0)) { |
||
63 | $faction = Bataille::getRelationFaction(); |
||
64 | $faction->getFactionPlayer(); |
||
65 | $id_faction = $faction->getIdFaction(); |
||
66 | $faction_allie = $faction->getIdFactionRelation("allié"); |
||
67 | $faction_non_agression = $faction->getIdFactionRelation("pacte non agression"); |
||
68 | $faction_ennemies = $faction->getIdFactionRelation("ennemi"); |
||
69 | |||
70 | foreach ($query as $obj) { |
||
71 | $ma_base = ""; |
||
72 | $mes_bases = ""; |
||
73 | $ma_faction = ""; |
||
74 | $allie = ""; |
||
75 | $pacte_non_agression = ""; |
||
76 | $ennemi = ""; |
||
77 | |||
78 | if ($obj->ID_base == Bataille::getIdBase()) { |
||
79 | $ma_base = "ma-base"; |
||
80 | } |
||
81 | else if ($obj->ID_identite == Bataille::getIdIdentite()) { |
||
82 | $mes_bases = "mes-bases"; |
||
83 | } |
||
84 | |||
85 | $faction->getFactionPlayer($obj->ID_identite); |
||
86 | if (($id_faction == $faction->getIdFaction()) && ($obj->ID_identite != Bataille::getIdIdentite())) { |
||
87 | $ma_faction = "ma-faction"; |
||
88 | } |
||
89 | |||
90 | if (in_array($faction->getIdFaction(), $faction_allie)) { |
||
91 | $allie = "faction-allie"; |
||
92 | } |
||
93 | if (in_array($faction->getIdFaction(), $faction_non_agression)) { |
||
94 | $pacte_non_agression = "faction-non-agression"; |
||
95 | } |
||
96 | if (in_array($faction->getIdFaction(), $faction_ennemies)) { |
||
97 | $ennemi = "faction-ennemi"; |
||
98 | } |
||
99 | |||
100 | $map[] = [ |
||
101 | "nom_base" => $obj->nom_base, |
||
102 | "points" => $obj->points, |
||
103 | "posx" => $obj->posx, |
||
104 | "posy" => $obj->posy, |
||
105 | "id_base" => $obj->ID_base, |
||
106 | "id_identite" => $obj->ID_identite, |
||
107 | "pseudo" => $obj->pseudo, |
||
108 | "ma_base" => $ma_base, |
||
109 | "mes_bases" => $mes_bases, |
||
110 | "ma_faction" => $ma_faction, |
||
111 | "faction_allie" => $allie, |
||
112 | "faction_pacte_non_agression" => $pacte_non_agression, |
||
113 | "faction_ennemies" => $ennemi, |
||
114 | "temps_trajet" => $temps_trajet, |
||
115 | "mode_vacances" => Profil::getTestVacancesBase($obj->ID_base) |
||
116 | ]; |
||
117 | } |
||
118 | |||
119 | Bataille::setValues(["map" => $map]); |
||
120 | } |
||
121 | } |
||
122 | //-------------------------- END BUILDER ----------------------------------------------------------------------------// |
||
194 | } |