Conditions | 1 |
Paths | 1 |
Total Lines | 63 |
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 |
||
130 | public function provideConflictDetection() { |
||
131 | $cases = []; |
||
132 | |||
133 | // #0: adding a label where there was none before |
||
134 | $base = self::newEntity( Item::ENTITY_TYPE ); |
||
135 | $current = unserialize( serialize( $base ) ); |
||
136 | |||
137 | $new = unserialize( serialize( $base ) ); |
||
138 | $new->setLabel( 'en', 'TEST' ); |
||
139 | |||
140 | $cases[] = [ |
||
141 | $base, |
||
142 | $current, |
||
143 | $new, |
||
144 | 0 // there should eb no conflicts. |
||
145 | ]; |
||
146 | |||
147 | // #1: adding an alias where there was none before |
||
148 | $base = self::newEntity( Item::ENTITY_TYPE ); |
||
149 | $current = $base; |
||
150 | |||
151 | $new = unserialize( serialize( $base ) ); |
||
152 | $new->setAliases( 'en', [ 'TEST' ] ); |
||
153 | |||
154 | $cases[] = [ |
||
155 | $base, |
||
156 | $current, |
||
157 | $new, |
||
158 | 0 // there should eb no conflicts. |
||
159 | ]; |
||
160 | |||
161 | // #2: adding an alias where there already was one before |
||
162 | $base = self::newEntity( Item::ENTITY_TYPE ); |
||
163 | $base->setAliases( 'en', [ 'Foo' ] ); |
||
164 | $current = $base; |
||
165 | |||
166 | $new = unserialize( serialize( $base ) ); |
||
167 | $new->setAliases( 'en', [ 'Bar' ] ); |
||
168 | |||
169 | $cases[] = [ |
||
170 | $base, |
||
171 | $current, |
||
172 | $new, |
||
173 | 0 // there should be no conflicts. |
||
174 | ]; |
||
175 | |||
176 | // #3: adding an alias where there already was one in another language |
||
177 | $base = self::newEntity( Item::ENTITY_TYPE ); |
||
178 | $base->setAliases( 'en', [ 'Foo' ] ); |
||
179 | $current = $base; |
||
180 | |||
181 | $new = unserialize( serialize( $base ) ); |
||
182 | $new->setAliases( 'de', [ 'Bar' ] ); |
||
183 | |||
184 | $cases[] = [ |
||
185 | $base, |
||
186 | $current, |
||
187 | $new, |
||
188 | 0 // there should be no conflicts. |
||
189 | ]; |
||
190 | |||
191 | return $cases; |
||
192 | } |
||
193 | |||
219 |