Conditions | 10 |
Paths | 21 |
Total Lines | 66 |
Code Lines | 34 |
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 |
||
39 | public function onKernelController(FilterControllerEvent $event) |
||
40 | { |
||
41 | $controller = $event->getController(); |
||
42 | |||
43 | // $controller passed can be either a class or a Closure. This is not |
||
44 | // usual in Symfony but it may happen. If it is a class, it comes in |
||
45 | // array format |
||
46 | if (!is_array($controller)) { |
||
47 | return; |
||
48 | } |
||
49 | |||
50 | // Get the request with namespace and others information we need and |
||
51 | // construct the bundle namespace |
||
52 | $request = $this->getRequest($event); |
||
53 | |||
54 | $namespace = array('_namespace', '_bundle'); |
||
55 | foreach ($namespace as $key => $value) { |
||
56 | $namespace[$key] = $request->attributes->get($value); |
||
57 | } |
||
58 | |||
59 | array_unshift($namespace, '@'); |
||
60 | $namespace = implode('', $namespace); |
||
61 | $namespace = array($namespace, 'Resources', 'config', 'sonata.yml'); |
||
62 | $namespace = implode('/', $namespace); |
||
63 | |||
64 | // Get the configuration file from the configuration into the |
||
65 | // corresponding bundle |
||
66 | try { |
||
67 | $path = $this->fileLocator->locate($namespace); |
||
68 | } catch (\InvalidArgumentException $e) { |
||
69 | // Nothing to do because there's no SEO file |
||
70 | return; |
||
71 | } |
||
72 | |||
73 | try { |
||
74 | $config = Yaml::parse($path); |
||
75 | } catch (Symfony\Component\Yaml\Exception\ParseException $e) { |
||
76 | // Do nothing on error. Just log error |
||
77 | $this->logger->err('YAML returns a parse error', array('exception' => $e)); |
||
78 | |||
79 | return; |
||
80 | } |
||
81 | |||
82 | $controller = $request->attributes->get('_controller'); |
||
83 | $action = $request->attributes->get('_action'); |
||
84 | |||
85 | if (array_key_exists($controller, $config)) { |
||
86 | $config = $config[$controller]; |
||
87 | |||
88 | if (array_key_exists($action, $config)) { |
||
89 | $config = $config[$action]; |
||
90 | $title = $this->getConfiguration($config, 'title'); |
||
91 | $metas = $this->getConfiguration($config, 'metas'); |
||
92 | |||
93 | if (!empty($title)) { |
||
94 | $this->sonata->setTitle($title); |
||
95 | } |
||
96 | |||
97 | foreach ($metas as $key => $values) { |
||
98 | foreach ($values as $head => $value) { |
||
99 | $this->sonata->addMeta($key, $head, $value); |
||
100 | } |
||
101 | } |
||
102 | } |
||
103 | } |
||
104 | } |
||
105 | |||
147 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function.
Consider the following example. The parameter
$italy
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was removed, but the annotation was not.