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