| Conditions | 15 |
| Paths | 12 |
| Total Lines | 49 |
| 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 |
||
| 92 | protected function createAdapter(ContainerInterface $container, string $adapter): AdapterInterface |
||
| 93 | { |
||
| 94 | $config = $this->retrieveAdapterConfig($container, $adapter); |
||
| 95 | |||
| 96 | switch ($adapter) { |
||
| 97 | case 'array': |
||
| 98 | return new ArrayAdapter($config['default_lifetime'], $config['store_serialized']); |
||
| 99 | case 'apcu': |
||
| 100 | // @codeCoverageIgnoreStart |
||
| 101 | return new ApcuAdapter($config['namespace'], $config['default_lifetime'], $config['version']); |
||
| 102 | // @codeCoverageIgnoreEnd |
||
| 103 | case 'filesystem': |
||
| 104 | return new FilesystemAdapter($config['namespace'], $config['default_lifetime'], $config['directory']); |
||
| 105 | case 'redis': |
||
| 106 | // @codeCoverageIgnoreStart |
||
| 107 | $instance = $config['instance']; |
||
| 108 | |||
| 109 | if (\is_string($instance) && $container->has($instance)) { |
||
| 110 | $instance = $container->get($instance); |
||
| 111 | } |
||
| 112 | |||
| 113 | return new RedisAdapter($instance, $config['namespace'], $config['default_lifetime']); |
||
| 114 | // @codeCoverageIgnoreEnd |
||
| 115 | case 'pdo': |
||
| 116 | // @codeCoverageIgnoreStart |
||
| 117 | $instance = $config['instance']; |
||
| 118 | |||
| 119 | if (\is_string($instance) && $container->has($instance)) { |
||
| 120 | $instance = $container->get($instance); |
||
| 121 | } elseif (!$instance instanceof PDO && !$instance instanceof Connection) { |
||
| 122 | $instance = $config['dns']; |
||
| 123 | } |
||
| 124 | |||
| 125 | return new PdoAdapter($instance, $config['namespace'], $config['default_lifetime'], $config['options']); |
||
| 126 | // @codeCoverageIgnoreEnd |
||
| 127 | case 'php_files': |
||
| 128 | return new PhpFilesAdapter($config['namespace'], $config['default_lifetime'], $config['directory']); |
||
| 129 | case 'chain': |
||
| 130 | $adapters = []; |
||
| 131 | |||
| 132 | foreach ($config['adapters'] as $pool) { |
||
| 133 | $adapters[] = $this->createAdapter($container, $pool); |
||
| 134 | } |
||
| 135 | |||
| 136 | return new ChainAdapter($adapters); |
||
| 137 | default: |
||
| 138 | return new NullAdapter(); |
||
| 139 | } |
||
| 140 | } |
||
| 141 | |||
| 162 |