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  | 
            ||
| 8 | class SensorDataTable extends DataTable  | 
            ||
| 9 | { | 
            ||
| 10 | /**  | 
            ||
| 11 | * Build DataTable class.  | 
            ||
| 12 | *  | 
            ||
| 13 | * @return \Yajra\DataTables\Engines\BaseEngine  | 
            ||
| 14 | */  | 
            ||
| 15 | public function dataTable($query)  | 
            ||
| 31 | |||
| 32 | /**  | 
            ||
| 33 | * Get the query object to be processed by dataTables.  | 
            ||
| 34 | *  | 
            ||
| 35 | * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Query\Builder|\Illuminate\Support\Collection  | 
            ||
| 36 | */  | 
            ||
| 37 | public function query()  | 
            ||
| 42 | |||
| 43 | /**  | 
            ||
| 44 | * Optional method if you want to use html builder.  | 
            ||
| 45 | *  | 
            ||
| 46 | * @return \Yajra\DataTables\Html\Builder  | 
            ||
| 47 | */  | 
            ||
| 48 | public function html()  | 
            ||
| 55 | |||
| 56 | /**  | 
            ||
| 57 | * Get columns.  | 
            ||
| 58 | *  | 
            ||
| 59 | * @return array  | 
            ||
| 60 | */  | 
            ||
| 61 | View Code Duplication | protected function getColumns()  | 
            |
| 72 | |||
| 73 | /**  | 
            ||
| 74 | * Get builder parameters.  | 
            ||
| 75 | *  | 
            ||
| 76 | * @return array  | 
            ||
| 77 | */  | 
            ||
| 78 | View Code Duplication | protected function getBuilderParameters()  | 
            |
| 96 | |||
| 97 | /**  | 
            ||
| 98 | * Get filename for export.  | 
            ||
| 99 | *  | 
            ||
| 100 | * @return string  | 
            ||
| 101 | */  | 
            ||
| 102 | protected function filename()  | 
            ||
| 106 | }  | 
            ||
| 107 | 
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: