| Conditions | 15 |
| Paths | 16384 |
| Total Lines | 69 |
| Code Lines | 36 |
| 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 |
||
| 123 | private function getDTOReponse(Hook $hook, CommonOutputInterface $commonOutput) |
||
| 124 | { |
||
| 125 | $dto = null; |
||
| 126 | $errorMsg = null; |
||
| 127 | |||
| 128 | if (MangoPayConstants::isEventTypeToDoWithPayInNormal($hook->getEventType())) { |
||
| 129 | $dto = $this->payIn->getPayIn($hook->getResourceId()); |
||
| 130 | } |
||
| 131 | |||
| 132 | if (MangoPayConstants::isEventTypeToDoWithPayOutNormal($hook->getEventType())) { |
||
| 133 | $dto = $this->payOut->get($hook->getResourceId()); |
||
| 134 | } |
||
| 135 | |||
| 136 | if (MangoPayConstants::isEventTypeToDoWithTransferNormal($hook->getEventType())) { |
||
| 137 | $dto = $this->transfer->get($hook->getResourceId()); |
||
| 138 | } |
||
| 139 | |||
| 140 | if (MangoPayConstants::isEventTypeToDoWithPayInRefund($hook->getEventType())) { |
||
| 141 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 142 | } |
||
| 143 | |||
| 144 | if (MangoPayConstants::isEventTypeToDoWithPayOutRefund($hook->getEventType())) { |
||
| 145 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 146 | } |
||
| 147 | |||
| 148 | if (MangoPayConstants::isEventTypeToDoWithTransferRefund($hook->getEventType())) { |
||
| 149 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 150 | } |
||
| 151 | |||
| 152 | if (MangoPayConstants::isEventTypeToDoWithPayInRepudiation($hook->getEventType())) { |
||
| 153 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 154 | } |
||
| 155 | |||
| 156 | if (MangoPayConstants::isEventTypeToDoWithKYC($hook->getEventType())) { |
||
| 157 | $dto = $this->kyc->getDocument($hook->getResourceId()); |
||
| 158 | } |
||
| 159 | |||
| 160 | if (MangoPayConstants::isEventTypeToDoWithDisputeDocument($hook->getEventType())) { |
||
| 161 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 162 | } |
||
| 163 | |||
| 164 | if (MangoPayConstants::isEventTypeToDoWithDispute($hook->getEventType())) { |
||
| 165 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 166 | } |
||
| 167 | |||
| 168 | if (MangoPayConstants::isEventTypeToDoWithTransferSettlement($hook->getEventType())) { |
||
| 169 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 170 | } |
||
| 171 | |||
| 172 | if (MangoPayConstants::isEventTypeToDoWithMandate($hook->getEventType())) { |
||
| 173 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 174 | } |
||
| 175 | |||
| 176 | if (MangoPayConstants::isEventTypeToDoWithPreauthorisation($hook->getEventType())) { |
||
| 177 | $errorMsg = $hook->getEventType() . " NOT YET HANDLED. NEEDS CODING UP!"; |
||
| 178 | } |
||
| 179 | |||
| 180 | if (!is_null($errorMsg)) { |
||
| 181 | $this->sendMessage( |
||
| 182 | "Error, no code to action HookHandleService \n ```" . $errorMsg . "```", |
||
| 183 | ':leftwards_arrow_with_hook:' |
||
| 184 | ); |
||
| 185 | $commonOutput->error($errorMsg); |
||
| 186 | |||
| 187 | throw new \Exception("Inbound hook with event " . $hook->getEventType() . " not handled!"); |
||
| 188 | } |
||
| 189 | |||
| 190 | return $dto; |
||
| 191 | } |
||
| 192 | |||
| 266 |
Let’s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let’s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare 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.phpHowever, as
OtherDir/Foo.phpdoes 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: