| Conditions | 1 |
| Paths | 1 |
| Total Lines | 99 |
| 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 |
||
| 34 | public function testInit() |
||
| 35 | { |
||
| 36 | $adminConfiguration = [ |
||
| 37 | 'my_admin' => [ |
||
| 38 | 'entity' => 'TestClass', |
||
| 39 | 'actions' => [ |
||
| 40 | 'test' => [ |
||
| 41 | 'service' => 'test', |
||
| 42 | ], |
||
| 43 | ] |
||
| 44 | ], |
||
| 45 | ]; |
||
| 46 | $entity = 'TestClass'; |
||
| 47 | $dataProviderString = 'data_provider'; |
||
| 48 | $eventDispatcher = $this->getMockWithoutConstructor(EventDispatcher::class); |
||
| 49 | $eventDispatcher |
||
| 50 | ->expects($this->exactly(3)) |
||
| 51 | ->method('dispatch') |
||
| 52 | ; |
||
| 53 | |||
| 54 | $adminConfigurationObject = $this->getMockWithoutConstructor(AdminConfiguration::class); |
||
| 55 | $adminConfigurationObject |
||
| 56 | ->expects($this->atLeastOnce()) |
||
| 57 | ->method('getParameter') |
||
| 58 | ->willReturnMap([ |
||
| 59 | ['entity', $entity], |
||
| 60 | ['data_provider', $dataProviderString], |
||
| 61 | ]) |
||
| 62 | ; |
||
| 63 | |||
| 64 | $applicationConfigurationObject = $this->getMockWithoutConstructor(ApplicationConfiguration::class); |
||
| 65 | $applicationConfigurationObject |
||
| 66 | ->expects($this->atLeastOnce()) |
||
| 67 | ->method('getParameter') |
||
| 68 | ->willReturnMap([ |
||
| 69 | ['admin_class', Admin::class], |
||
| 70 | ]) |
||
| 71 | ; |
||
| 72 | |||
| 73 | $configurationFactory = $this->getMockWithoutConstructor(ConfigurationFactory::class); |
||
| 74 | $configurationFactory |
||
| 75 | ->expects($this->once()) |
||
| 76 | ->method('create') |
||
| 77 | ->with($adminConfiguration['my_admin']) |
||
| 78 | ->willReturn($adminConfigurationObject) |
||
| 79 | ; |
||
| 80 | |||
| 81 | $actionFactory = $this->getMockWithoutConstructor(ActionFactory::class); |
||
| 82 | $messageHandler = $this->getMockWithoutConstructor(MessageHandlerInterface::class); |
||
| 83 | $registry = $this->getMockWithoutConstructor(Registry::class); |
||
| 84 | |||
| 85 | |||
| 86 | $dataProvider = $this->getMockWithoutConstructor(DataProviderInterface::class); |
||
| 87 | |||
| 88 | $dataProviderFactory = $this->getMockWithoutConstructor(DataProviderFactory::class); |
||
| 89 | $dataProviderFactory |
||
| 90 | ->expects($this->once()) |
||
| 91 | ->method('get') |
||
| 92 | ->with('data_provider') |
||
| 93 | ->willReturn($dataProvider) |
||
| 94 | ; |
||
| 95 | |||
| 96 | $requestHandler = $this->getMockWithoutConstructor(RequestHandler::class); |
||
| 97 | $authorizationChecker = $this->getMockWithoutConstructor(AuthorizationCheckerInterface::class); |
||
| 98 | $tokenStorage = $this->getMockWithoutConstructor(TokenStorageInterface::class); |
||
| 99 | |||
| 100 | $actionRegistry = $this->getMockWithoutConstructor(\LAG\AdminBundle\Action\Registry\Registry::class); |
||
| 101 | $viewFactory = $this->getMockWithoutConstructor(ViewFactory::class); |
||
| 102 | |||
| 103 | $applicationConfigurationStorage = $this->getMockWithoutConstructor(ApplicationConfigurationStorage::class); |
||
| 104 | $applicationConfigurationStorage |
||
| 105 | ->expects($this->once()) |
||
| 106 | ->method('getApplicationConfiguration') |
||
| 107 | ->willReturn($applicationConfigurationObject) |
||
| 108 | ; |
||
| 109 | |||
| 110 | $factory = new AdminFactory( |
||
| 111 | $adminConfiguration, |
||
| 112 | $eventDispatcher, |
||
| 113 | $messageHandler, |
||
| 114 | $registry, |
||
| 115 | $actionRegistry, |
||
| 116 | $actionFactory, |
||
| 117 | $configurationFactory, |
||
| 118 | $dataProviderFactory, |
||
| 119 | $viewFactory, |
||
| 120 | $requestHandler, |
||
| 121 | $authorizationChecker, |
||
| 122 | $tokenStorage, |
||
| 123 | $applicationConfigurationStorage |
||
| 124 | ); |
||
| 125 | |||
| 126 | $factory->init(); |
||
| 127 | $this->assertTrue($factory->isInit()); |
||
| 128 | |||
| 129 | // second init should do nothing |
||
| 130 | $factory->init(); |
||
| 131 | $this->assertTrue($factory->isInit()); |
||
| 132 | } |
||
| 133 | |||
| 203 |