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 |
||
| 34 | trait ClientPoolerTrait |
||
| 35 | { |
||
| 36 | private $session; |
||
| 37 | |||
| 38 | /** |
||
| 39 | * getPoolerType |
||
| 40 | * |
||
| 41 | * @see ClientPoolerInterface |
||
| 42 | */ |
||
| 43 | abstract public function getPoolerType(); |
||
| 44 | |||
| 45 | /** |
||
| 46 | * createClient |
||
| 47 | * |
||
| 48 | * Create a new client. |
||
| 49 | * |
||
| 50 | * @abstract |
||
| 51 | * @access protected |
||
| 52 | * @param string $identifier |
||
| 53 | * @return Client |
||
| 54 | */ |
||
| 55 | abstract protected function createClient($identifier); |
||
| 56 | |||
| 57 | /** |
||
| 58 | * register |
||
| 59 | * |
||
| 60 | * @see ClientPoolerInterface |
||
| 61 | */ |
||
| 62 | public function register(Session $session) |
||
| 68 | |||
| 69 | /** |
||
| 70 | * getClient |
||
| 71 | * |
||
| 72 | * Basic getClient method. |
||
| 73 | * |
||
| 74 | * @access public |
||
| 75 | * @param string $identifier |
||
| 76 | * @return Client |
||
| 77 | * @see ClientInterface |
||
| 78 | */ |
||
| 79 | public function getClient($identifier) |
||
| 90 | |||
| 91 | /** |
||
| 92 | * getClientFromPool |
||
| 93 | * |
||
| 94 | * How the pooler fetch a client from the pool. |
||
| 95 | * |
||
| 96 | * @access protected |
||
| 97 | * @param string $identifier |
||
| 98 | * @return Client|null |
||
| 99 | */ |
||
| 100 | protected function getClientFromPool($identifier) |
||
| 107 | |||
| 108 | /** |
||
| 109 | * getSession |
||
| 110 | * |
||
| 111 | * Check if the session is set and return it. |
||
| 112 | * |
||
| 113 | * @access protected |
||
| 114 | * @return Session |
||
| 115 | * @throws FoundationException |
||
| 116 | */ |
||
| 117 | View Code Duplication | protected function getSession() |
|
| 125 | } |
||
| 126 |