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