Conditions | 5 |
Paths | 5 |
Total Lines | 80 |
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 |
||
29 | public function index(){ |
||
30 | $obj_ret = array(); |
||
31 | |||
32 | $sql = "SELECT "; |
||
33 | $sql .= 'rowid,'; |
||
34 | $sql .= 'date,'; |
||
35 | $sql .= 'lieuD,'; |
||
36 | $sql .= 'lieuA,'; |
||
37 | $sql .= 'heureD,'; |
||
38 | $sql .= 'heureA,'; |
||
39 | $sql .= 'BBC_ballons_idBBC_ballons,'; |
||
40 | $sql .= 'nbrPax,'; |
||
41 | $sql .= 'remarque,'; |
||
42 | $sql .= 'incidents,'; |
||
43 | $sql .= 'fk_type,'; |
||
44 | $sql .= 'fk_pilot,'; |
||
45 | $sql .= 'fk_organisateur,'; |
||
46 | $sql .= 'is_facture,'; |
||
47 | $sql .= 'kilometers,'; |
||
48 | $sql .= 'cost,'; |
||
49 | $sql .= 'fk_receiver,'; |
||
50 | $sql .= 'justif_kilometers,'; |
||
51 | $sql .= 'date_creation,'; |
||
52 | $sql .= 'date_update,'; |
||
53 | $sql .= 'passenger_names'; |
||
54 | |||
55 | $sql.= " FROM ".MAIN_DB_PREFIX."bbc_vols"; |
||
56 | |||
57 | $sql.= ' WHERE 1=1 LIMIT 10'; |
||
58 | |||
59 | // Add sql filters |
||
60 | |||
61 | $result = $this->connection->query($sql); |
||
62 | |||
63 | if ($result) |
||
64 | { |
||
65 | $num = $this->connection->num_rows($result); |
||
66 | $min = min($num, (-1 <= 0 ? $num : -1)); |
||
67 | $i=0; |
||
68 | while ($i < $min) |
||
69 | { |
||
70 | $obj = $this->connection->fetch_object($result); |
||
71 | |||
72 | $flight = new Flight(); |
||
73 | $flight->rowid = (int)$obj->rowid; |
||
74 | $flight->date = $obj->date; |
||
75 | $flight->lieuD = $obj->lieuD; |
||
76 | $flight->lieuA = $obj->lieuA; |
||
77 | $flight->heureD = $obj->heureD; |
||
78 | $flight->heureA = $obj->heureA; |
||
79 | $flight->balloon = (int)$obj->BBC_ballons_idBBC_ballons; |
||
80 | $flight->nbrPax = (int)$obj->nbrPax; |
||
81 | $flight->remarque = $obj->remarque; |
||
82 | $flight->incidents = $obj->incidents; |
||
83 | $flight->type = (int)$obj->fk_type; |
||
84 | $flight->pilot = (int)$obj->fk_pilot; |
||
85 | $flight->organisator = (int)$obj->fk_organisateur; |
||
86 | $flight->billed = (bool)$obj->is_facture; |
||
87 | $flight->cost = (int)$obj->cost; |
||
88 | $flight->receiver = (int)$obj->fk_receiver; |
||
89 | $flight->kilometers = (int)$obj->kilometers ; |
||
90 | $flight->justifKilometers = $obj->justif_kilometers; |
||
91 | $flight->createdAt = $obj->date_creation; |
||
92 | $flight->updatedAt = $obj->date_update; |
||
93 | |||
94 | $obj_ret[] = $flight; |
||
95 | |||
96 | $i++; |
||
97 | } |
||
98 | } |
||
99 | else { |
||
100 | throw new RestException(500, 'Error when retrieve commande list : '.$this->connection->lasterror()); |
||
101 | } |
||
102 | |||
103 | if( ! count($obj_ret)) { |
||
104 | throw new RestException(404, 'No flight found'); |
||
105 | } |
||
106 | |||
107 | return $obj_ret; |
||
108 | } |
||
109 | } |