Conditions | 11 |
Paths | 14 |
Total Lines | 44 |
Code Lines | 18 |
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 |
||
52 | protected function driverConnect(): bool |
||
53 | { |
||
54 | if ($this->instance instanceof RedisClient) { |
||
55 | throw new PhpfastcacheLogicException('Already connected to Redis server'); |
||
56 | } |
||
57 | |||
58 | /** |
||
59 | * In case of an user-provided |
||
60 | * Redis client just return here |
||
61 | */ |
||
62 | if($this->getConfig()->getRedisClient() instanceof RedisClient){ |
||
|
|||
63 | /** |
||
64 | * Unlike Predis, we can't test if we're are connected |
||
65 | * or not, so let's just assume that we are |
||
66 | */ |
||
67 | $this->instance = $this->getConfig()->getRedisClient(); |
||
68 | return true; |
||
69 | } |
||
70 | |||
71 | $this->instance = $this->instance ?: new RedisClient(); |
||
72 | |||
73 | /** |
||
74 | * If path is provided we consider it as an UNIX Socket |
||
75 | */ |
||
76 | if ($this->getConfig()->getPath()) { |
||
77 | $isConnected = $this->instance->connect($this->getConfig()->getPath()); |
||
78 | } else { |
||
79 | $isConnected = $this->instance->connect($this->getConfig()->getHost(), $this->getConfig()->getPort(), $this->getConfig()->getTimeout()); |
||
80 | } |
||
81 | |||
82 | if (!$isConnected && $this->getConfig()->getPath()) { |
||
83 | return false; |
||
84 | } |
||
85 | |||
86 | if (!$this->getConfig()->getPath()) { |
||
87 | if ($this->getConfig()->getPassword() && !$this->instance->auth($this->getConfig()->getPassword())) { |
||
88 | return false; |
||
89 | } |
||
90 | } |
||
91 | |||
92 | if ($this->getConfig()->getDatabase() !== null) { |
||
93 | $this->instance->select($this->getConfig()->getDatabase()); |
||
94 | } |
||
95 | return true; |
||
96 | } |
||
186 | } |