| Conditions | 1 |
| Paths | 1 |
| Total Lines | 53 |
| Code Lines | 32 |
| 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 |
||
| 92 | public static function getInvalidSKUs() |
||
| 93 | { |
||
| 94 | // format: [ "sku", "expected exception messages" ] |
||
| 95 | return [ |
||
| 96 | // empty |
||
| 97 | ["", "empty"], |
||
| 98 | |||
| 99 | // white space |
||
| 100 | [" product", "white space"], |
||
| 101 | ["product ", "white space"], |
||
| 102 | [" product ", "white space"], |
||
| 103 | ["pro duct", "white space"], |
||
| 104 | |||
| 105 | // invalid characters |
||
| 106 | ['7$tshirt', "invalid characters"], // Dollar sign |
||
| 107 | ['gâteau', "invalid characters"], // French umlaut |
||
| 108 | ['käse', "invalid characters"], // German umlaut |
||
| 109 | ['product/1', "invalid characters"], |
||
| 110 | ['product:1', "invalid characters"], |
||
| 111 | ['product.1', "invalid characters"], |
||
| 112 | ['product(1)', "invalid characters"], |
||
| 113 | ['product§1', "invalid characters"], |
||
| 114 | ['👃-spray', "invalid characters"], // nose emoji |
||
| 115 | ['Åre', "invalid characters"], // Swedish umlaut |
||
| 116 | ['Öresund', "invalid characters"], // German umlaut |
||
| 117 | ['наушник', "invalid characters"], // Russian |
||
| 118 | ['이어폰', "invalid characters"], // Korean |
||
| 119 | |||
| 120 | // invalid prefix |
||
| 121 | ['-product', "cannot start"], |
||
| 122 | |||
| 123 | |||
| 124 | // invalid postfix |
||
| 125 | ['product-', "cannot end"], |
||
| 126 | |||
| 127 | // uppercase characters |
||
| 128 | ["Product-123", "uppercase"], |
||
| 129 | ["pro-Duct-123", "uppercase"], |
||
| 130 | ["AAA", "uppercase"], |
||
| 131 | ["aBc", "uppercase"], |
||
| 132 | ["abC", "uppercase"], |
||
| 133 | ["abC", "uppercase"], |
||
| 134 | |||
| 135 | // minimum length |
||
| 136 | ["a", "too short"], |
||
| 137 | ["1", "too short"], |
||
| 138 | ["0", "too short"], |
||
| 139 | |||
| 140 | // maximum length |
||
| 141 | ["abcdefghijklmnopqrstuvwxyz0123456789", "too long"], |
||
| 142 | |||
| 143 | ]; |
||
| 144 | } |
||
| 145 | } |
||
| 146 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.