Conditions | 15 |
Paths | 15 |
Total Lines | 106 |
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 |
||
94 | protected function getMagentoEditionByYearAndVersion($year, $version) |
||
95 | { |
||
96 | switch ($year) { |
||
97 | case 2008: |
||
98 | if (in_array($version, [ |
||
99 | '1', |
||
100 | '1.1.1', |
||
101 | '1.1.2', |
||
102 | '1.1.3', |
||
103 | '1.1.4', |
||
104 | '1.1.5', |
||
105 | '1.1.6', |
||
106 | '1.1.7', |
||
107 | '1.1.8', |
||
108 | '1.2.0', |
||
109 | '1.2.0.1', |
||
110 | '1.2.0.2', |
||
111 | '1.2.0.3', |
||
112 | '1.2.1', |
||
113 | '1.2.1.1', |
||
114 | '1.2.1.2', |
||
115 | '1.3.0', |
||
116 | '1.3.1', |
||
117 | '1.3.1.1', |
||
118 | '1.3.2', |
||
119 | '1.3.2.1', |
||
120 | '1.3.2.2', |
||
121 | '1.3.2.3', |
||
122 | '1.3.2.4', |
||
123 | '1.3.3.0', |
||
124 | '1.4.0.0', |
||
125 | '1.4.0.1', |
||
126 | '1.4.1.0', |
||
127 | '1.4.1.1', |
||
128 | '1.4.2.0', |
||
129 | ]) |
||
130 | ) { |
||
131 | return Version::EDITION_COMMUNITY; |
||
132 | } |
||
133 | break; |
||
134 | case 2010: |
||
135 | if (in_array($version, [ |
||
136 | '1.5.0.0', |
||
137 | '1.5.0.1', |
||
138 | '1.5.1.0', |
||
139 | '1.6.0.0', |
||
140 | '1.6.1.0', |
||
141 | '1.6.2.0', |
||
142 | ]) |
||
143 | ) { |
||
144 | return Version::EDITION_COMMUNITY; |
||
145 | } |
||
146 | break; |
||
147 | case 2012: |
||
148 | if (in_array($version, [ |
||
149 | '1.7.0.0', |
||
150 | '1.7.0.1', |
||
151 | '1.7.0.2', |
||
152 | ]) |
||
153 | ) { |
||
154 | return Version::EDITION_COMMUNITY; |
||
155 | } |
||
156 | break; |
||
157 | case 2013: |
||
158 | if (in_array($version, [ |
||
159 | '1.8.0.0', |
||
160 | '1.8.1.0', |
||
161 | ]) |
||
162 | ) { |
||
163 | return Version::EDITION_COMMUNITY; |
||
164 | } |
||
165 | break; |
||
166 | case 2014: |
||
167 | if (in_array($version, [ |
||
168 | '1.9.0.0', |
||
169 | '1.9.0.1', |
||
170 | '1.9.1.0', |
||
171 | '1.9.1.1', |
||
172 | ]) |
||
173 | ) { |
||
174 | return Version::EDITION_COMMUNITY; |
||
175 | } |
||
176 | break; |
||
177 | case 2015: |
||
178 | if (in_array($version, [ |
||
179 | '1.9.1.1', |
||
180 | '1.9.2.0', |
||
181 | '1.9.2.1', |
||
182 | '1.9.2.2', |
||
183 | ]) |
||
184 | ) { |
||
185 | return Version::EDITION_COMMUNITY; |
||
186 | } |
||
187 | break; |
||
188 | case 2016: |
||
189 | if (in_array($version, [ |
||
190 | '1.9.2.3', |
||
191 | '1.9.2.4', |
||
192 | ]) |
||
193 | ) { |
||
194 | return Version::EDITION_COMMUNITY; |
||
195 | } |
||
196 | break; |
||
197 | } |
||
198 | return Version::EDITION_ENTERPRISE; |
||
199 | } |
||
200 | } |
||
201 |
This check looks for type mismatches where the missing type is
false
. This is usually indicative of an error condtion.Consider the follow example
This function either returns a new
DateTime
object or false, if there was an error. This is a typical pattern in PHP programming to show that an error has occurred without raising an exception. The calling code should check for this returnedfalse
before passing on the value to another function or method that may not be able to handle afalse
.