CraftLogan /
Laravel-Overflow
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
| 1 | <?php |
||
| 2 | |||
| 3 | namespace CraftLogan\LaravelOverflow; |
||
| 4 | use Illuminate\Support\Facades\Schema; |
||
| 5 | |||
| 6 | View Code Duplication | trait Overflowable{ |
|
|
0 ignored issues
–
show
This class seems to be duplicated in your project.
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. Loading history...
|
|||
| 7 | |||
| 8 | public function allWithOverflow() |
||
| 9 | { |
||
| 10 | $properties[$this->overflow_column] = $this->overflow(); |
||
| 11 | return array_merge($properties, $this->getColumns()); |
||
| 12 | } |
||
| 13 | |||
| 14 | public function getColumns() |
||
| 15 | { |
||
| 16 | $columnNames = $this->getTableColumns(); |
||
| 17 | $columnNames = array_fill_keys($columnNames, ""); |
||
| 18 | $attributes = array_intersect_key($this->all(), $columnNames); |
||
| 19 | return $attributes; |
||
| 20 | } |
||
| 21 | |||
| 22 | public function overflow() |
||
| 23 | { |
||
| 24 | $columnNames = $this->getTableColumns(); |
||
| 25 | $columnNames = array_fill_keys($columnNames, ""); |
||
| 26 | $attributes = array_diff_key($this->all(), $columnNames); |
||
| 27 | $attributes = json_encode($attributes); |
||
| 28 | return $attributes; |
||
| 29 | } |
||
| 30 | |||
| 31 | public function getTableColumns() |
||
| 32 | { |
||
| 33 | return Schema::getColumnListing($this->table); |
||
| 34 | } |
||
| 35 | } |
||
| 36 |
This check looks for classes that have been defined more than once.
If you can, we would recommend to use standard object-oriented programming techniques. For example, to avoid multiple types, it might make sense to create a common interface, and then multiple, different implementations for that interface.
This also has the side-effect of providing you with better IDE auto-completion, static analysis and also better OPCode caching from PHP.