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 |
||
| 12 | class LqlBuilder extends LqlAbstract |
||
| 13 | { |
||
| 14 | /** |
||
| 15 | * @var \Kwkm\MkLiveStatusClient\LqlObject |
||
| 16 | */ |
||
| 17 | private $lqlObject; |
||
| 18 | |||
| 19 | /** |
||
| 20 | * @var string |
||
| 21 | */ |
||
| 22 | private $table; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var string |
||
| 26 | */ |
||
| 27 | private $authUser; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * 初期化 |
||
| 31 | * |
||
| 32 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 33 | */ |
||
| 34 | 5 | View Code Duplication | public function reset() |
|
|
|||
| 35 | { |
||
| 36 | 5 | $this->lqlObject = new LqlObject(); |
|
| 37 | 5 | $this->lqlObject->setTable($this->table); |
|
| 38 | 5 | if (!is_null($this->authUser)) { |
|
| 39 | 1 | $this->lqlObject->setAuthUser($this->authUser); |
|
| 40 | 1 | } |
|
| 41 | |||
| 42 | 5 | return $this; |
|
| 43 | } |
||
| 44 | |||
| 45 | /** |
||
| 46 | * 取得カラムの指定 |
||
| 47 | * |
||
| 48 | * @param string $column |
||
| 49 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 50 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 51 | */ |
||
| 52 | 1 | public function column($column) |
|
| 53 | { |
||
| 54 | 1 | $this->lqlObject->appendColumns($column); |
|
| 55 | |||
| 56 | 1 | return $this; |
|
| 57 | } |
||
| 58 | |||
| 59 | /** |
||
| 60 | * ヘッダ情報を取得するかの設定 |
||
| 61 | * |
||
| 62 | * @param boolean $boolean |
||
| 63 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 64 | * @throw \InvalidArgumentException if the provided argument is not of type 'boolean'. |
||
| 65 | */ |
||
| 66 | public function headers($boolean) |
||
| 72 | |||
| 73 | /** |
||
| 74 | * 取得カラムの一括指定 |
||
| 75 | * |
||
| 76 | * @param array $columns |
||
| 77 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 78 | * @throw \InvalidArgumentException if the provided argument is not of type 'array'. |
||
| 79 | */ |
||
| 80 | 3 | public function columns($columns) |
|
| 86 | |||
| 87 | /** |
||
| 88 | * 任意のフィルタ設定 |
||
| 89 | * |
||
| 90 | * @param string $filter |
||
| 91 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 92 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 93 | */ |
||
| 94 | 2 | public function filter($filter) |
|
| 100 | |||
| 101 | /** |
||
| 102 | * column = value のフィルタ設定 |
||
| 103 | * |
||
| 104 | * @param string $column カラム名 |
||
| 105 | * @param string $value フィルタする値 |
||
| 106 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 107 | */ |
||
| 108 | 2 | public function filterEqual($column, $value) |
|
| 114 | |||
| 115 | /** |
||
| 116 | * column ~ value のフィルタ設定 |
||
| 117 | * |
||
| 118 | * @param string $column カラム名 |
||
| 119 | * @param string $value フィルタする値 |
||
| 120 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 121 | */ |
||
| 122 | public function filterMatch($column, $value) |
||
| 128 | |||
| 129 | /** |
||
| 130 | * column != value のフィルタ設定 |
||
| 131 | * |
||
| 132 | * @param string $column カラム名 |
||
| 133 | * @param string $value フィルタする値 |
||
| 134 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 135 | */ |
||
| 136 | public function filterNotEqual($column, $value) |
||
| 142 | |||
| 143 | /** |
||
| 144 | * column !~ value のフィルタ設定 |
||
| 145 | * |
||
| 146 | * @param string $column カラム名 |
||
| 147 | * @param string $value フィルタする値 |
||
| 148 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 149 | */ |
||
| 150 | public function filterNotMatch($column, $value) |
||
| 156 | |||
| 157 | /** |
||
| 158 | * column < value のフィルタ設定 |
||
| 159 | * |
||
| 160 | * @param string $column カラム名 |
||
| 161 | * @param string $value フィルタする値 |
||
| 162 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 163 | */ |
||
| 164 | public function filterLess($column, $value) |
||
| 170 | |||
| 171 | /** |
||
| 172 | * column > value のフィルタ設定 |
||
| 173 | * |
||
| 174 | * @param string $column カラム名 |
||
| 175 | * @param string $value フィルタする値 |
||
| 176 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 177 | */ |
||
| 178 | public function filterGreater($column, $value) |
||
| 184 | |||
| 185 | /** |
||
| 186 | * column <= value のフィルタ設定 |
||
| 187 | * |
||
| 188 | * @param string $column カラム名 |
||
| 189 | * @param string $value フィルタする値 |
||
| 190 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 191 | */ |
||
| 192 | public function filterLessEqual($column, $value) |
||
| 198 | |||
| 199 | /** |
||
| 200 | * column >= value のフィルタ設定 |
||
| 201 | * |
||
| 202 | * @param string $column カラム名 |
||
| 203 | * @param string $value フィルタする値 |
||
| 204 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 205 | */ |
||
| 206 | public function filterGreaterEqual($column, $value) |
||
| 212 | |||
| 213 | /** |
||
| 214 | * Stats の指定 |
||
| 215 | * @param string $stats |
||
| 216 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 217 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 218 | */ |
||
| 219 | public function stats($stats) |
||
| 225 | |||
| 226 | /** |
||
| 227 | * column = value のStats設定 |
||
| 228 | * |
||
| 229 | * @param string $column カラム名 |
||
| 230 | * @param string $value フィルタする値 |
||
| 231 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 232 | */ |
||
| 233 | public function statsEqual($column, $value) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * column != value のStats設定 |
||
| 242 | * |
||
| 243 | * @param string $column カラム名 |
||
| 244 | * @param string $value フィルタする値 |
||
| 245 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 246 | */ |
||
| 247 | public function statsNotEqual($column, $value) |
||
| 253 | |||
| 254 | /** |
||
| 255 | * StatsAnd の指定 |
||
| 256 | * @param integer $statsAnd |
||
| 257 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 258 | * @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
||
| 259 | */ |
||
| 260 | public function statsAnd($statsAnd) |
||
| 266 | |||
| 267 | /** |
||
| 268 | * StatsNegate の指定 |
||
| 269 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 270 | */ |
||
| 271 | public function statsNegate() |
||
| 277 | |||
| 278 | /** |
||
| 279 | * Or の指定 |
||
| 280 | * @param integer $or |
||
| 281 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 282 | * @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
||
| 283 | */ |
||
| 284 | public function filterOr($or) |
||
| 290 | |||
| 291 | /** |
||
| 292 | * And の指定 |
||
| 293 | * @param integer $and |
||
| 294 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 295 | * @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
||
| 296 | */ |
||
| 297 | public function filterAnd($and) |
||
| 303 | |||
| 304 | /** |
||
| 305 | * Negate の指定 |
||
| 306 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 307 | */ |
||
| 308 | public function negate() |
||
| 314 | |||
| 315 | /** |
||
| 316 | * パラメータの指定 |
||
| 317 | * @param string $parameter |
||
| 318 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 319 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 320 | */ |
||
| 321 | public function parameter($parameter) |
||
| 327 | |||
| 328 | /** |
||
| 329 | * OutputFormat の指定 |
||
| 330 | * @param string $outputFormat |
||
| 331 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 332 | * @throw \InvalidArgumentException if the provided argument is not of type 'string'. |
||
| 333 | */ |
||
| 334 | public function outputFormat($outputFormat) |
||
| 340 | |||
| 341 | /** |
||
| 342 | * Limit の指定 |
||
| 343 | * @param integer $limit |
||
| 344 | * @return \Kwkm\MkLiveStatusClient\LqlBuilder |
||
| 345 | * @throw \InvalidArgumentException if the provided argument is not of type 'integer'. |
||
| 346 | */ |
||
| 347 | public function limit($limit) |
||
| 353 | |||
| 354 | /** |
||
| 355 | * Lqlの実行テキストの作成 |
||
| 356 | * @return string |
||
| 357 | */ |
||
| 358 | 5 | public function build() |
|
| 362 | |||
| 363 | /** |
||
| 364 | * コンストラクタ |
||
| 365 | */ |
||
| 366 | 5 | public function __construct($table, $authUser = null) |
|
| 372 | } |
||
| 373 |
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.