| Conditions | 11 | 
| Paths | 73 | 
| Total Lines | 57 | 
| 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 | ||
| 16 | public function load(array $configs, ContainerBuilder $container) | ||
| 17 |     { | ||
| 18 | $configuration = new Configuration(); | ||
| 19 | $config = $this->processConfiguration($configuration, $configs); | ||
| 20 | |||
| 21 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); | ||
| 22 |         $loader->load('services.yml'); | ||
| 23 | |||
| 24 |         if ('none' === $config['metadata']['cache']) { | ||
| 25 |             $container->removeAlias('novaway.open_graph.metadata.cache'); | ||
| 26 |         } elseif ('file' === $config['metadata']['cache']) { | ||
| 27 | $container | ||
| 28 |                 ->getDefinition('novaway.open_graph.metadata.file_cache') | ||
| 29 | ->replaceArgument(0, $config['metadata']['file_cache']['dir']) | ||
| 30 | ; | ||
| 31 | $dir = $container->getParameterBag()->resolveValue($config['metadata']['file_cache']['dir']); | ||
| 32 |             if (!file_exists($dir)) { | ||
| 33 |                 if (!$rs = @mkdir($dir, 0777, true)) { | ||
| 34 |                     throw new \RuntimeException(sprintf('Could not create cache directory "%s".', $dir)); | ||
| 35 | } | ||
| 36 | } | ||
| 37 |         } else { | ||
| 38 |             $container->setAlias('novaway.open_graph.metadata.cache', new Alias($config['metadata']['cache'], false)); | ||
| 39 | } | ||
| 40 | |||
| 41 |         $debug = ($config['metadata']['debug'] || $container->getParameter('kernel.debug')); | ||
| 42 | $container | ||
| 43 |             ->getDefinition('novaway.open_graph.metadata_factory') | ||
| 44 | ->replaceArgument(2, $debug) | ||
| 45 | ; | ||
| 46 | |||
| 47 |         $bundles = $container->getParameter('kernel.bundles'); | ||
| 48 | |||
| 49 | $directories = []; | ||
| 50 |         if ($config['metadata']['auto_detection']) { | ||
| 51 |             foreach ($bundles as $name => $class) { | ||
| 52 | $ref = new \ReflectionClass($class); | ||
| 53 | $directories[$ref->getNamespaceName()] = dirname($ref->getFileName()).'/Resources/config/open-graph'; | ||
| 54 | } | ||
| 55 | } | ||
| 56 |         foreach ($config['metadata']['directories'] as $directory) { | ||
| 57 |             $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/'); | ||
| 58 |             if ('@' === $directory['path'][0]) { | ||
| 59 | $bundleName = substr($directory['path'], 1, strpos($directory['path'], '/') - 1); | ||
| 60 |                 if (!isset($bundles[$bundleName])) { | ||
| 61 |                     throw new \RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. Available bundles: %s', $bundleName, implode(', ', array_keys($bundles)))); | ||
| 62 | } | ||
| 63 | $ref = new \ReflectionClass($bundles[$bundleName]); | ||
| 64 |                 $directory['path'] = dirname($ref->getFileName()).substr($directory['path'], strlen('@'.$bundleName)); | ||
| 65 | } | ||
| 66 | $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/'); | ||
| 67 | } | ||
| 68 | $container | ||
| 69 |             ->getDefinition('novaway.open_graph.metadata.file_locator') | ||
| 70 | ->replaceArgument(0, $directories) | ||
| 71 | ; | ||
| 72 | } | ||
| 73 | } | ||
| 74 |