Conditions | 2 |
Paths | 2 |
Total Lines | 110 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 0 | Features | 1 |
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 |
||
206 | protected function setUp(): void { |
||
207 | parent::setUp(); |
||
208 | |||
209 | // Set a CSRF token manager. |
||
210 | $this->csrfTokenManager = $this->getMockBuilder(CsrfTokenManagerInterface::class)->getMock(); |
||
211 | |||
212 | // Set an Encoder factory mock. |
||
213 | $this->encoderFactory = $this->getMockBuilder(EncoderFactoryInterface::class)->getMock(); |
||
214 | |||
215 | // Set an Entity manager mock. |
||
216 | $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->getMock(); |
||
217 | |||
218 | // Set an Event dispatcher mock. |
||
219 | $this->eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); |
||
220 | |||
221 | // Set a Flash bag mock. |
||
222 | $this->flashBag = $this->getMockBuilder(FlashBagInterface::class)->getMock(); |
||
223 | |||
224 | // Set a Form factory mock. |
||
225 | $this->formFactory = $this->getMockBuilder(FormFactoryInterface::class)->getMock(); |
||
226 | |||
227 | // Set a Kernel mock. |
||
228 | $this->kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); |
||
229 | |||
230 | // Set a Logger mock. |
||
231 | $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); |
||
232 | |||
233 | // Set a Mailer mock. |
||
234 | $this->mailer = $this->getMockBuilder(MailerInterface::class)->getMock(); |
||
235 | |||
236 | // Set a Request stack. |
||
237 | $this->requestStack = $this->getMockBuilder(RequestStack::class)->disableOriginalConstructor()->getMock(); |
||
238 | |||
239 | // Set a Router mock. |
||
240 | $this->router = $this->getMockBuilder(RouterInterface::class)->getMock(); |
||
241 | |||
242 | // Set a Session mock. |
||
243 | $this->session = $this->getMockBuilder(SessionInterface::class)->getMock(); |
||
244 | |||
245 | // TODO: Remove when dropping support for Symfony 5.2 |
||
246 | if (50300 <= Kernel::VERSION_ID) { |
||
247 | $this->requestStack->expects($this->any())->method("getSession")->willReturn($this->session); |
||
248 | } |
||
249 | |||
250 | // Set a Session bag mock. |
||
251 | $this->sessionBag = $this->getMockBuilder(SessionBagInterface::class)->getMock(); |
||
252 | |||
253 | // Set a trans() callback. |
||
254 | $trans = TestCaseHelper::getTranslatorTransFunction(); |
||
255 | |||
256 | // Set a Translator mock. |
||
257 | $this->translator = $this->getMockBuilder(TranslatorInterface::class)->getMock(); |
||
258 | $this->translator->expects($this->any())->method("trans")->willReturnCallback($trans); |
||
259 | |||
260 | // Set getUser() callback. |
||
261 | $getUser = function(): ?UserInterface { |
||
262 | return $this->user; |
||
263 | }; |
||
264 | |||
265 | // Set a Token mock. |
||
266 | $this->token = $this->getMockBuilder(TokenInterface::class)->getMock(); |
||
267 | $this->token->expects($this->any())->method("getUser")->willReturnCallback($getUser); |
||
268 | |||
269 | // Set a Token storage mock. |
||
270 | $this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); |
||
271 | $this->tokenStorage->expects($this->any())->method("getToken")->willReturn($this->token); |
||
272 | |||
273 | // Set a Twig loader mock. |
||
274 | $this->twigLoader = $this->getMockBuilder(LoaderInterface::class)->getMock(); |
||
275 | |||
276 | // Set addGlobal() callback. |
||
277 | $addGlobal = function(string $name, $value): void { |
||
278 | $this->twigGlobals[$name] = $value; |
||
279 | }; |
||
280 | |||
281 | // Set getGlobals() callback. |
||
282 | $getGlobals = function(): array { |
||
283 | return $this->twigGlobals; |
||
284 | }; |
||
285 | |||
286 | // Set a Twig environment mock. |
||
287 | $this->twigEnvironment = $this->getMockBuilder(Environment::class)->setConstructorArgs([$this->twigLoader, []])->getMock(); |
||
288 | $this->twigEnvironment->expects($this->any())->method("addGlobal")->willReturnCallback($addGlobal); |
||
289 | $this->twigEnvironment->expects($this->any())->method("getGlobals")->willReturnCallback($getGlobals); |
||
290 | |||
291 | // Set a Parameter bag mock. |
||
292 | $parameterBag = new ParameterBag([ |
||
293 | "kernel.environment" => "test", |
||
294 | "kernel.project_dir" => realpath(__DIR__ . "/Fixtures/app"), |
||
295 | ]); |
||
296 | |||
297 | // Set a Container builder with only the necessary. |
||
298 | $this->containerBuilder = new ContainerBuilder($parameterBag); |
||
299 | $this->containerBuilder->set("doctrine.orm.entity_manager", $this->entityManager); |
||
300 | $this->containerBuilder->set("event_dispatcher", $this->eventDispatcher); |
||
301 | $this->containerBuilder->set("form.factory", $this->formFactory); |
||
302 | $this->containerBuilder->set("kernel", $this->kernel); |
||
303 | $this->containerBuilder->set("logger", $this->logger); |
||
304 | $this->containerBuilder->set("mailer", $this->mailer); |
||
305 | $this->containerBuilder->set("router", $this->router); |
||
306 | $this->containerBuilder->set("request_stack", $this->requestStack); |
||
307 | $this->containerBuilder->set("session", $this->session); |
||
308 | $this->containerBuilder->set("security.csrf.token_manager", $this->csrfTokenManager); |
||
309 | $this->containerBuilder->set("security.encoder_factory", $this->encoderFactory); |
||
310 | $this->containerBuilder->set("security.token_storage", $this->tokenStorage); |
||
311 | $this->containerBuilder->set("swiftmailer.mailer", $this->mailer); |
||
312 | $this->containerBuilder->set("translator", $this->translator); |
||
313 | $this->containerBuilder->set("twig", $this->twigEnvironment); |
||
314 | |||
315 | $this->containerBuilder->set("Psr\\Container\\ContainerInterface", $this->containerBuilder); |
||
316 | } |
||
318 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths