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