| Conditions | 23 |
| Paths | 23 |
| Total Lines | 52 |
| Code Lines | 47 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 |
||
| 41 | public function century(int $century): string |
||
| 42 | { |
||
| 43 | if ($century < 0) { |
||
| 44 | return I18N::translate('%s BCE', $this->century(-$century)); |
||
| 45 | } |
||
| 46 | |||
| 47 | // The current chart engine (Google charts) can't handle <sup></sup> markup |
||
| 48 | switch ($century) { |
||
| 49 | case 21: |
||
| 50 | return strip_tags(I18N::translateContext('CENTURY', '21st')); |
||
| 51 | case 20: |
||
| 52 | return strip_tags(I18N::translateContext('CENTURY', '20th')); |
||
| 53 | case 19: |
||
| 54 | return strip_tags(I18N::translateContext('CENTURY', '19th')); |
||
| 55 | case 18: |
||
| 56 | return strip_tags(I18N::translateContext('CENTURY', '18th')); |
||
| 57 | case 17: |
||
| 58 | return strip_tags(I18N::translateContext('CENTURY', '17th')); |
||
| 59 | case 16: |
||
| 60 | return strip_tags(I18N::translateContext('CENTURY', '16th')); |
||
| 61 | case 15: |
||
| 62 | return strip_tags(I18N::translateContext('CENTURY', '15th')); |
||
| 63 | case 14: |
||
| 64 | return strip_tags(I18N::translateContext('CENTURY', '14th')); |
||
| 65 | case 13: |
||
| 66 | return strip_tags(I18N::translateContext('CENTURY', '13th')); |
||
| 67 | case 12: |
||
| 68 | return strip_tags(I18N::translateContext('CENTURY', '12th')); |
||
| 69 | case 11: |
||
| 70 | return strip_tags(I18N::translateContext('CENTURY', '11th')); |
||
| 71 | case 10: |
||
| 72 | return strip_tags(I18N::translateContext('CENTURY', '10th')); |
||
| 73 | case 9: |
||
| 74 | return strip_tags(I18N::translateContext('CENTURY', '9th')); |
||
| 75 | case 8: |
||
| 76 | return strip_tags(I18N::translateContext('CENTURY', '8th')); |
||
| 77 | case 7: |
||
| 78 | return strip_tags(I18N::translateContext('CENTURY', '7th')); |
||
| 79 | case 6: |
||
| 80 | return strip_tags(I18N::translateContext('CENTURY', '6th')); |
||
| 81 | case 5: |
||
| 82 | return strip_tags(I18N::translateContext('CENTURY', '5th')); |
||
| 83 | case 4: |
||
| 84 | return strip_tags(I18N::translateContext('CENTURY', '4th')); |
||
| 85 | case 3: |
||
| 86 | return strip_tags(I18N::translateContext('CENTURY', '3rd')); |
||
| 87 | case 2: |
||
| 88 | return strip_tags(I18N::translateContext('CENTURY', '2nd')); |
||
| 89 | case 1: |
||
| 90 | return strip_tags(I18N::translateContext('CENTURY', '1st')); |
||
| 91 | default: |
||
| 92 | return ($century - 1) . '01-' . $century . '00'; |
||
| 93 | } |
||
| 190 |
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: