| Conditions | 1 |
| Paths | 1 |
| Total Lines | 93 |
| Code Lines | 56 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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->addEngine(TestEngine::class); |
||
| 94 | |||
| 95 | $validation->addAlias('aliased', 'notEmpty'); |
||
| 96 | $validation->addChecker('my', MyChecker::class); |
||
| 97 | $validation->addCondition('cond', MyCondition::class); |
||
| 98 | |||
| 99 | $json->addContentType('application/vnd.api+json'); |
||
| 100 | |||
| 101 | $this->registerInterceptedRoute( |
||
| 102 | $router, |
||
| 103 | 'without', |
||
| 104 | [ |
||
| 105 | new Interceptor\Append('one'), |
||
| 106 | new Interceptor\Append('two'), |
||
| 107 | new Interceptor\Append('three'), |
||
| 108 | ] |
||
| 109 | ); |
||
| 110 | |||
| 111 | $this->registerInterceptedRoute( |
||
| 112 | $router, |
||
| 113 | 'with', |
||
| 114 | [ |
||
| 115 | $pipelineInterceptor, |
||
| 116 | ] |
||
| 117 | ); |
||
| 118 | $this->registerInterceptedRoute( |
||
| 119 | $router, |
||
| 120 | 'mix', |
||
| 121 | [ |
||
| 122 | new Interceptor\Append('four'), |
||
| 123 | new Interceptor\Append('five'), |
||
| 124 | $pipelineInterceptor, |
||
| 125 | new Interceptor\Append('six'), |
||
| 126 | ] |
||
| 127 | ); |
||
| 128 | $this->registerInterceptedRoute( |
||
| 129 | $router, |
||
| 130 | 'dup', |
||
| 131 | [ |
||
| 132 | $pipelineInterceptor, |
||
| 133 | new Interceptor\Append('one'), |
||
| 134 | new Interceptor\Append('two'), |
||
| 135 | new Interceptor\Append('three'), |
||
| 136 | ] |
||
| 137 | ); |
||
| 138 | $this->registerInterceptedRoute( |
||
| 139 | $router, |
||
| 140 | 'skip', |
||
| 141 | [ |
||
| 142 | new Interceptor\Append('one'), |
||
| 143 | $pipelineInterceptor, |
||
| 144 | new Interceptor\Append('two'), |
||
| 145 | new Interceptor\Append('three'), |
||
| 146 | ] |
||
| 147 | ); |
||
| 148 | $this->registerInterceptedRoute( |
||
| 149 | $router, |
||
| 150 | 'first', |
||
| 151 | [ |
||
| 152 | $pipelineInterceptor, |
||
| 153 | new Interceptor\Append('four'), |
||
| 154 | new Interceptor\Append('five'), |
||
| 155 | new Interceptor\Append('six'), |
||
| 156 | ] |
||
| 183 |