Conditions | 16 |
Paths | 11296 |
Total Lines | 47 |
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 createClientWithSentinel(array $options) |
||
93 | { |
||
94 | $servers = $this->servers; |
||
95 | $timeout = isset($options['sentinel_timeout']) ? $options['sentinel_timeout'] : 0; |
||
96 | $persistent = isset($options['sentinel_peristent']) ? $options['sentinel_peristent'] : null; |
||
97 | $retryWait = isset($options['retry_wait']) ? $options['retry_wait'] : 0; |
||
98 | $readTimeout = isset($options['sentinel_read_timeout']) ? $options['sentinel_read_timeout'] : 0; |
||
99 | $parameters = isset($options['parameters']) ? $options['parameters'] : []; |
||
100 | |||
101 | // Shuffle the servers to perform some loadbalancing. |
||
102 | shuffle($servers); |
||
103 | |||
104 | // Try to connect to any of the servers. |
||
105 | foreach ($servers as $idx => $server) { |
||
106 | $host = isset($server['host']) ? $server['host'] : 'localhost'; |
||
107 | $port = isset($server['port']) ? $server['port'] : 26739; |
||
108 | $service = isset($options['service']) ? $options['service'] : 'mymaster'; |
||
109 | |||
110 | // Create a connection to the Sentinel instance. |
||
111 | $sentinel = new RedisSentinel($host, $port, $timeout, $persistent, $retryWait, $readTimeout); |
||
112 | |||
113 | try { |
||
114 | // Check if the Sentinel server list needs to be updated. |
||
115 | // Put the current server and the other sentinels in the server list. |
||
116 | $updateSentinels = isset($options['update_sentinels']) ? $options['update_sentinels'] : false; |
||
117 | if ($updateSentinels === true) { |
||
118 | $this->updateSentinels($sentinel, $host, $port, $service); |
||
119 | } |
||
120 | |||
121 | // Lookup the master node. |
||
122 | $master = $sentinel->getMasterAddrByName($service); |
||
123 | if (is_array($master) && ! count($master)) { |
||
124 | throw new RedisException(sprintf('No master found for service "%s".', $service)); |
||
125 | } |
||
126 | |||
127 | // Create a PhpRedis client for the selected master node. |
||
128 | return $this->createClient( |
||
129 | array_merge($parameters, $server, ['host' => $master[0], 'port' => $master[1]]) |
||
130 | ); |
||
131 | } catch (RedisException $e) { |
||
132 | // Rethrow the expection when the last server is reached. |
||
133 | if ($idx === count($servers) - 1) { |
||
134 | throw $e; |
||
135 | } |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | |||
192 |
This check looks for PHPDoc comments describing methods or function parameters that do not exist on the corresponding method or function. It has, however, found a similar but not annotated parameter which might be a good fit.
Consider the following example. The parameter
$ireland
is not defined by the methodfinale(...)
.The most likely cause is that the parameter was changed, but the annotation was not.