Conditions | 11 |
Paths | 38 |
Total Lines | 40 |
Code Lines | 27 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
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 /** MicroMemcachedDriver */ |
||
37 | public function __construct(IContainer $container, array $config = []) |
||
38 | { |
||
39 | parent::__construct($container, $config); |
||
40 | |||
41 | if (empty($config['type']) || !$this->check()) { |
||
42 | throw new Exception('Memcache(d) not installed or not select type'); |
||
43 | } |
||
44 | |||
45 | switch (strtolower($config['type'])) { |
||
46 | case 'memcached': |
||
47 | $this->driver = new \Memcached; |
||
48 | break; |
||
49 | |||
50 | case 'memcache': |
||
51 | $this->driver = new \Memcache; |
||
52 | break; |
||
53 | |||
54 | default: |
||
55 | throw new Exception('Selected type not valid in the driver'); |
||
56 | } |
||
57 | |||
58 | if (!empty($config['servers'])) { |
||
59 | $this->driver->addServers($config['servers']); |
||
|
|||
60 | } elseif ($config['server']) { |
||
61 | $conf = $config['server']; |
||
62 | $server = [ |
||
63 | 'hostname' => !empty($conf['hostname']) ? $conf['hostname'] : '127.0.0.1', |
||
64 | 'port' => !empty($conf['port']) ? $conf['port'] : 11211, |
||
65 | 'weight' => !empty($conf['weight']) ? $conf['weight'] : 1 |
||
66 | ]; |
||
67 | |||
68 | if (get_class($this->driver) === 'Memcached') { |
||
69 | $this->driver->addServer($server['hostname'], $server['port'], $server['weight']); |
||
70 | } else { |
||
71 | $this->driver->addServer($server['hostname'], $server['port'], true, $server['weight']); |
||
72 | } |
||
73 | } else { |
||
74 | throw new Exception('Server(s) not configured'); |
||
75 | } |
||
76 | } |
||
77 | |||
183 |
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: