| Conditions | 11 |
| Paths | 11 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 86 | public function getTransactionStatus() |
||
| 87 | { |
||
| 88 | if ($this->getType() === 'payments') { |
||
| 89 | switch ($this->getAction()) { |
||
| 90 | case 'confirmed': |
||
| 91 | case 'paid_out': |
||
| 92 | return NotificationInterface::STATUS_COMPLETED; |
||
| 93 | case 'pending_customer_approval': |
||
| 94 | case 'pending_submission': |
||
| 95 | case 'submitted': |
||
| 96 | return NotificationInterface::STATUS_PENDING; |
||
| 97 | case 'cancelled': |
||
| 98 | case 'charged_back': |
||
| 99 | case 'customer_approval_denied': |
||
| 100 | case 'failed': |
||
| 101 | return NotificationInterface::STATUS_FAILED; |
||
| 102 | default: |
||
| 103 | // no state change, do nothing? other events from docs: |
||
| 104 | // created -- pending? |
||
| 105 | // customer_approval_granted -- pending? |
||
| 106 | // chargeback_cancelled |
||
| 107 | // late_failure_settled -- failure? |
||
| 108 | // chargeback_settled -- failure? |
||
| 109 | // surcharge_fee_debited |
||
| 110 | // resubmission_requested -- pending? |
||
| 111 | break; |
||
| 112 | } |
||
| 157 |
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: