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