| Conditions | 1 |
| Paths | 1 |
| Total Lines | 59 |
| Code Lines | 35 |
| 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 |
||
| 18 | public function testContainerInjected(): void |
||
| 19 | { |
||
| 20 | $container = $this->getContainer(); |
||
| 21 | |||
| 22 | $routes = [ |
||
| 23 | Route::get('/info')->name('api-info'), |
||
| 24 | Group::create( |
||
| 25 | '/v2', |
||
| 26 | [ |
||
| 27 | Route::get('/user')->name('api-v2-user/index'), |
||
| 28 | Route::get('/user/{id}')->name('api-v2-user/view'), |
||
| 29 | Group::create( |
||
| 30 | '/news', |
||
| 31 | [ |
||
| 32 | Route::get('/post')->name('api-v2-news-post/index'), |
||
| 33 | Route::get('/post/{id}')->name('api-v2-news-post/view'), |
||
| 34 | ] |
||
| 35 | ), |
||
| 36 | Group::create( |
||
| 37 | '/blog', |
||
| 38 | [ |
||
| 39 | Route::get('/post')->name('api-v2-blog-post/index'), |
||
| 40 | Route::get('/post/{id}')->name('api-v2-blog-post/view'), |
||
| 41 | ] |
||
| 42 | ), |
||
| 43 | Route::get('/note')->name('api-v2-note/index'), |
||
| 44 | Route::get('/note/{id}')->name('api-v2-note/view'), |
||
| 45 | ] |
||
| 46 | ), |
||
| 47 | Group::create( |
||
| 48 | '/v2', |
||
| 49 | [ |
||
| 50 | Route::get('/user')->name('api-v2-user/index'), |
||
| 51 | Route::get('/user/{id}')->name('api-v2-user/view'), |
||
| 52 | Group::create( |
||
| 53 | '/news', |
||
| 54 | [ |
||
| 55 | Route::get('/post')->name('api-v2-news-post/index'), |
||
| 56 | Route::get('/post/{id}')->name('api-v2-news-post/view'), |
||
| 57 | ] |
||
| 58 | ), |
||
| 59 | Group::create( |
||
| 60 | '/blog', |
||
| 61 | [ |
||
| 62 | Route::get('/post')->name('api-v2-blog-post/index'), |
||
| 63 | Route::get('/post/{id}')->name('api-v2-blog-post/view'), |
||
| 64 | ] |
||
| 65 | ), |
||
| 66 | Route::get('/note')->name('api-v2-note/index'), |
||
| 67 | Route::get('/note/{id}')->name('api-v2-note/view'), |
||
| 68 | ] |
||
| 69 | ) |
||
| 70 | ]; |
||
| 71 | |||
| 72 | $factory = new RouterFactory($this->getEngineFactory(), $routes); |
||
| 73 | $router = $factory($container); |
||
| 74 | $items = $router->getItems(); |
||
| 75 | |||
| 76 | $this->assertAllRoutesAndGroupsHaveContainer($items); |
||
| 77 | } |
||
| 130 |
For hinted functions/methods where all return statements with the correct type are only reachable via conditions, ?null? gets implicitly returned which may be incompatible with the hinted type. Let?s take a look at an example: