| Conditions | 1 |
| Paths | 1 |
| Total Lines | 51 |
| Code Lines | 28 |
| 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 |
||
| 25 | public function testMakingMvcApplication() |
||
| 26 | { |
||
| 27 | $router = new Router(); |
||
| 28 | |||
| 29 | $router->addRoute([ |
||
| 30 | 'AppRoute' => [ |
||
| 31 | 'module' => 'Master', |
||
| 32 | 'controller' => 'Admin', |
||
| 33 | 'view' => 'index' |
||
| 34 | ], |
||
| 35 | ]); |
||
| 36 | |||
| 37 | // you should code the request to match /Master/Admin/index |
||
| 38 | $router->setIdentifiers('Master', 'Admin', 'index'); |
||
| 39 | |||
| 40 | $router->setClassNameBuilder(function($module, $class) { |
||
| 41 | return "\\$module\Controller\\$class"; |
||
| 42 | }); |
||
| 43 | |||
| 44 | \Drone\Loader\ClassMap::$path = 'test-skeleton/module/Master/source'; |
||
| 45 | spl_autoload_register("Drone\Loader\ClassMap::autoload"); |
||
| 46 | |||
| 47 | $router->match(); |
||
| 48 | $ctrl = $router->getController(); |
||
|
|
|||
| 49 | |||
| 50 | # inject the module dependency to the controller |
||
| 51 | $router->getController()->setModule(ModuleFactory::create("Master", [ |
||
| 52 | "config" => 'test-skeleton/module/Master/config/config.php' |
||
| 53 | ])); |
||
| 54 | |||
| 55 | $result = $router->run(); |
||
| 56 | |||
| 57 | $this->assertSame(["message" => "Hello world!"], $result); |
||
| 58 | |||
| 59 | $router->addRoute([ |
||
| 60 | 'AppRouteView' => [ |
||
| 61 | 'module' => 'Master', |
||
| 62 | 'controller' => 'Admin', |
||
| 63 | 'view' => 'withView' |
||
| 64 | ], |
||
| 65 | ]); |
||
| 66 | |||
| 67 | $router->setIdentifiers('Master', 'Admin', 'withView'); |
||
| 68 | $router->match(); |
||
| 69 | $result = $router->run(); |
||
| 70 | |||
| 71 | $this->assertTrue($result instanceof View); |
||
| 72 | |||
| 73 | $result->setPath("test-skeleton/module/Master/source/view/Admin"); |
||
| 74 | |||
| 75 | $this->assertSame("<h1>Hello world!</h1>", $result->getContents()); |
||
| 76 | |||
| 81 | } |