Conditions | 1 |
Paths | 1 |
Total Lines | 67 |
Code Lines | 47 |
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 |
||
136 | public function testWillTryAutoGeneration() : void |
||
137 | { |
||
138 | $instance = new stdClass(); |
||
139 | $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); |
||
140 | $generator = $this->createMock(GeneratorStrategyInterface::class); |
||
141 | $autoloader = $this->createMock(AutoloaderInterface::class); |
||
142 | |||
143 | $this->config->expects(self::any())->method('getGeneratorStrategy')->will(self::returnValue($generator)); |
||
144 | $this->config->expects(self::any())->method('getProxyAutoloader')->will(self::returnValue($autoloader)); |
||
145 | |||
146 | $generator |
||
147 | ->expects(self::once()) |
||
148 | ->method('generate') |
||
149 | ->with( |
||
150 | self::callback( |
||
151 | function (ClassGenerator $targetClass) use ($proxyClassName) : bool { |
||
152 | return $targetClass->getName() === $proxyClassName; |
||
153 | } |
||
154 | ) |
||
155 | ); |
||
156 | |||
157 | // simulate autoloading |
||
158 | $autoloader |
||
159 | ->expects(self::once()) |
||
160 | ->method('__invoke') |
||
161 | ->with($proxyClassName) |
||
162 | ->willReturnCallback(function () use ($proxyClassName) : bool { |
||
163 | eval( |
||
164 | 'class ' . $proxyClassName |
||
165 | . ' extends \\ProxyManagerTestAsset\\AccessInterceptorValueHolderMock {}' |
||
166 | ); |
||
167 | |||
168 | return true; |
||
169 | }); |
||
170 | |||
171 | $this |
||
172 | ->inflector |
||
173 | ->expects(self::once()) |
||
174 | ->method('getProxyClassName') |
||
175 | ->with('stdClass') |
||
176 | ->will(self::returnValue($proxyClassName)); |
||
177 | |||
178 | $this |
||
179 | ->inflector |
||
180 | ->expects(self::once()) |
||
181 | ->method('getUserClassName') |
||
182 | ->with('stdClass') |
||
183 | ->will(self::returnValue(LazyLoadingMock::class)); |
||
184 | |||
185 | $this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature'); |
||
186 | $this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0)); |
||
187 | |||
188 | $factory = new AccessInterceptorScopeLocalizerFactory($this->config); |
||
189 | $prefixInterceptors = [function () { |
||
190 | self::fail('Not supposed to be called'); |
||
191 | }]; |
||
192 | $suffixInterceptors = [function () { |
||
193 | self::fail('Not supposed to be called'); |
||
194 | }]; |
||
195 | /* @var $proxy AccessInterceptorValueHolderMock */ |
||
196 | $proxy = $factory->createProxy($instance, $prefixInterceptors, $suffixInterceptors); |
||
197 | |||
198 | self::assertInstanceOf($proxyClassName, $proxy); |
||
199 | self::assertSame($instance, $proxy->instance); |
||
200 | self::assertSame($prefixInterceptors, $proxy->prefixInterceptors); |
||
201 | self::assertSame($suffixInterceptors, $proxy->suffixInterceptors); |
||
202 | } |
||
203 | } |
||
204 |