Conditions | 1 |
Paths | 1 |
Total Lines | 65 |
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 |
||
50 | public function testRouteDynamic() |
||
51 | { |
||
52 | $router = new Router(); |
||
53 | $collection = $router->getRoutes(); |
||
54 | |||
55 | RouteFactory::generateStandardRoute( |
||
56 | $collection, |
||
57 | "admin.standard", |
||
58 | StandardRoute::class, |
||
59 | "/admin", |
||
60 | '/:controller/:action', ['module' => 'admin']); |
||
61 | RouteFactory::generateStandardRoute( |
||
62 | $collection, "api.standard", |
||
63 | StandardRoute::class, |
||
64 | "/api", |
||
65 | '/:controller/:action', ['module' => 'api']); |
||
66 | |||
67 | RouteFactory::generateStandardRoute( |
||
68 | $collection, |
||
69 | "frontend.standard", |
||
70 | StandardRoute::class, |
||
71 | "/"); |
||
72 | |||
73 | $request = Request::create('/api/pages/delete'); |
||
74 | self::assertEquals( |
||
75 | ['module' => 'api', 'controller' => 'pages', 'action' => 'delete', '_route' => 'api.standard'], |
||
76 | $router->matchRequest($request) |
||
77 | ); |
||
78 | |||
79 | $request = Request::create('/api/pages/'); |
||
80 | self::assertEquals( |
||
81 | ['module' => 'api', 'controller' => 'pages', 'action' => 'index', '_route' => 'api.standard'], |
||
82 | $router->matchRequest($request) |
||
83 | ); |
||
84 | |||
85 | $request = Request::create('/api/pages'); |
||
86 | self::assertEquals( |
||
87 | ['module' => 'api', 'controller' => 'pages', 'action' => 'index', '_route' => 'api.standard'], |
||
88 | $router->matchRequest($request) |
||
89 | ); |
||
90 | |||
91 | $request = Request::create('/admin/pages/delete'); |
||
92 | self::assertEquals( |
||
93 | ['module' => 'admin', 'controller' => 'pages', 'action' => 'delete', '_route' => 'admin.standard'], |
||
94 | $router->matchRequest($request) |
||
95 | ); |
||
96 | |||
97 | $request = Request::create('/users/delete'); |
||
98 | self::assertEquals( |
||
99 | ['controller' => 'users', 'action' => 'delete', '_route' => 'frontend.standard'], |
||
100 | $router->matchRequest($request) |
||
101 | ); |
||
102 | |||
103 | $request = Request::create('/users/'); |
||
104 | self::assertEquals( |
||
105 | ['controller' => 'users', 'action' => 'index', '_route' => 'frontend.standard'], |
||
106 | $router->matchRequest($request) |
||
107 | ); |
||
108 | |||
109 | $request = Request::create('/users'); |
||
110 | self::assertEquals( |
||
111 | ['controller' => 'users', 'action' => 'index', '_route' => 'frontend.standard'], |
||
112 | $router->matchRequest($request) |
||
113 | ); |
||
114 | } |
||
115 | } |
||
116 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.