Conditions | 11 |
Paths | 16 |
Total Lines | 46 |
Code Lines | 19 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
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 |
||
72 | protected function driverConnect(): bool |
||
73 | { |
||
74 | if ($this->instance instanceof RedisClient) { |
||
75 | throw new PhpfastcacheLogicException('Already connected to Redis server'); |
||
76 | } |
||
77 | |||
78 | /** |
||
79 | * In case of an user-provided |
||
80 | * Redis client just return here |
||
81 | */ |
||
82 | if ($this->getConfig()->getRedisClient() instanceof RedisClient) { |
||
|
|||
83 | /** |
||
84 | * Unlike Predis, we can't test if we're are connected |
||
85 | * or not, so let's just assume that we are |
||
86 | */ |
||
87 | $this->instance = $this->getConfig()->getRedisClient(); |
||
88 | return true; |
||
89 | } |
||
90 | |||
91 | $this->instance = $this->instance ?: new RedisClient(); |
||
92 | |||
93 | /** |
||
94 | * If path is provided we consider it as an UNIX Socket |
||
95 | */ |
||
96 | if ($this->getConfig()->getPath()) { |
||
97 | $isConnected = $this->instance->connect($this->getConfig()->getPath()); |
||
98 | } else { |
||
99 | $isConnected = $this->instance->connect($this->getConfig()->getHost(), $this->getConfig()->getPort(), $this->getConfig()->getTimeout()); |
||
100 | } |
||
101 | |||
102 | if (!$isConnected && $this->getConfig()->getPath()) { |
||
103 | return false; |
||
104 | } |
||
105 | |||
106 | if ($this->getConfig()->getOptPrefix()) { |
||
107 | $this->instance->setOption(RedisClient::OPT_PREFIX, $this->getConfig()->getOptPrefix()); |
||
108 | } |
||
109 | |||
110 | if ($this->getConfig()->getPassword() && !$this->instance->auth($this->getConfig()->getPassword())) { |
||
111 | return false; |
||
112 | } |
||
113 | |||
114 | if ($this->getConfig()->getDatabase() !== null) { |
||
115 | $this->instance->select($this->getConfig()->getDatabase()); |
||
116 | } |
||
117 | return true; |
||
118 | } |
||
192 |