Conditions | 6 |
Paths | 6 |
Total Lines | 62 |
Code Lines | 37 |
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 |
||
43 | public function previewTemplatesAction(Request $request, Application $app) |
||
44 | { |
||
45 | if (!$app['security']->isGranted('ROLE_ADMIN')) { |
||
46 | $app->abort(403); |
||
47 | } |
||
48 | |||
49 | $data = array(); |
||
50 | |||
51 | $templates = array(); |
||
52 | $template = $request->query->get('template', false); |
||
53 | $raw = $request->query->has('raw'); |
||
54 | |||
55 | // Set some possible global defaults for the template |
||
56 | $emailData = array( |
||
57 | 'app' => $app, |
||
58 | 'user' => $app['user'], |
||
59 | 'content' => 'Hello world!', |
||
60 | 'formData' => array( |
||
61 | 'message' => 'Just a test message!', |
||
62 | ), |
||
63 | ); |
||
64 | |||
65 | if ($template && $raw) { |
||
66 | $app['debug'] = false; |
||
67 | $app['showProfiler'] = false; |
||
68 | |||
69 | return $app['mailer.css_to_inline_styles_converter']( |
||
70 | 'emails/'.$template.'.html.twig', |
||
71 | $emailData |
||
72 | ); |
||
73 | } |
||
74 | |||
75 | $templatesArray = Helpers::rglob( |
||
76 | APP_DIR.'/templates/emails/*.html.twig' |
||
77 | ); |
||
78 | |||
79 | if ($templatesArray) { |
||
80 | foreach ($templatesArray as $templatePath) { |
||
81 | $templatePath = str_replace( |
||
82 | APP_DIR.'/templates/emails/', |
||
83 | '', |
||
84 | $templatePath |
||
85 | ); |
||
86 | |||
87 | $templates[] = str_replace( |
||
88 | '.html.twig', |
||
89 | '', |
||
90 | $templatePath |
||
91 | ); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | $data['template'] = $template; |
||
96 | $data['templates'] = $templates; |
||
97 | |||
98 | return new Response( |
||
99 | $app['twig']->render( |
||
100 | 'contents/members-area/tools/email/preview-templates.html.twig', |
||
101 | $data |
||
102 | ) |
||
103 | ); |
||
104 | } |
||
105 | } |
||
106 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.