| Conditions | 12 |
| Paths | 256 |
| Total Lines | 98 |
| Code Lines | 68 |
| 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 |
||
| 99 | public function configureCache(ContainerBuilder $container, $config) |
||
| 100 | { |
||
| 101 | if ($config['default_cache']) { |
||
| 102 | $container->setAlias('sonata.cache', $config['default_cache']); |
||
| 103 | } |
||
| 104 | |||
| 105 | if (isset($config['caches']['esi'])) { |
||
| 106 | $container |
||
| 107 | ->getDefinition('sonata.cache.esi') |
||
| 108 | ->replaceArgument(0, $config['caches']['esi']['token']) |
||
| 109 | ->replaceArgument(1, $config['caches']['esi']['servers']) |
||
| 110 | ->replaceArgument(3, 3 === $config['caches']['esi']['version'] ? 'ban' : 'purge'); |
||
| 111 | } else { |
||
| 112 | $container->removeDefinition('sonata.cache.esi'); |
||
| 113 | } |
||
| 114 | |||
| 115 | if (isset($config['caches']['ssi'])) { |
||
| 116 | $container |
||
| 117 | ->getDefinition('sonata.cache.ssi') |
||
| 118 | ->replaceArgument(0, $config['caches']['ssi']['token']) |
||
| 119 | ; |
||
| 120 | } else { |
||
| 121 | $container->removeDefinition('sonata.cache.ssi'); |
||
| 122 | } |
||
| 123 | |||
| 124 | if (isset($config['caches']['mongo'])) { |
||
| 125 | $this->checkMongo(); |
||
| 126 | |||
| 127 | $database = $config['caches']['mongo']['database']; |
||
| 128 | $servers = []; |
||
| 129 | foreach ($config['caches']['mongo']['servers'] as $server) { |
||
| 130 | if ($server['user']) { |
||
| 131 | $servers[] = sprintf('%s:%s@%s:%s/%s', $server['user'], $server['password'], $server['host'], $server['port'], $database); |
||
| 132 | } else { |
||
| 133 | $servers[] = sprintf('%s:%s', $server['host'], $server['port']); |
||
| 134 | } |
||
| 135 | } |
||
| 136 | |||
| 137 | $container |
||
| 138 | ->getDefinition('sonata.cache.mongo') |
||
| 139 | ->replaceArgument(0, $servers) |
||
| 140 | ->replaceArgument(1, $database) |
||
| 141 | ->replaceArgument(2, $config['caches']['mongo']['collection']) |
||
| 142 | ; |
||
| 143 | } else { |
||
| 144 | $container->removeDefinition('sonata.cache.mongo'); |
||
| 145 | } |
||
| 146 | |||
| 147 | if (isset($config['caches']['memcached'])) { |
||
| 148 | $this->checkMemcached(); |
||
| 149 | |||
| 150 | $container |
||
| 151 | ->getDefinition('sonata.cache.memcached') |
||
| 152 | ->replaceArgument(0, $config['caches']['memcached']['prefix']) |
||
| 153 | ->replaceArgument(1, $config['caches']['memcached']['servers']) |
||
| 154 | ; |
||
| 155 | } else { |
||
| 156 | $container->removeDefinition('sonata.cache.memcached'); |
||
| 157 | } |
||
| 158 | |||
| 159 | if (isset($config['caches']['predis'])) { |
||
| 160 | $this->checkPRedis(); |
||
| 161 | |||
| 162 | $container |
||
| 163 | ->getDefinition('sonata.cache.predis') |
||
| 164 | ->replaceArgument(0, $config['caches']['predis']['servers']) |
||
| 165 | ; |
||
| 166 | } else { |
||
| 167 | $container->removeDefinition('sonata.cache.predis'); |
||
| 168 | } |
||
| 169 | |||
| 170 | if (isset($config['caches']['apc'])) { |
||
| 171 | $this->checkApc(); |
||
| 172 | |||
| 173 | $container |
||
| 174 | ->getDefinition('sonata.cache.apc') |
||
| 175 | ->replaceArgument(1, $config['caches']['apc']['token']) |
||
| 176 | ->replaceArgument(2, $config['caches']['apc']['prefix']) |
||
| 177 | ->replaceArgument(3, $this->configureServers($config['caches']['apc']['servers'])) |
||
| 178 | ->replaceArgument(4, $config['caches']['apc']['timeout']) |
||
| 179 | ; |
||
| 180 | } else { |
||
| 181 | $container->removeDefinition('sonata.cache.apc'); |
||
| 182 | } |
||
| 183 | |||
| 184 | if (isset($config['caches']['symfony'])) { |
||
| 185 | $container |
||
| 186 | ->getDefinition('sonata.cache.symfony') |
||
| 187 | ->replaceArgument(3, $config['caches']['symfony']['token']) |
||
| 188 | ->replaceArgument(4, $config['caches']['symfony']['php_cache_enabled']) |
||
| 189 | ->replaceArgument(5, $config['caches']['symfony']['types']) |
||
| 190 | ->replaceArgument(6, $this->configureServers($config['caches']['symfony']['servers'])) |
||
| 191 | ->replaceArgument(7, $config['caches']['symfony']['timeout']) |
||
| 192 | ; |
||
| 193 | } else { |
||
| 194 | $container->removeDefinition('sonata.cache.symfony'); |
||
| 195 | } |
||
| 196 | } |
||
| 197 | |||
| 339 |