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 |
||
| 14 | class Builder |
||
| 15 | { |
||
| 16 | use Macroable; |
||
| 17 | use HasOptions; |
||
| 18 | use HasTable; |
||
| 19 | use HasEditor; |
||
| 20 | use Columns\Index; |
||
| 21 | use Columns\Action; |
||
| 22 | use Columns\Checkbox; |
||
| 23 | |||
| 24 | // Select plugin constants. |
||
| 25 | const SELECT_STYLE_API = 'api'; |
||
| 26 | const SELECT_STYLE_SINGLE = 'single'; |
||
| 27 | const SELECT_STYLE_MULTI = 'multi'; |
||
| 28 | const SELECT_STYLE_OS = 'os'; |
||
| 29 | const SELECT_STYLE_MULTI_SHIFT = 'multi+shift'; |
||
| 30 | const SELECT_ITEMS_ROW = 'row'; |
||
| 31 | const SELECT_ITEMS_COLUMN = 'column'; |
||
| 32 | const SELECT_ITEMS_CELL = 'cell'; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var Collection |
||
| 36 | */ |
||
| 37 | public $collection; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var Repository |
||
| 41 | */ |
||
| 42 | public $config; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var Factory |
||
| 46 | */ |
||
| 47 | public $view; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var HtmlBuilder |
||
| 51 | */ |
||
| 52 | public $html; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @var array |
||
| 56 | */ |
||
| 57 | protected $tableAttributes = []; |
||
| 58 | |||
| 59 | /** |
||
| 60 | * @var string |
||
| 61 | */ |
||
| 62 | protected $template = ''; |
||
| 63 | |||
| 64 | /** |
||
| 65 | * @var array |
||
| 66 | */ |
||
| 67 | protected $attributes = []; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @param Repository $config |
||
| 71 | * @param Factory $view |
||
| 72 | * @param HtmlBuilder $html |
||
| 73 | */ |
||
| 74 | public function __construct(Repository $config, Factory $view, HtmlBuilder $html) |
||
| 82 | |||
| 83 | /** |
||
| 84 | * Generate DataTable javascript. |
||
| 85 | * |
||
| 86 | * @param null $script |
||
| 87 | * @param array $attributes |
||
| 88 | * @return \Illuminate\Support\HtmlString |
||
| 89 | * @throws \Exception |
||
| 90 | */ |
||
| 91 | public function scripts($script = null, array $attributes = ['type' => 'text/javascript']) |
||
| 98 | |||
| 99 | /** |
||
| 100 | * Get generated raw scripts. |
||
| 101 | * |
||
| 102 | * @return \Illuminate\Support\HtmlString |
||
| 103 | * @throws \Exception |
||
| 104 | */ |
||
| 105 | public function generateScripts() |
||
| 113 | |||
| 114 | /** |
||
| 115 | * Get generated json configuration. |
||
| 116 | * |
||
| 117 | * @return string |
||
| 118 | */ |
||
| 119 | public function generateJson() |
||
| 135 | |||
| 136 | /** |
||
| 137 | * Generate DataTables js parameters. |
||
| 138 | * |
||
| 139 | * @param array $attributes |
||
| 140 | * @return string |
||
| 141 | */ |
||
| 142 | public function parameterize($attributes = []) |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Check if given key & value is a valid callback js function. |
||
| 171 | * |
||
| 172 | * @param string $value |
||
| 173 | * @param string $key |
||
| 174 | * @return bool |
||
| 175 | */ |
||
| 176 | protected function isCallbackFunction($value, $key) |
||
| 186 | |||
| 187 | /** |
||
| 188 | * Get javascript template to use. |
||
| 189 | * |
||
| 190 | * @return string |
||
| 191 | */ |
||
| 192 | protected function template() |
||
| 198 | |||
| 199 | /** |
||
| 200 | * Generate DataTable's table html. |
||
| 201 | * |
||
| 202 | * @param array $attributes |
||
| 203 | * @param bool $drawFooter |
||
| 204 | * @param bool $drawSearch |
||
| 205 | * @return \Illuminate\Support\HtmlString |
||
| 206 | */ |
||
| 207 | public function table(array $attributes = [], $drawFooter = false, $drawSearch = false) |
||
| 226 | |||
| 227 | /** |
||
| 228 | * Configure DataTable's parameters. |
||
| 229 | * |
||
| 230 | * @param array $attributes |
||
| 231 | * @return $this |
||
| 232 | */ |
||
| 233 | public function parameters(array $attributes = []) |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Set custom javascript template. |
||
| 242 | * |
||
| 243 | * @param string $template |
||
| 244 | * @return $this |
||
| 245 | */ |
||
| 246 | public function setTemplate($template) |
||
| 252 | |||
| 253 | /** |
||
| 254 | * Make a data script to be appended on ajax request of dataTables. |
||
| 255 | * |
||
| 256 | * @param array $data |
||
| 257 | * @return string |
||
| 258 | */ |
||
| 259 | protected function makeDataScript(array $data) |
||
| 269 | |||
| 270 | /** |
||
| 271 | * Generate scripts that sets the dataTables options into a variable. |
||
| 272 | * |
||
| 273 | * @return $this |
||
| 274 | */ |
||
| 275 | public function asOptions() |
||
| 279 | |||
| 280 | /** |
||
| 281 | * Wrap dataTable scripts with a function. |
||
| 282 | * |
||
| 283 | * @return $this |
||
| 284 | */ |
||
| 285 | public function asFunction() |
||
| 289 | } |
||
| 290 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..