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