| Conditions | 14 |
| Paths | 21 |
| Total Lines | 39 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 8 | ||
| 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 |
||
| 20 | public function load(array $configs, ContainerBuilder $container) |
||
| 21 | { |
||
| 22 | $configuration = new Configuration(); |
||
| 23 | $config = $this->processConfiguration($configuration, $configs); |
||
| 24 | |||
| 25 | foreach ($config['content_types'] as $name => $contentType) { |
||
| 26 | if (empty($contentType['title'])) { |
||
| 27 | throw new InvalidConfigurationException('Content type ' . $name . ' shoud have a title'); |
||
| 28 | } |
||
| 29 | |||
| 30 | if (empty($contentType['description'])) { |
||
| 31 | @trigger_error('Content type ' . $name . ' shoud have a description', E_USER_WARNING); |
||
|
|
|||
| 32 | } |
||
| 33 | |||
| 34 | if (!isset($contentType['class']) || empty($contentType['class']) || !class_exists($contentType['class'])) { |
||
| 35 | throw new InvalidConfigurationException('CMS ' . $contentType['class'] . ' can\'t be found'); |
||
| 36 | } |
||
| 37 | } |
||
| 38 | $container->setParameter('alpixel_cms.content_types', $config['content_types']); |
||
| 39 | |||
| 40 | foreach ($config['blocks'] as $name => $contentType) { |
||
| 41 | if (empty($contentType['title'])) { |
||
| 42 | throw new InvalidConfigurationException('Block ' . $name . ' shoud have a title'); |
||
| 43 | } |
||
| 44 | |||
| 45 | if ((!isset($contentType['class']) || empty($contentType['class'])) && class_exists($this->_blockDefaultClass)) { |
||
| 46 | $config['blocks'][$name]['class'] = $this->_blockDefaultClass; |
||
| 47 | } |
||
| 48 | |||
| 49 | if (isset($contentType['class']) && !class_exists($contentType['class'])) { |
||
| 50 | throw new InvalidConfigurationException('Block ' . $contentType['class'] . ' can\'t be found'); |
||
| 51 | } |
||
| 52 | } |
||
| 53 | $container->setParameter('alpixel_cms.blocks', $config['blocks']); |
||
| 54 | $container->setParameter('alpixel_cms.exception_template', $config['exception_template']); |
||
| 55 | |||
| 56 | $loader = new Loader\YamlFileLoader($container, new FileLocator(__DIR__ . '/../Resources/config')); |
||
| 57 | $loader->load('services.yml'); |
||
| 58 | } |
||
| 59 | |||
| 81 |
If you suppress an error, we recommend checking for the error condition explicitly: