Conditions | 1 |
Paths | 1 |
Total Lines | 61 |
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 |
||
119 | public function testWillTryAutoGeneration() : void |
||
120 | { |
||
121 | $className = UniqueIdentifierGenerator::getIdentifier('foo'); |
||
122 | $proxyClassName = UniqueIdentifierGenerator::getIdentifier('bar'); |
||
123 | $generator = $this->createMock(GeneratorStrategyInterface::class); |
||
124 | $autoloader = $this->createMock(AutoloaderInterface::class); |
||
125 | |||
126 | $this->config->method('getGeneratorStrategy')->will(self::returnValue($generator)); |
||
127 | $this->config->method('getProxyAutoloader')->will(self::returnValue($autoloader)); |
||
128 | |||
129 | $generator |
||
130 | ->expects(self::once()) |
||
131 | ->method('generate') |
||
132 | ->with( |
||
133 | self::callback( |
||
134 | static function (ClassGenerator $targetClass) use ($proxyClassName) : bool { |
||
135 | return $targetClass->getName() === $proxyClassName; |
||
136 | } |
||
137 | ) |
||
138 | ); |
||
139 | |||
140 | // simulate autoloading |
||
141 | $autoloader |
||
142 | ->expects(self::once()) |
||
143 | ->method('__invoke') |
||
144 | ->with($proxyClassName) |
||
145 | ->willReturnCallback(static function () use ($proxyClassName) : bool { |
||
146 | eval('class ' . $proxyClassName . ' extends \\ProxyManagerTestAsset\\LazyLoadingMock {}'); |
||
147 | |||
148 | return true; |
||
149 | }); |
||
150 | |||
151 | $this |
||
152 | ->inflector |
||
153 | ->expects(self::once()) |
||
154 | ->method('getProxyClassName') |
||
155 | ->with($className) |
||
156 | ->willReturn($proxyClassName); |
||
157 | |||
158 | $this |
||
159 | ->inflector |
||
160 | ->expects(self::once()) |
||
161 | ->method('getUserClassName') |
||
162 | ->with($className) |
||
163 | ->willReturn(EmptyClass::class); |
||
164 | |||
165 | $this->signatureChecker->expects(self::atLeastOnce())->method('checkSignature'); |
||
166 | $this->classSignatureGenerator->expects(self::once())->method('addSignature')->will(self::returnArgument(0)); |
||
167 | |||
168 | $factory = new LazyLoadingValueHolderFactory($this->config); |
||
169 | $initializer = static function () : void { |
||
170 | }; |
||
171 | /** @var LazyLoadingMock $proxy */ |
||
172 | $proxy = $factory->createProxy($className, $initializer); |
||
173 | |||
174 | /** @noinspection UnnecessaryAssertionInspection */ |
||
175 | self::assertInstanceOf($proxyClassName, $proxy); |
||
176 | |||
177 | self::assertSame($proxyClassName, get_class($proxy)); |
||
178 | self::assertSame($initializer, $proxy->initializer); |
||
179 | } |
||
180 | } |
||
181 |