| Conditions | 1 |
| Paths | 1 |
| Total Lines | 80 |
| 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 |
||
| 195 | protected function setUp(): void { |
||
| 196 | parent::setUp(); |
||
| 197 | |||
| 198 | // Set an Entity manager mock. |
||
| 199 | $this->entityManager = $this->getMockBuilder(EntityManagerInterface::class)->getMock(); |
||
| 200 | |||
| 201 | // Set an Event dispatcher mock. |
||
| 202 | $this->eventDispatcher = $this->getMockBuilder(EventDispatcherInterface::class)->getMock(); |
||
| 203 | |||
| 204 | // Set a Flash bag mock. |
||
| 205 | $this->flashBag = $this->getMockBuilder(FlashBagInterface::class)->getMock(); |
||
| 206 | |||
| 207 | // Set a Kernel mock. |
||
| 208 | $this->kernel = $this->getMockBuilder(KernelInterface::class)->getMock(); |
||
| 209 | |||
| 210 | // Set a Logger mock. |
||
| 211 | $this->logger = $this->getMockBuilder(LoggerInterface::class)->getMock(); |
||
| 212 | |||
| 213 | // Set an Object manager mock. |
||
| 214 | $this->objectManager = $this->getMockBuilder(ObjectManager::class)->getMock(); |
||
| 215 | |||
| 216 | // Set a Router mock. |
||
| 217 | $this->router = $this->getMockBuilder(RouterInterface::class)->getMock(); |
||
| 218 | |||
| 219 | // Set a Session mock. |
||
| 220 | $this->session = $this->getMockBuilder(SessionInterface::class)->getMock(); |
||
| 221 | |||
| 222 | // Set a Session bag mock. |
||
| 223 | $this->sessionBag = $this->getMockBuilder(SessionBagInterface::class)->getMock(); |
||
| 224 | |||
| 225 | // Set a Swift mailer mock. |
||
| 226 | $this->swiftMailer = $this->getMockBuilder(Swift_Mailer::class)->disableOriginalConstructor()->getMock(); |
||
| 227 | |||
| 228 | // Set a Translator mock. |
||
| 229 | $this->translator = $this->getMockBuilder(BaseTranslatorInterface::class)->getMock(); |
||
| 230 | $this->translator->expects($this->any())->method("trans")->willReturnCallback(function($id, array $parameters = [], $domain = null, $locale = null) { |
||
| 231 | return $id; |
||
| 232 | }); |
||
| 233 | |||
| 234 | // Set a Token mock. |
||
| 235 | $this->token = $this->getMockBuilder(TokenInterface::class)->getMock(); |
||
| 236 | $this->token->expects($this->any())->method("getUser")->willReturnCallback(function() { |
||
| 237 | return $this->user; |
||
| 238 | }); |
||
| 239 | |||
| 240 | // Set a Token storage mock. |
||
| 241 | $this->tokenStorage = $this->getMockBuilder(TokenStorageInterface::class)->getMock(); |
||
| 242 | $this->tokenStorage->expects($this->any())->method("getToken")->willReturn($this->token); |
||
| 243 | |||
| 244 | // Set a Twig loader mock. |
||
| 245 | $this->twigLoader = $this->getMockBuilder(LoaderInterface::class)->getMock(); |
||
| 246 | |||
| 247 | // Set a Twig environment mock. |
||
| 248 | $this->twigEnvironment = $this->getMockBuilder(Environment::class)->setConstructorArgs([$this->twigLoader, []])->getMock(); |
||
| 249 | $this->twigEnvironment->expects($this->any())->method("addGlobal")->willReturnCallback(function($name, $value) { |
||
| 250 | $this->twigGlobals[$name] = $value; |
||
| 251 | }); |
||
| 252 | $this->twigEnvironment->expects($this->any())->method("getGlobals")->willReturnCallback(function() { |
||
| 253 | return $this->twigGlobals; |
||
| 254 | }); |
||
| 255 | |||
| 256 | // Set a Parameter bag mock. |
||
| 257 | $parameterBag = new ParameterBag([ |
||
| 258 | "kernel.environment" => "test", |
||
| 259 | "kernel.root_dir" => getcwd() . "/Fixtures/app", |
||
| 260 | ]); |
||
| 261 | |||
| 262 | // We set a container builder with only the necessary. |
||
| 263 | $this->containerBuilder = new ContainerBuilder($parameterBag); |
||
| 264 | $this->containerBuilder->set("doctrine.orm.entity_manager", $this->entityManager); |
||
| 265 | $this->containerBuilder->set("event_dispatcher", $this->eventDispatcher); |
||
| 266 | $this->containerBuilder->set("kernel", $this->kernel); |
||
| 267 | $this->containerBuilder->set("logger", $this->logger); |
||
| 268 | $this->containerBuilder->set("router", $this->router); |
||
| 269 | $this->containerBuilder->set("session", $this->session); |
||
| 270 | $this->containerBuilder->set("security.token_storage", $this->tokenStorage); |
||
| 271 | $this->containerBuilder->set("swiftmailer.mailer", $this->swiftMailer); |
||
| 272 | $this->containerBuilder->set("translator", $this->translator); |
||
| 273 | $this->containerBuilder->set("twig", $this->twigEnvironment); |
||
| 274 | } |
||
| 275 | } |
||
| 276 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.