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 |
||
| 13 | class Configuration |
||
| 14 | { |
||
| 15 | const DEFAULT_SETTINGS = 'analyze.yml'; |
||
| 16 | |||
| 17 | private $startUri; |
||
| 18 | |||
| 19 | private $rules = []; |
||
| 20 | |||
| 21 | private $configArray; |
||
| 22 | |||
| 23 | private $eventDispatcher; |
||
| 24 | |||
| 25 | private $extensions = array(); |
||
| 26 | |||
| 27 | private $runLevels = array(); |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var SessionContainer |
||
| 31 | */ |
||
| 32 | private $sessionContainer; |
||
| 33 | |||
| 34 | public function __construct(Uri $uri, Dispatcher $eventDispatcher, array $configArray, array $defaultSettings = null) |
||
| 58 | |||
| 59 | private function initConfigArray(array $configArray, array $defaultSettings = null) |
||
| 79 | |||
| 80 | private function initSessionContainer(array $sessionsArray) |
||
| 96 | |||
| 97 | private function addListener(array $listenerArray) |
||
| 105 | |||
| 106 | /** |
||
| 107 | * @return Uri |
||
| 108 | */ |
||
| 109 | public function getStartUri() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * This function initializes all the rules and sets the log level. |
||
| 116 | * |
||
| 117 | * @param array $rulesArray |
||
| 118 | */ |
||
| 119 | private function initRules(array $rulesArray) |
||
| 123 | |||
| 124 | /** |
||
| 125 | * Returns the log level of a given rule. |
||
| 126 | * |
||
| 127 | * @param string $key |
||
| 128 | * |
||
| 129 | * @return int |
||
| 130 | */ |
||
| 131 | public function getRuleRunLevel($key) |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return Rule[] |
||
| 138 | */ |
||
| 139 | public function getRules() |
||
| 143 | |||
| 144 | public function getSessionContainer() |
||
| 148 | |||
| 149 | public function hasSection($section) |
||
| 153 | |||
| 154 | /** |
||
| 155 | * @param $section |
||
| 156 | * |
||
| 157 | * @return array |
||
| 158 | */ |
||
| 159 | public function getSection($section) |
||
| 167 | |||
| 168 | View Code Duplication | public function getExtension($name) |
|
| 176 | |||
| 177 | public function addExtension($name, $extension) |
||
| 182 | |||
| 183 | public function getConfigArray() |
||
| 187 | } |
||
| 188 |