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