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