Conditions | 15 |
Paths | 16384 |
Total Lines | 84 |
Code Lines | 51 |
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 |
||
142 | private function getDTOReponse(Hook $hook, CommonOutputInterface $commonOutput) |
||
143 | { |
||
144 | $dto = null; |
||
145 | $errorMsg = null; |
||
146 | |||
147 | if (MangoPayConstants::isEventTypeToDoWithPayInNormal($hook->getEventType())) { |
||
148 | $commonOutput->infoid(" Hook is to do with a Pay In Normal"); |
||
149 | $dto = $this->payIn->getPayIn($hook->getResourceId()); |
||
150 | } |
||
151 | |||
152 | if (MangoPayConstants::isEventTypeToDoWithPayOutNormal($hook->getEventType())) { |
||
153 | $commonOutput->infoid(" Hook is to do with a Pay Out Normal"); |
||
154 | $dto = $this->payOut->get($hook->getResourceId()); |
||
155 | } |
||
156 | |||
157 | if (MangoPayConstants::isEventTypeToDoWithTransferNormal($hook->getEventType())) { |
||
158 | $commonOutput->infoid(" Hook is to do with a Transfer Normal"); |
||
159 | $dto = $this->transfer->get($hook->getResourceId()); |
||
160 | } |
||
161 | |||
162 | if (MangoPayConstants::isEventTypeToDoWithPayInRefund($hook->getEventType())) { |
||
163 | $commonOutput->infoid(" Hook is to do with a Pay In Refund"); |
||
164 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
165 | } |
||
166 | |||
167 | if (MangoPayConstants::isEventTypeToDoWithPayOutRefund($hook->getEventType())) { |
||
168 | $commonOutput->infoid(" Hook is to do with a Pay Out Refund"); |
||
169 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
170 | } |
||
171 | |||
172 | if (MangoPayConstants::isEventTypeToDoWithTransferRefund($hook->getEventType())) { |
||
173 | $commonOutput->infoid(" Hook is to do with a Transfer Refund"); |
||
174 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
175 | } |
||
176 | |||
177 | if (MangoPayConstants::isEventTypeToDoWithPayInRepudiation($hook->getEventType())) { |
||
178 | $commonOutput->infoid(" Hook is to do with a Pay In Repudiation"); |
||
179 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
180 | } |
||
181 | |||
182 | if (MangoPayConstants::isEventTypeToDoWithKYC($hook->getEventType())) { |
||
183 | $commonOutput->infoid(" Hook is to do with a KYC"); |
||
184 | $dto = $this->kyc->getDocument($hook->getResourceId()); |
||
185 | } |
||
186 | |||
187 | if (MangoPayConstants::isEventTypeToDoWithDisputeDocument($hook->getEventType())) { |
||
188 | $commonOutput->infoid(" Hook is to do with a Dispute Document"); |
||
189 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
190 | } |
||
191 | |||
192 | if (MangoPayConstants::isEventTypeToDoWithDispute($hook->getEventType())) { |
||
193 | $commonOutput->infoid(" Hook is to do with a Dispute"); |
||
194 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
195 | } |
||
196 | |||
197 | if (MangoPayConstants::isEventTypeToDoWithTransferSettlement($hook->getEventType())) { |
||
198 | $commonOutput->infoid(" Hook is to do with a Transfer Settlement"); |
||
199 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
200 | } |
||
201 | |||
202 | if (MangoPayConstants::isEventTypeToDoWithMandate($hook->getEventType())) { |
||
203 | $commonOutput->infoid(" Hook is to do with a Mandate"); |
||
204 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
205 | } |
||
206 | |||
207 | if (MangoPayConstants::isEventTypeToDoWithPreauthorisation($hook->getEventType())) { |
||
208 | $commonOutput->infoid(" Hook is to do with a PreAuthorisation"); |
||
209 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
210 | } |
||
211 | |||
212 | if (!is_null($errorMsg)) { |
||
213 | $this->sendMessage( |
||
214 | "Error, no code to action HookHandleService \n ```" . $errorMsg . "```", |
||
215 | ':leftwards_arrow_with_hook:' |
||
216 | ); |
||
217 | $commonOutput->error($errorMsg); |
||
218 | |||
219 | throw new \Exception("Inbound hook with event " . $hook->getEventType() . " not handled!"); |
||
220 | } else { |
||
221 | $commonOutput->infoid(" Hook returning with status " . $dto->getStatus()); |
||
222 | } |
||
223 | |||
224 | return $dto; |
||
225 | } |
||
226 | |||
300 |
Let’s assume that you have a directory layout like this:
and let’s assume the following content of
Bar.php
:If both files
OtherDir/Foo.php
andSomeDir/Foo.php
are loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.php
However, as
OtherDir/Foo.php
does not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php
, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: