| Conditions | 10 |
| Paths | 37 |
| Total Lines | 63 |
| Code Lines | 38 |
| 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 |
||
| 66 | public function load(array $configs, ContainerBuilder $container) |
||
| 67 | { |
||
| 68 | $config = $this->processConfiguration($this->getConfiguration($configs, $container), $configs); |
||
|
|
|||
| 69 | |||
| 70 | $loader = new XmlFileLoader($container, new FileLocator(__DIR__.'/../Resources/config')); |
||
| 71 | $loader->load('services.xml'); |
||
| 72 | |||
| 73 | // metadata |
||
| 74 | if ('none' === $config['metadata']['cache']) { |
||
| 75 | $container->removeAlias('opensoft_simple_serializer.metadata.cache'); |
||
| 76 | } else if ('file' === $config['metadata']['cache']) { |
||
| 77 | $container |
||
| 78 | ->getDefinition('opensoft_simple_serializer.metadata.cache.file') |
||
| 79 | ->replaceArgument(0, $config['metadata']['file_cache']['dir']) |
||
| 80 | ; |
||
| 81 | |||
| 82 | $dir = $container->getParameterBag()->resolveValue($config['metadata']['file_cache']['dir']); |
||
| 83 | if (!file_exists($dir)) { |
||
| 84 | if (!$rs = @mkdir($dir, 0777, true)) { |
||
| 85 | throw new RuntimeException(sprintf('Could not create cache directory "%s".', $dir)); |
||
| 86 | } |
||
| 87 | } |
||
| 88 | } else { |
||
| 89 | $container->setAlias('opensoft_simple_serializer.metadata.cache.file', new Alias($config['metadata']['cache'], false)); |
||
| 90 | } |
||
| 91 | $container |
||
| 92 | ->getDefinition('opensoft_simple_serializer.metadata.factory') |
||
| 93 | ->replaceArgument(2, $config['metadata']['debug']) |
||
| 94 | ; |
||
| 95 | |||
| 96 | |||
| 97 | // directories |
||
| 98 | $directories = array(); |
||
| 99 | $bundles = $container->getParameter('kernel.bundles'); |
||
| 100 | if ($config['metadata']['auto_detection']) { |
||
| 101 | foreach ($bundles as $class) { |
||
| 102 | $ref = new \ReflectionClass($class); |
||
| 103 | |||
| 104 | $directories[$ref->getNamespaceName()] = dirname($ref->getFileName()) . '/Resources/config/simple-serializer'; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | foreach ($config['metadata']['directories'] as $directory) { |
||
| 108 | $directory['path'] = rtrim(str_replace('\\', '/', $directory['path']), '/'); |
||
| 109 | |||
| 110 | if ($directory['path'][0] === '@') { |
||
| 111 | $bundleName = substr($directory['path'], 1, strpos($directory['path'], '/') - 1); |
||
| 112 | |||
| 113 | if (!isset($bundles[$bundleName])) { |
||
| 114 | throw new RuntimeException(sprintf('The bundle "%s" has not been registered with AppKernel. |
||
| 115 | Available bundles: %s', $bundleName, implode(', ', array_keys($bundles)))); |
||
| 116 | } |
||
| 117 | |||
| 118 | $ref = new \ReflectionClass($bundles[$bundleName]); |
||
| 119 | $directory['path'] = dirname($ref->getFileName()) . substr($directory['path'], strlen('@'.$bundleName)); |
||
| 120 | } |
||
| 121 | |||
| 122 | $directories[rtrim($directory['namespace_prefix'], '\\')] = rtrim($directory['path'], '\\/'); |
||
| 123 | } |
||
| 124 | $container |
||
| 125 | ->getDefinition('opensoft_simple_serializer.metadata.driver.file_locator') |
||
| 126 | ->replaceArgument(0, $directories) |
||
| 127 | ; |
||
| 128 | } |
||
| 129 | |||
| 142 |
Unless you are absolutely sure that the expression can never be null because of other conditions, we strongly recommend to add an additional type check to your code: