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 |
||
| 18 | class Configuration |
||
| 19 | { |
||
| 20 | const DEFAULT_SETTINGS = 'analyze.yml'; |
||
| 21 | |||
| 22 | const CONFIG_RULES_KEY = 'rules'; |
||
| 23 | |||
| 24 | const CACHE_DIR = '/tmp/cache/smoke/'; |
||
| 25 | |||
| 26 | private $startUri; |
||
| 27 | |||
| 28 | private $rules = []; |
||
| 29 | |||
| 30 | private $configArray; |
||
| 31 | |||
| 32 | private $eventDispatcher; |
||
| 33 | |||
| 34 | private $extensions = array(); |
||
| 35 | |||
| 36 | private $runLevels = array(); |
||
| 37 | |||
| 38 | /** |
||
| 39 | * @var SessionContainer |
||
| 40 | */ |
||
| 41 | private $sessionContainer; |
||
| 42 | |||
| 43 | public function __construct(Uri $uri, Dispatcher $eventDispatcher, array $configArray, array $defaultSettings = null) |
||
| 68 | |||
| 69 | private function initCache() |
||
| 74 | |||
| 75 | private function initLogger($loggerArray) |
||
| 81 | |||
| 82 | private function initConfigArray(array $configArray, array $defaultSettings = null) |
||
| 102 | |||
| 103 | private function initSessionContainer(array $sessionsArray) |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @param array $listenerArray |
||
| 122 | * @throws \phmLabs\Components\Annovent\Exception |
||
| 123 | */ |
||
| 124 | private function addListener(array $listenerArray) |
||
| 132 | |||
| 133 | /** |
||
| 134 | * @return Uri |
||
| 135 | */ |
||
| 136 | public function getStartUri() |
||
| 140 | |||
| 141 | /** |
||
| 142 | * This function initializes all the rules and sets the log level. |
||
| 143 | * |
||
| 144 | * @param array $rulesArray |
||
| 145 | */ |
||
| 146 | private function initRules(array $rulesArray) |
||
| 150 | |||
| 151 | /** |
||
| 152 | * Returns the log level of a given rule. |
||
| 153 | * |
||
| 154 | * @param string $key |
||
| 155 | * |
||
| 156 | * @return int |
||
| 157 | */ |
||
| 158 | public function getRuleRunLevel($key) |
||
| 162 | |||
| 163 | /** |
||
| 164 | * @return Rule[] |
||
| 165 | */ |
||
| 166 | public function getRules() |
||
| 170 | |||
| 171 | public function getSessionContainer() |
||
| 175 | |||
| 176 | public function hasSection($section) |
||
| 180 | |||
| 181 | /** |
||
| 182 | * @param $section |
||
| 183 | * |
||
| 184 | * @return array |
||
| 185 | */ |
||
| 186 | public function getSection($section) |
||
| 194 | |||
| 195 | View Code Duplication | public function getExtension($name) |
|
| 203 | |||
| 204 | /** |
||
| 205 | * @param $name |
||
| 206 | * @param $extension |
||
| 207 | * @throws \phmLabs\Components\Annovent\Exception |
||
| 208 | */ |
||
| 209 | public function addExtension($name, $extension) |
||
| 214 | |||
| 215 | public function getConfigArray() |
||
| 219 | |||
| 220 | /** |
||
| 221 | * @return HttpClient |
||
| 222 | */ |
||
| 223 | public function getClient() |
||
| 240 | } |
||
| 241 |