| Conditions | 8 |
| Paths | 9 |
| Total Lines | 54 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 72 |
| 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 |
||
| 51 | public function create($name, array $options = array()) |
||
| 52 | { |
||
| 53 | switch ( $name ) { |
||
| 54 | case 'chain': |
||
| 55 | $valid_caches = array(); |
||
| 56 | |||
| 57 | foreach ( array_filter($options) as $cache_name ) { |
||
| 58 | $valid_caches[] = self::create($cache_name); |
||
| 59 | } |
||
| 60 | |||
| 61 | if ( !$valid_caches ) { |
||
|
1 ignored issue
–
show
|
|||
| 62 | throw new \LogicException('No valid caches provided for "chain" cache.'); |
||
| 63 | } |
||
| 64 | |||
| 65 | $cache_driver = new ChainCache($valid_caches); |
||
| 66 | $cache_driver->setNamespace($this->_namespace); |
||
| 67 | |||
| 68 | return $cache_driver; |
||
| 69 | |||
| 70 | case 'array': |
||
| 71 | $cache_driver = new ArrayCache(); |
||
| 72 | $cache_driver->setNamespace($this->_namespace); |
||
| 73 | |||
| 74 | return $cache_driver; |
||
| 75 | |||
| 76 | case 'apc': |
||
| 77 | $cache_driver = new ApcCache(); |
||
| 78 | $cache_driver->setNamespace($this->_namespace); |
||
| 79 | |||
| 80 | return $cache_driver; |
||
| 81 | |||
| 82 | case 'memcache': |
||
| 83 | $memcache = new \Memcache(); |
||
| 84 | $memcache->connect('localhost', 11211); |
||
| 85 | |||
| 86 | $cache_driver = new MemcacheCache(); |
||
| 87 | $cache_driver->setMemcache($memcache); |
||
| 88 | $cache_driver->setNamespace($this->_namespace); |
||
| 89 | |||
| 90 | return $cache_driver; |
||
| 91 | |||
| 92 | case 'memcached': |
||
| 93 | $memcached = new \Memcached(); |
||
| 94 | $memcached->addServer('memcache_host', 11211); |
||
| 95 | |||
| 96 | $cache_driver = new MemcachedCache(); |
||
| 97 | $cache_driver->setMemcached($memcached); |
||
| 98 | $cache_driver->setNamespace($this->_namespace); |
||
| 99 | |||
| 100 | return $cache_driver; |
||
| 101 | } |
||
| 102 | |||
| 103 | throw new \InvalidArgumentException('Cache provider "' . $name . '" not found.'); |
||
| 104 | } |
||
| 105 | |||
| 107 |
This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.
Consider making the comparison explicit by using
empty(..)or! empty(...)instead.