Conditions | 29 |
Paths | 80 |
Total Lines | 89 |
Code Lines | 71 |
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 |
||
116 | public function haveRights($buildingId, $level, $type, $sup) { |
||
117 | if ($this->isABuilding($buildingId)) { |
||
118 | switch($type) { |
||
119 | // assez de ressources pour contruire ? |
||
120 | case 'resource' : |
||
121 | return ($sup < $this->getBuildingInfo($buildingId, 'level', $level, 'resourcePrice')) ? FALSE : TRUE; |
||
122 | break; |
||
123 | // encore de la place dans la queue ? |
||
124 | // $sup est le nombre de batiments dans la queue |
||
125 | case 'queue' : |
||
126 | // $buildingId n'est pas utilisé |
||
127 | return ($sup < $this->getBuildingInfo($buildingId, 'level', $level, 'nbQueues')) ? TRUE : FALSE; |
||
128 | break; |
||
129 | // droit de construire le batiment ? |
||
130 | // $sup est un objet de type OrbitalBase |
||
131 | case 'buildingTree' : |
||
132 | $diminution = NULL; |
||
133 | switch ($buildingId) { |
||
134 | case OrbitalBaseResource::GENERATOR : |
||
135 | $diminution = 0; |
||
136 | break; |
||
137 | case OrbitalBaseResource::REFINERY : |
||
138 | $diminution = 0; |
||
139 | break; |
||
140 | case OrbitalBaseResource::DOCK1 : |
||
141 | $diminution = 0; |
||
142 | break; |
||
143 | case OrbitalBaseResource::DOCK2 : |
||
144 | $diminution = 20; |
||
145 | break; |
||
146 | case OrbitalBaseResource::DOCK3 : |
||
147 | $diminution = 30; |
||
148 | break; |
||
149 | case OrbitalBaseResource::TECHNOSPHERE : |
||
150 | $diminution = 0; |
||
151 | break; |
||
152 | case OrbitalBaseResource::COMMERCIAL_PLATEFORME : |
||
153 | $diminution = 10; |
||
154 | break; |
||
155 | case OrbitalBaseResource::STORAGE : |
||
156 | $diminution = 0; |
||
157 | break; |
||
158 | case OrbitalBaseResource::RECYCLING : |
||
159 | $diminution = 10; |
||
160 | break; |
||
161 | case OrbitalBaseResource::SPATIOPORT : |
||
162 | $diminution = 20; |
||
163 | break; |
||
164 | default : |
||
165 | throw new ErrorException('buildingId invalide (entre 0 et 9) dans haveRights de OrbitalBaseResource'); |
||
166 | } |
||
167 | if ($diminution !== NULL) { |
||
168 | if ($buildingId == OrbitalBaseResource::GENERATOR) { |
||
169 | if ($level > OrbitalBaseResource::$building[$buildingId]['maxLevel'][$sup->typeOfBase]) { |
||
170 | return 'niveau maximum atteint'; |
||
171 | } else { |
||
172 | return TRUE; |
||
173 | } |
||
174 | } else { |
||
175 | if ($level == 1 AND $sup->typeOfBase == OrbitalBase::TYP_NEUTRAL AND ($buildingId == OrbitalBaseResource::SPATIOPORT OR $buildingId == OrbitalBaseResource::DOCK2)) { |
||
176 | return 'vous devez évoluer votre colonie pour débloquer ce bâtiment'; |
||
177 | } |
||
178 | if ($level > OrbitalBaseResource::$building[$buildingId]['maxLevel'][$sup->typeOfBase]) { |
||
179 | return 'niveau maximum atteint'; |
||
180 | } elseif ($level > ($sup->realGeneratorLevel - $diminution)) { |
||
181 | return 'le niveau du générateur n\'est pas assez élevé'; |
||
182 | } else { |
||
183 | return TRUE; |
||
184 | } |
||
185 | } |
||
186 | } |
||
187 | break; |
||
188 | // a la technologie pour construire ce bâtiment ? |
||
189 | // $sup est un objet de type Technology |
||
190 | case 'techno' : |
||
191 | if ($this->getBuildingInfo($buildingId, 'techno') == -1) { return TRUE; } |
||
192 | if ($sup->getTechnology($this->getBuildingInfo($buildingId, 'techno')) == 1) { |
||
193 | return TRUE; |
||
194 | } else { |
||
195 | return 'il vous faut développer la technologie ' . $this->technologyHelper->getInfo($this->getBuildingInfo($buildingId, 'techno'), 'name'); |
||
196 | } |
||
197 | break; |
||
198 | default : |
||
199 | throw new ErrorException('$type invalide (entre 1 et 4) dans haveRights de OrbitalBaseResource'); |
||
200 | } |
||
201 | } else { |
||
202 | throw new ErrorException('buildingId invalide (entre 0 et 9) dans haveRights de OrbitalBaseResource'); |
||
203 | } |
||
204 | } |
||
205 | } |
The break statement is not necessary if it is preceded for example by a return statement:
If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.