Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
1 | <?php |
||
31 | class Driver implements ExtendedCacheItemPoolInterface |
||
32 | { |
||
33 | use DriverBaseTrait, MemcacheDriverCollisionDetectorTrait; |
||
34 | |||
35 | /** |
||
36 | * Driver constructor. |
||
37 | * @param array $config |
||
38 | * @throws phpFastCacheDriverException |
||
39 | */ |
||
40 | View Code Duplication | public function __construct(array $config = []) |
|
52 | |||
53 | /** |
||
54 | * @return bool |
||
55 | */ |
||
56 | public function driverCheck() |
||
60 | |||
61 | /** |
||
62 | * @param \Psr\Cache\CacheItemInterface $item |
||
63 | * @return mixed |
||
64 | * @throws phpFastCacheInvalidArgumentException |
||
65 | */ |
||
66 | protected function driverWrite(CacheItemInterface $item) |
||
85 | |||
86 | /** |
||
87 | * @param \Psr\Cache\CacheItemInterface $item |
||
88 | * @return mixed |
||
89 | */ |
||
90 | View Code Duplication | protected function driverRead(CacheItemInterface $item) |
|
100 | |||
101 | /** |
||
102 | * @param \Psr\Cache\CacheItemInterface $item |
||
103 | * @return bool |
||
104 | * @throws phpFastCacheInvalidArgumentException |
||
105 | */ |
||
106 | protected function driverDelete(CacheItemInterface $item) |
||
117 | |||
118 | /** |
||
119 | * @return bool |
||
120 | */ |
||
121 | protected function driverClear() |
||
125 | |||
126 | /** |
||
127 | * @return bool |
||
128 | */ |
||
129 | View Code Duplication | protected function driverConnect() |
|
130 | { |
||
131 | $servers = (!empty($this->config[ 'servers' ]) && is_array($this->config[ 'servers' ]) ? $this->config[ 'servers' ] : []); |
||
132 | if (count($servers) < 1) { |
||
133 | $servers = [ |
||
134 | [ |
||
135 | 'host' =>'127.0.0.1', |
||
136 | 'port' => 11211, |
||
137 | 'sasl_user' => false, |
||
138 | 'sasl_password' => false |
||
139 | ], |
||
140 | ]; |
||
141 | } |
||
142 | |||
143 | foreach ($servers as $server) { |
||
144 | try { |
||
145 | if (!$this->instance->addServer($server['host'], $server['port'])) { |
||
146 | $this->fallback = true; |
||
147 | } |
||
148 | if(!empty($server[ 'sasl_user' ]) && !empty($server[ 'sasl_password'])){ |
||
149 | $this->instance->setSaslAuthData($server[ 'sasl_user' ], $server[ 'sasl_password']); |
||
150 | } |
||
151 | } catch (\Exception $e) { |
||
152 | $this->fallback = true; |
||
153 | } |
||
154 | } |
||
155 | } |
||
156 | |||
157 | /******************** |
||
158 | * |
||
159 | * PSR-6 Extended Methods |
||
160 | * |
||
161 | *******************/ |
||
162 | |||
163 | /** |
||
164 | * @return driverStatistic |
||
165 | */ |
||
166 | View Code Duplication | public function getStats() |
|
181 | } |