Conditions | 18 |
Paths | 60 |
Total Lines | 102 |
Lines | 53 |
Ratio | 51.96 % |
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 |
||
38 | public function __invoke(BillableFlightQuery $query) |
||
39 | { |
||
40 | $sql = "SELECT USR.lastname AS nom , USR.firstname AS prenom ,COUNT(`idBBC_vols`) AS nbr,fk_pilot as pilot, TT.numero as type,SEC_TO_TIME(SUM(TIME_TO_SEC(TIMEDIFF(heureA,heureD)))) AS time"; |
||
41 | $sql .= " FROM llx_bbc_vols, llx_user AS USR,llx_bbc_types AS TT "; |
||
42 | $sql .= " WHERE `fk_pilot`= USR.rowid AND fk_type = TT.idType AND YEAR(llx_bbc_vols.date) = " . ($query->hasYear() ? "'" . $query->getFiscalYear() . "'" : 'YEAR(NOW())'); |
||
43 | $sql .= " GROUP BY fk_pilot,`fk_type`"; |
||
44 | |||
45 | $resql = $this->db->query($sql); |
||
46 | $array = array(); |
||
47 | if ($resql) { |
||
48 | $num = $this->db->num_rows($resql); |
||
49 | $i = 0; |
||
50 | if ($num) { |
||
51 | while ($i < $num) { |
||
52 | $obj = $this->db->fetch_object($resql); //vol |
||
53 | if ($obj) { |
||
54 | if (!isset($array[$obj->pilot])) { |
||
55 | $name = $obj->prenom . ' ' . $obj->nom; |
||
56 | $pilot = Pilot::create($name, $obj->pilot); |
||
57 | $array[$obj->pilot] = $pilot; |
||
58 | } |
||
59 | |||
60 | $array[$obj->pilot] = $array[$obj->pilot]->addCount( |
||
61 | new FlightTypeCount( |
||
62 | $obj->type, |
||
63 | $obj->nbr, |
||
64 | $this->getFactorByType($obj->type) |
||
65 | ) |
||
66 | ); |
||
67 | } |
||
68 | $i++; |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | |||
73 | if (!$query->isIncludeTotal()) { |
||
74 | return $array; |
||
75 | } |
||
76 | |||
77 | //total orga |
||
78 | $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type IN (1,2) GROUP BY fk_organisateur'; |
||
79 | $resql = $this->db->query($sql); |
||
80 | View Code Duplication | if ($resql) { |
|
|
|||
81 | $num = $this->db->num_rows($resql); |
||
82 | $i = 0; |
||
83 | if ($num) { |
||
84 | while ($i < $num) { |
||
85 | $obj = $this->db->fetch_object($resql); //vol |
||
86 | |||
87 | if ($obj) { |
||
88 | |||
89 | if (!isset($array[$obj->rowid])) { |
||
90 | $name = $obj->firstname . ' ' . $obj->name; |
||
91 | $pilot = Pilot::create($name, $obj->rowid); |
||
92 | $array[$obj->rowid] = $pilot; |
||
93 | } |
||
94 | |||
95 | $array[$obj->rowid] = $array[$obj->rowid]->addCount( |
||
96 | new FlightTypeCount( |
||
97 | 'orga', |
||
98 | $obj->total, |
||
99 | $this->getFactorByType('orga') |
||
100 | ) |
||
101 | ); |
||
102 | } |
||
103 | $i++; |
||
104 | } |
||
105 | } |
||
106 | } |
||
107 | |||
108 | //total orga T6 - instructeur |
||
109 | $sql = 'SELECT llx_user.lastname as name , llx_user.firstname,llx_user.rowid, count(idBBC_vols) as total FROM llx_bbc_vols LEFT JOIN llx_user ON rowid = fk_organisateur WHERE YEAR(date) = \'' . $query->getFiscalYear() . '\' AND fk_type = 6 GROUP BY fk_organisateur'; |
||
110 | $resql = $this->db->query($sql); |
||
111 | View Code Duplication | if ($resql) { |
|
112 | $num = $this->db->num_rows($resql); |
||
113 | $i = 0; |
||
114 | if ($num) { |
||
115 | while ($i < $num) { |
||
116 | $obj = $this->db->fetch_object($resql); //vol |
||
117 | |||
118 | if ($obj) { |
||
119 | if (!isset($array[$obj->rowid])) { |
||
120 | $name = $obj->firstname . ' ' . $obj->name; |
||
121 | $pilot = Pilot::create($name, $obj->rowid); |
||
122 | $array[$obj->rowid] = $pilot; |
||
123 | } |
||
124 | |||
125 | $array[$obj->rowid] = $array[$obj->rowid]->addCount( |
||
126 | new FlightTypeCount( |
||
127 | 'orga_T6', |
||
128 | $obj->total, |
||
129 | $this->getFactorByType('orga_T6') |
||
130 | ) |
||
131 | ); |
||
132 | } |
||
133 | $i++; |
||
134 | } |
||
135 | } |
||
136 | } |
||
137 | |||
138 | return $array; |
||
139 | } |
||
140 | |||
184 | } |
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.