DownloadTable   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 55
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 27
c 1
b 0
f 0
dl 0
loc 55
rs 10
wmc 6

5 Methods

Rating   Name   Duplication   Size   Complexity  
A bulkDelete() 0 3 1
A builder() 0 3 1
A configure() 0 11 1
A reorder() 0 4 2
A columns() 0 19 1
1
<?php
2
3
namespace Adminetic\Website\Http\Livewire\Admin\Download;
4
5
use Adminetic\Website\Models\Admin\Download;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Support\Facades\Blade;
8
use Rappasoft\LaravelLivewireTables\DataTableComponent;
9
use Rappasoft\LaravelLivewireTables\Views\Column;
10
11
class DownloadTable extends DataTableComponent
12
{
13
    public function builder(): Builder
14
    {
15
        return Download::query()->orderBy('position'); // Eager load anything; // Select some things
0 ignored issues
show
Bug Best Practice introduced by
The expression return Adminetic\Website...()->orderBy('position') could return the type Illuminate\Database\Query\Builder which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
16
    }
17
18
    public array $bulkActions = [
19
        'bulkDelete' => 'Bulk Delete',
20
    ];
21
22
    public function bulkDelete()
23
    {
24
        Download::whereIn('id', $this->getSelected())->delete();
25
    }
26
27
    public function configure(): void
28
    {
29
        $this->setPrimaryKey('id');
30
31
        $this->setEagerLoadAllRelationsEnabled();
32
33
        $this->setEmptyMessage('No download found');
34
35
        $this->setReorderStatus(true);
36
37
        $this->setDefaultReorderSort('position', 'asc');
38
    }
39
40
    public function reorder($items): void
41
    {
42
        foreach ($items as $item) {
43
            Download::find((int) $item['value'])->update(['position' => (int) $item['order']]);
44
        }
45
    }
46
47
    public function columns(): array
48
    {
49
        return [
50
            Column::make('ID', 'id')
51
                ->sortable()
52
                ->searchable(),
53
            Column::make('Name', 'name')
54
                ->format(
55
                    fn ($value, $row, Column $column) => '<a href="'.$row->getFirstMediaUrl('file').'" download>'.$row->name.'</a>'
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

55
                    fn ($value, $row, /** @scrutinizer ignore-unused */ Column $column) => '<a href="'.$row->getFirstMediaUrl('file').'" download>'.$row->name.'</a>'

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
56
                )
57
                ->html()
58
                ->sortable()
59
                ->searchable(),
60
            Column::make('Action')
61
                ->label(
62
                    fn ($row, Column $column) => Blade::render('<x-adminetic-action :model="$model" route="download" :show="0" />', ['model' => $row])
0 ignored issues
show
Unused Code introduced by
The parameter $column is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

62
                    fn ($row, /** @scrutinizer ignore-unused */ Column $column) => Blade::render('<x-adminetic-action :model="$model" route="download" :show="0" />', ['model' => $row])

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
63
                )
64
                ->html()
65
                ->collapseOnTablet(),
66
        ];
67
    }
68
}
69