Conditions | 13 |
Paths | 28 |
Total Lines | 46 |
Code Lines | 30 |
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 |
||
49 | public function homeAction(Request $request): Response |
||
50 | { |
||
51 | $startPageInfo = $this->variableApi->getSystemVar('startController'); |
||
52 | if (!is_array($startPageInfo) || !isset($startPageInfo['controller']) || empty($startPageInfo['controller'])) { |
||
53 | return new Response(''); // home page is static |
||
54 | } |
||
55 | |||
56 | $isValidStartController = true; |
||
57 | [$route, $controller] = explode('###', $startPageInfo['controller']); |
||
58 | if (false === mb_strpos($controller, '\\') || false === mb_strpos($controller, '::')) { |
||
59 | $isValidStartController = false; |
||
60 | } else { |
||
61 | [$vendor, $extensionName] = explode('\\', $controller); |
||
62 | $extensionName = $vendor . $extensionName; |
||
63 | [$fqcn, $method] = explode('::', $controller); |
||
64 | if (!$this->kernel->isBundle($extensionName) || !class_exists($fqcn) || !is_callable([$fqcn, $method])) { |
||
65 | $isValidStartController = false; |
||
66 | } |
||
67 | } |
||
68 | |||
69 | if (!$isValidStartController) { |
||
70 | return new Response(''); // home page is static |
||
71 | } |
||
72 | |||
73 | $queryParams = $requestParams = $attributes = []; |
||
74 | if (null !== $startPageInfo['query']) { |
||
75 | parse_str($startPageInfo['query'], $queryParams); |
||
76 | } |
||
77 | if (null !== $startPageInfo['request']) { |
||
78 | parse_str($startPageInfo['request'], $requestParams); |
||
79 | } |
||
80 | if (null !== $startPageInfo['attributes']) { |
||
81 | parse_str($startPageInfo['attributes'], $attributes); |
||
82 | } |
||
83 | $attributes['_controller'] = $controller; |
||
84 | $attributes['_route'] = $route; |
||
85 | |||
86 | $subRequest = $request->duplicate($queryParams, $requestParams, $attributes); |
||
87 | |||
88 | $subRequest->attributes->set('_zkBundle', $extensionName); |
||
|
|||
89 | $subRequest->attributes->set('_zkModule', $extensionName); |
||
90 | // fix for #3929, #3932 |
||
91 | $request->attributes->set('_zkBundle', $extensionName); |
||
92 | $request->attributes->set('_zkModule', $extensionName); |
||
93 | |||
94 | return $this->kernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST); |
||
95 | } |
||
97 |