| Conditions | 1 |
| Paths | 1 |
| Total Lines | 152 |
| Code Lines | 95 |
| 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 |
||
| 63 | public function boot( |
||
| 64 | \Spiral\Bootloader\Auth\AuthBootloader $authBootloader, |
||
| 65 | RouterInterface $router, |
||
| 66 | PermissionsInterface $rbac, |
||
| 67 | ViewsBootloader $views, |
||
| 68 | ValidationBootloader $validation, |
||
| 69 | JsonPayloadsBootloader $json, |
||
| 70 | PipelineInterceptor $pipelineInterceptor |
||
| 71 | ): void { |
||
| 72 | $authBootloader->addActorProvider(UserRepository::class); |
||
| 73 | |||
| 74 | $rbac->addRole('user'); |
||
| 75 | $rbac->associate('user', '*'); |
||
| 76 | |||
| 77 | $rbac->addRole('demo'); |
||
| 78 | $rbac->associate('demo', 'demo.*'); |
||
| 79 | |||
| 80 | $route = new Route( |
||
| 81 | '/<action>[/<name>]', |
||
| 82 | new Controller(TestController::class) |
||
| 83 | ); |
||
| 84 | |||
| 85 | $router->setDefault($route->withDefaults(['name' => 'Dave'])); |
||
| 86 | |||
| 87 | $router->setRoute( |
||
| 88 | 'auth', |
||
| 89 | new Route('/auth/<action>', new Controller(AuthController::class)) |
||
| 90 | ); |
||
| 91 | |||
| 92 | $views->addDirectory('custom', __DIR__ . '/../../views/custom/'); |
||
| 93 | $views->addDirectory('stempler', __DIR__ . '/../../views/stempler/'); |
||
| 94 | $views->addEngine(TestEngine::class); |
||
| 95 | |||
| 96 | $validation->addAlias('aliased', 'notEmpty'); |
||
| 97 | $validation->addChecker('my', MyChecker::class); |
||
| 98 | $validation->addCondition('cond', MyCondition::class); |
||
| 99 | |||
| 100 | $json->addContentType('application/vnd.api+json'); |
||
| 101 | |||
| 102 | $this->registerInterceptedRoute( |
||
| 103 | $router, |
||
| 104 | 'without', |
||
| 105 | [ |
||
| 106 | new Interceptor\Append('one'), |
||
| 107 | new Interceptor\Append('two'), |
||
| 108 | new Interceptor\Append('three'), |
||
| 109 | ] |
||
| 110 | ); |
||
| 111 | |||
| 112 | $this->registerInterceptedRoute( |
||
| 113 | $router, |
||
| 114 | 'with', |
||
| 115 | [ |
||
| 116 | $pipelineInterceptor, |
||
| 117 | ] |
||
| 118 | ); |
||
| 119 | $this->registerInterceptedRoute( |
||
| 120 | $router, |
||
| 121 | 'mix', |
||
| 122 | [ |
||
| 123 | new Interceptor\Append('four'), |
||
| 124 | new Interceptor\Append('five'), |
||
| 125 | $pipelineInterceptor, |
||
| 126 | new Interceptor\Append('six'), |
||
| 127 | ] |
||
| 128 | ); |
||
| 129 | $this->registerInterceptedRoute( |
||
| 130 | $router, |
||
| 131 | 'dup', |
||
| 132 | [ |
||
| 133 | $pipelineInterceptor, |
||
| 134 | new Interceptor\Append('one'), |
||
| 135 | new Interceptor\Append('two'), |
||
| 136 | new Interceptor\Append('three'), |
||
| 137 | ] |
||
| 138 | ); |
||
| 139 | $this->registerInterceptedRoute( |
||
| 140 | $router, |
||
| 141 | 'skip', |
||
| 142 | [ |
||
| 143 | new Interceptor\Append('one'), |
||
| 144 | $pipelineInterceptor, |
||
| 145 | new Interceptor\Append('two'), |
||
| 146 | new Interceptor\Append('three'), |
||
| 147 | ] |
||
| 148 | ); |
||
| 149 | $this->registerInterceptedRoute( |
||
| 150 | $router, |
||
| 151 | 'first', |
||
| 152 | [ |
||
| 153 | $pipelineInterceptor, |
||
| 154 | new Interceptor\Append('four'), |
||
| 155 | new Interceptor\Append('five'), |
||
| 156 | new Interceptor\Append('six'), |
||
| 157 | ] |
||
| 158 | ); |
||
| 159 | |||
| 160 | $this->registerInterceptedRoute( |
||
| 161 | $router, |
||
| 162 | 'withoutAttribute', |
||
| 163 | [ |
||
| 164 | new Interceptor\Append('one'), |
||
| 165 | new Interceptor\Append('two'), |
||
| 166 | new Interceptor\Append('three'), |
||
| 167 | ] |
||
| 168 | ); |
||
| 169 | |||
| 170 | $this->registerInterceptedRoute( |
||
| 171 | $router, |
||
| 172 | 'withAttribute', |
||
| 173 | [ |
||
| 174 | $pipelineInterceptor, |
||
| 175 | ] |
||
| 176 | ); |
||
| 177 | $this->registerInterceptedRoute( |
||
| 178 | $router, |
||
| 179 | 'mixAttribute', |
||
| 180 | [ |
||
| 181 | new Interceptor\Append('four'), |
||
| 182 | new Interceptor\Append('five'), |
||
| 183 | $pipelineInterceptor, |
||
| 184 | new Interceptor\Append('six'), |
||
| 185 | ] |
||
| 186 | ); |
||
| 187 | $this->registerInterceptedRoute( |
||
| 188 | $router, |
||
| 189 | 'dupAttribute', |
||
| 190 | [ |
||
| 191 | $pipelineInterceptor, |
||
| 192 | new Interceptor\Append('one'), |
||
| 193 | new Interceptor\Append('two'), |
||
| 194 | new Interceptor\Append('three'), |
||
| 195 | ] |
||
| 196 | ); |
||
| 197 | $this->registerInterceptedRoute( |
||
| 198 | $router, |
||
| 199 | 'skipAttribute', |
||
| 200 | [ |
||
| 201 | new Interceptor\Append('one'), |
||
| 202 | $pipelineInterceptor, |
||
| 203 | new Interceptor\Append('two'), |
||
| 204 | new Interceptor\Append('three'), |
||
| 205 | ] |
||
| 206 | ); |
||
| 207 | $this->registerInterceptedRoute( |
||
| 208 | $router, |
||
| 209 | 'firstAttribute', |
||
| 210 | [ |
||
| 211 | $pipelineInterceptor, |
||
| 212 | new Interceptor\Append('four'), |
||
| 213 | new Interceptor\Append('five'), |
||
| 214 | new Interceptor\Append('six'), |
||
| 215 | ] |
||
| 242 |