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