| Conditions | 7 |
| Paths | 9 |
| Total Lines | 123 |
| Code Lines | 71 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| Bugs | 2 | 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 |
||
| 41 | public function loadRoutes($env, $manager) |
||
| 42 | { |
||
| 43 | $routes = [ |
||
| 44 | 'dev' => [ |
||
| 45 | [ |
||
| 46 | 'parent' => '/swp/default/routes', |
||
| 47 | 'name' => 'news', |
||
| 48 | 'variablePattern' => '/{slug}', |
||
| 49 | 'requirements' => [ |
||
| 50 | 'slug' => '[a-zA-Z1-9\-_\/]+', |
||
| 51 | ], |
||
| 52 | 'defaults' => [ |
||
| 53 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContainerPageAction', |
||
| 54 | ], |
||
| 55 | ], |
||
| 56 | [ |
||
| 57 | 'parent' => '/swp/default/routes', |
||
| 58 | 'name' => 'articles', |
||
| 59 | 'defaults' => [ |
||
| 60 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContentPageAction', |
||
| 61 | ], |
||
| 62 | ], |
||
| 63 | [ |
||
| 64 | 'parent' => '/swp/default/routes/articles', |
||
| 65 | 'name' => 'get-involved', |
||
| 66 | 'defaults' => [ |
||
| 67 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContentPageAction', |
||
| 68 | ], |
||
| 69 | ], |
||
| 70 | [ |
||
| 71 | 'parent' => '/swp/default/routes/articles', |
||
| 72 | 'name' => 'features', |
||
| 73 | 'defaults' => [ |
||
| 74 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContentPageAction', |
||
| 75 | ], |
||
| 76 | ], |
||
| 77 | ], |
||
| 78 | 'test' => [ |
||
| 79 | [ |
||
| 80 | 'parent' => '/swp/default/routes', |
||
| 81 | 'name' => 'news', |
||
| 82 | 'variablePattern' => '/{slug}', |
||
| 83 | 'requirements' => [ |
||
| 84 | 'slug' => '[a-zA-Z1-9\-_\/]+', |
||
| 85 | ], |
||
| 86 | 'defaults' => [ |
||
| 87 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContainerPageAction', |
||
| 88 | ], |
||
| 89 | ], |
||
| 90 | [ |
||
| 91 | 'parent' => '/swp/client1/routes', |
||
| 92 | 'name' => 'news', |
||
| 93 | 'variablePattern' => '/{slug}', |
||
| 94 | 'requirements' => [ |
||
| 95 | 'slug' => '[a-zA-Z1-9\-_\/]+', |
||
| 96 | ], |
||
| 97 | 'defaults' => [ |
||
| 98 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContainerPageAction', |
||
| 99 | ], |
||
| 100 | ], |
||
| 101 | [ |
||
| 102 | 'parent' => '/swp/default/routes', |
||
| 103 | 'name' => 'articles', |
||
| 104 | 'defaults' => [ |
||
| 105 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContentPageAction', |
||
| 106 | ], |
||
| 107 | ], |
||
| 108 | [ |
||
| 109 | 'parent' => '/swp/default/routes/articles', |
||
| 110 | 'name' => 'features', |
||
| 111 | 'defaults' => [ |
||
| 112 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContentPageAction', |
||
| 113 | ], |
||
| 114 | ], |
||
| 115 | [ |
||
| 116 | 'parent' => '/swp/client1/routes', |
||
| 117 | 'name' => 'features', |
||
| 118 | 'defaults' => [ |
||
| 119 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContentPageAction', |
||
| 120 | ], |
||
| 121 | ], |
||
| 122 | [ |
||
| 123 | 'parent' => '/swp/default/routes', |
||
| 124 | 'name' => 'homepage', |
||
| 125 | 'defaults' => [ |
||
| 126 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContainerPageAction', |
||
| 127 | ], |
||
| 128 | ], |
||
| 129 | [ |
||
| 130 | 'parent' => '/swp/client1/routes', |
||
| 131 | 'name' => 'homepage', |
||
| 132 | 'defaults' => [ |
||
| 133 | '_controller' => '\SWP\Bundle\WebRendererBundle\Controller\ContentController::renderContainerPageAction', |
||
| 134 | ], |
||
| 135 | ], |
||
| 136 | ], |
||
| 137 | ]; |
||
| 138 | |||
| 139 | foreach ($routes[$env] as $routeData) { |
||
| 140 | $route = new Route(); |
||
| 141 | $route->setParentDocument($manager->find(null, $routeData['parent'])); |
||
| 142 | $route->setName($routeData['name']); |
||
| 143 | |||
| 144 | if (isset($routeData['variablePattern'])) { |
||
| 145 | $route->setVariablePattern($routeData['variablePattern']); |
||
| 146 | } |
||
| 147 | |||
| 148 | if (isset($routeData['requirements'])) { |
||
| 149 | foreach ($routeData['requirements'] as $key => $value) { |
||
| 150 | $route->setRequirement($key, $value); |
||
| 151 | } |
||
| 152 | } |
||
| 153 | |||
| 154 | if (isset($routeData['defaults'])) { |
||
| 155 | foreach ($routeData['defaults'] as $key => $value) { |
||
| 156 | $route->setDefault($key, $value); |
||
| 157 | } |
||
| 158 | } |
||
| 159 | $manager->persist($route); |
||
| 160 | } |
||
| 161 | |||
| 162 | $manager->flush(); |
||
| 163 | } |
||
| 164 | |||
| 266 |