Conditions | 1 |
Paths | 1 |
Total Lines | 162 |
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 |
||
101 | public function testBodyStructureWithTypedProperties() : void |
||
102 | { |
||
103 | /** @var PropertyGenerator|PHPUnit_Framework_MockObject_MockObject $initializer */ |
||
104 | $initializer = $this->createMock(PropertyGenerator::class); |
||
105 | /** @var PropertyGenerator|PHPUnit_Framework_MockObject_MockObject $initializationTracker */ |
||
106 | $initializationTracker = $this->createMock(PropertyGenerator::class); |
||
107 | |||
108 | $initializer->expects(self::any())->method('getName')->will(self::returnValue('init')); |
||
109 | $initializationTracker->expects(self::any())->method('getName')->will(self::returnValue('track')); |
||
110 | |||
111 | $callInitializer = new CallInitializer( |
||
112 | $initializer, |
||
113 | $initializationTracker, |
||
114 | Properties::fromReflectionClass(new ReflectionClass(ClassWithMixedTypedProperties::class)) |
||
115 | ); |
||
116 | |||
117 | $expectedCode = <<<'PHP' |
||
118 | if ($this->track || ! $this->init) { |
||
119 | return; |
||
120 | } |
||
121 | |||
122 | $this->track = true; |
||
123 | |||
124 | $this->publicUnTypedProperty = 'publicUnTypedProperty'; |
||
125 | $this->publicUnTypedPropertyWithoutDefaultValue = NULL; |
||
126 | $this->publicBoolProperty = true; |
||
127 | $this->publicNullableBoolProperty = true; |
||
128 | $this->publicIntProperty = 123; |
||
129 | $this->publicNullableIntProperty = 123; |
||
130 | $this->publicFloatProperty = 123.456; |
||
131 | $this->publicNullableFloatProperty = 123.456; |
||
132 | $this->publicStringProperty = 'publicStringProperty'; |
||
133 | $this->publicNullableStringProperty = 'publicStringProperty'; |
||
134 | $this->publicArrayProperty = array ( |
||
135 | 0 => 'publicArrayProperty', |
||
136 | ); |
||
137 | $this->publicNullableArrayProperty = array ( |
||
138 | 0 => 'publicArrayProperty', |
||
139 | ); |
||
140 | $this->publicIterableProperty = array ( |
||
141 | 0 => 'publicIterableProperty', |
||
142 | ); |
||
143 | $this->publicNullableIterableProperty = array ( |
||
144 | 0 => 'publicIterableProperty', |
||
145 | ); |
||
146 | $this->protectedUnTypedProperty = 'protectedUnTypedProperty'; |
||
147 | $this->protectedUnTypedPropertyWithoutDefaultValue = NULL; |
||
148 | $this->protectedBoolProperty = true; |
||
149 | $this->protectedNullableBoolProperty = true; |
||
150 | $this->protectedIntProperty = 123; |
||
151 | $this->protectedNullableIntProperty = 123; |
||
152 | $this->protectedFloatProperty = 123.456; |
||
153 | $this->protectedNullableFloatProperty = 123.456; |
||
154 | $this->protectedStringProperty = 'protectedStringProperty'; |
||
155 | $this->protectedNullableStringProperty = 'protectedStringProperty'; |
||
156 | $this->protectedArrayProperty = array ( |
||
157 | 0 => 'protectedArrayProperty', |
||
158 | ); |
||
159 | $this->protectedNullableArrayProperty = array ( |
||
160 | 0 => 'protectedArrayProperty', |
||
161 | ); |
||
162 | $this->protectedIterableProperty = array ( |
||
163 | 0 => 'protectedIterableProperty', |
||
164 | ); |
||
165 | $this->protectedNullableIterableProperty = array ( |
||
166 | 0 => 'protectedIterableProperty', |
||
167 | ); |
||
168 | static $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties; |
||
169 | |||
170 | $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties ?: $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(function ($instance) { |
||
171 | $instance->privateUnTypedProperty = 'privateUnTypedProperty'; |
||
172 | $instance->privateUnTypedPropertyWithoutDefaultValue = NULL; |
||
173 | $instance->privateBoolProperty = true; |
||
174 | $instance->privateNullableBoolProperty = true; |
||
175 | $instance->privateIntProperty = 123; |
||
176 | $instance->privateNullableIntProperty = 123; |
||
177 | $instance->privateFloatProperty = 123.456; |
||
178 | $instance->privateNullableFloatProperty = 123.456; |
||
179 | $instance->privateStringProperty = 'privateStringProperty'; |
||
180 | $instance->privateNullableStringProperty = 'privateStringProperty'; |
||
181 | $instance->privateArrayProperty = array ( |
||
182 | 0 => 'privateArrayProperty', |
||
183 | ); |
||
184 | $instance->privateNullableArrayProperty = array ( |
||
185 | 0 => 'privateArrayProperty', |
||
186 | ); |
||
187 | $instance->privateIterableProperty = array ( |
||
188 | 0 => 'privateIterableProperty', |
||
189 | ); |
||
190 | $instance->privateNullableIterableProperty = array ( |
||
191 | 0 => 'privateIterableProperty', |
||
192 | ); |
||
193 | }, null, 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties'); |
||
194 | |||
195 | $cacheProxyManagerTestAsset_ClassWithMixedTypedProperties($this); |
||
196 | |||
197 | |||
198 | |||
199 | |||
200 | $properties = [ |
||
201 | 'publicUnTypedProperty' => & $this->publicUnTypedProperty, |
||
202 | 'publicUnTypedPropertyWithoutDefaultValue' => & $this->publicUnTypedPropertyWithoutDefaultValue, |
||
203 | 'publicBoolProperty' => & $this->publicBoolProperty, |
||
204 | 'publicNullableBoolProperty' => & $this->publicNullableBoolProperty, |
||
205 | 'publicIntProperty' => & $this->publicIntProperty, |
||
206 | 'publicNullableIntProperty' => & $this->publicNullableIntProperty, |
||
207 | 'publicFloatProperty' => & $this->publicFloatProperty, |
||
208 | 'publicNullableFloatProperty' => & $this->publicNullableFloatProperty, |
||
209 | 'publicStringProperty' => & $this->publicStringProperty, |
||
210 | 'publicNullableStringProperty' => & $this->publicNullableStringProperty, |
||
211 | 'publicArrayProperty' => & $this->publicArrayProperty, |
||
212 | 'publicNullableArrayProperty' => & $this->publicNullableArrayProperty, |
||
213 | 'publicIterableProperty' => & $this->publicIterableProperty, |
||
214 | 'publicNullableIterableProperty' => & $this->publicNullableIterableProperty, |
||
215 | '' . "\0" . '*' . "\0" . 'protectedUnTypedProperty' => & $this->protectedUnTypedProperty, |
||
216 | '' . "\0" . '*' . "\0" . 'protectedUnTypedPropertyWithoutDefaultValue' => & $this->protectedUnTypedPropertyWithoutDefaultValue, |
||
217 | '' . "\0" . '*' . "\0" . 'protectedBoolProperty' => & $this->protectedBoolProperty, |
||
218 | '' . "\0" . '*' . "\0" . 'protectedNullableBoolProperty' => & $this->protectedNullableBoolProperty, |
||
219 | '' . "\0" . '*' . "\0" . 'protectedIntProperty' => & $this->protectedIntProperty, |
||
220 | '' . "\0" . '*' . "\0" . 'protectedNullableIntProperty' => & $this->protectedNullableIntProperty, |
||
221 | '' . "\0" . '*' . "\0" . 'protectedFloatProperty' => & $this->protectedFloatProperty, |
||
222 | '' . "\0" . '*' . "\0" . 'protectedNullableFloatProperty' => & $this->protectedNullableFloatProperty, |
||
223 | '' . "\0" . '*' . "\0" . 'protectedStringProperty' => & $this->protectedStringProperty, |
||
224 | '' . "\0" . '*' . "\0" . 'protectedNullableStringProperty' => & $this->protectedNullableStringProperty, |
||
225 | '' . "\0" . '*' . "\0" . 'protectedArrayProperty' => & $this->protectedArrayProperty, |
||
226 | '' . "\0" . '*' . "\0" . 'protectedNullableArrayProperty' => & $this->protectedNullableArrayProperty, |
||
227 | '' . "\0" . '*' . "\0" . 'protectedIterableProperty' => & $this->protectedIterableProperty, |
||
228 | '' . "\0" . '*' . "\0" . 'protectedNullableIterableProperty' => & $this->protectedNullableIterableProperty, |
||
229 | ]; |
||
230 | |||
231 | static $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties; |
||
232 | |||
233 | $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties ?: $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties = \Closure::bind(function ($instance, array & $properties) { |
||
234 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateUnTypedProperty'] = & $instance->privateUnTypedProperty; |
||
235 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateUnTypedPropertyWithoutDefaultValue'] = & $instance->privateUnTypedPropertyWithoutDefaultValue; |
||
236 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateBoolProperty'] = & $instance->privateBoolProperty; |
||
237 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableBoolProperty'] = & $instance->privateNullableBoolProperty; |
||
238 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateIntProperty'] = & $instance->privateIntProperty; |
||
239 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableIntProperty'] = & $instance->privateNullableIntProperty; |
||
240 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateFloatProperty'] = & $instance->privateFloatProperty; |
||
241 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableFloatProperty'] = & $instance->privateNullableFloatProperty; |
||
242 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateStringProperty'] = & $instance->privateStringProperty; |
||
243 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableStringProperty'] = & $instance->privateNullableStringProperty; |
||
244 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateArrayProperty'] = & $instance->privateArrayProperty; |
||
245 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableArrayProperty'] = & $instance->privateNullableArrayProperty; |
||
246 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateIterableProperty'] = & $instance->privateIterableProperty; |
||
247 | $properties['' . "\0" . 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties' . "\0" . 'privateNullableIterableProperty'] = & $instance->privateNullableIterableProperty; |
||
248 | }, $this, 'ProxyManagerTestAsset\\ClassWithMixedTypedProperties'); |
||
249 | |||
250 | $cacheFetchProxyManagerTestAsset_ClassWithMixedTypedProperties($this, $properties); |
||
251 | |||
252 | $result = $this->init->__invoke($this, $methodName, $parameters, $this->init, $properties); |
||
253 | $this->track = false; |
||
254 | |||
255 | return $result; |
||
256 | PHP; |
||
257 | |||
258 | self::assertSame( |
||
259 | $expectedCode, |
||
260 | $callInitializer->getBody() |
||
261 | ); |
||
262 | } |
||
263 | } |
||
264 |