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 |
||
| 36 | class LqlBuilder extends LqlAbstract |
||
| 37 | { |
||
| 38 | /** |
||
| 39 | * @var \Kwkm\MkLiveStatusClient\Lql |
||
| 40 | */ |
||
| 41 | private $lql; |
||
| 42 | |||
| 43 | /** |
||
| 44 | * @var \Kwkm\MkLiveStatusClient\Column |
||
| 45 | */ |
||
| 46 | private $column; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * @var \Kwkm\MkLiveStatusClient\Filter |
||
| 50 | */ |
||
| 51 | private $filter; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * @var \Kwkm\MkLiveStatusClient\Stats |
||
| 55 | */ |
||
| 56 | private $stats; |
||
| 57 | |||
| 58 | /** |
||
| 59 | * 初期化 |
||
| 60 | * |
||
| 61 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 62 | */ |
||
| 63 | 17 | public function reset() |
|
| 72 | |||
| 73 | 14 | public function __call($method, $arguments) |
|
| 88 | |||
| 89 | 3 | View Code Duplication | private function callStats($method, $arguments) |
| 102 | |||
| 103 | 13 | View Code Duplication | private function callFilter($method, $arguments) |
| 116 | |||
| 117 | /** |
||
| 118 | * 取得カラムの指定 |
||
| 119 | * |
||
| 120 | * @param string $column |
||
| 121 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 122 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 123 | */ |
||
| 124 | 2 | public function column($column) |
|
| 131 | |||
| 132 | /** |
||
| 133 | * ヘッダ情報を取得するかの設定 |
||
| 134 | * |
||
| 135 | * @param boolean $boolean |
||
| 136 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 137 | * @throw \InvalidArgumentException if the provided argument is not of type 'boolean'. |
||
| 138 | */ |
||
| 139 | public function headers($boolean) |
||
| 145 | |||
| 146 | /** |
||
| 147 | * 取得カラムの一括指定 |
||
| 148 | * |
||
| 149 | * @param array $columns |
||
| 150 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 151 | * @throw \InvalidArgumentException if the provided argument is not of type 'array'. |
||
| 152 | */ |
||
| 153 | 7 | public function columns($columns) |
|
| 160 | |||
| 161 | /** |
||
| 162 | * StatsNegate の指定 |
||
| 163 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 164 | */ |
||
| 165 | public function statsNegate() |
||
| 171 | |||
| 172 | /** |
||
| 173 | * Negate の指定 |
||
| 174 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 175 | */ |
||
| 176 | 1 | public function negate() |
|
| 182 | |||
| 183 | /** |
||
| 184 | * パラメータの指定 |
||
| 185 | * @param string $parameter |
||
| 186 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 187 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 188 | */ |
||
| 189 | public function parameter($parameter) |
||
| 195 | |||
| 196 | /** |
||
| 197 | * OutputFormat の指定 |
||
| 198 | * @param string $outputFormat |
||
| 199 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 200 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 201 | */ |
||
| 202 | public function outputFormat($outputFormat) |
||
| 208 | |||
| 209 | /** |
||
| 210 | * Limit の指定 |
||
| 211 | * @param integer $limit |
||
| 212 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 213 | * @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
||
| 214 | */ |
||
| 215 | public function limit($limit) |
||
| 221 | |||
| 222 | /** |
||
| 223 | * Lqlの実行テキストの作成 |
||
| 224 | * @return string |
||
| 225 | */ |
||
| 226 | 17 | public function build() |
|
| 230 | |||
| 231 | /** |
||
| 232 | * コンストラクタ |
||
| 233 | */ |
||
| 234 | 17 | public function __construct($table, $authUser = null) |
|
| 239 | } |
||
| 240 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.