Issues (364)

app/Tables/Builders/DnaTable.php (4 issues)

1
<?php
2
3
namespace App\Tables\Builders;
4
5
use App\Models\Dna;
6
use Illuminate\Database\Eloquent\Builder;
7
use LaravelEnso\Tables\Contracts\Table;
8
9
class DnaTable implements Table
10
{
11
    protected const TemplatePath = __DIR__.'/../Templates/dna.json';
12
13
    public function query(): Builder
14
    {
15
        $role = \Auth::user()->role_id;
0 ignored issues
show
Accessing role_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
16
        $userId = \Auth::user()->id;
0 ignored issues
show
Accessing id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
17
18
        if (in_array($role, [1, 2])) {
19
            return Dna::selectRaw('
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Dna::s...s.created_at ') could return the type Illuminate\Database\Eloq...gHasThroughRelationship which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
20
            dnas.id, dnas.name, dnas.file_name, dnas.variable_name, dnas.created_at
21
        ');
22
        }
23
24
        return Dna::selectRaw('
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Models\Dna::s...dnas.user_id', $userId) could return the type Illuminate\Database\Eloq...Relations\HasOneThrough which is incompatible with the type-hinted return Illuminate\Database\Eloquent\Builder. Consider adding an additional type-check to rule them out.
Loading history...
25
            dnas.id, dnas.name, dnas.file_name, dnas.variable_name, dnas.created_at, dnas.user_id
26
        ')->where('dnas.user_id', $userId);
27
    }
28
29
    public function templatePath(): string
30
    {
31
        return static::TemplatePath;
32
    }
33
}
34