Issues (364)

app/Tables/Builders/CompanyTable.php (3 issues)

1
<?php
2
3
namespace App\Tables\Builders;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use LaravelEnso\Companies\Models\Company as Model;
7
use LaravelEnso\Tables\Contracts\Table;
8
9
class CompanyTable implements Table
10
{
11
    private const TemplatePath = __DIR__.'/../Templates/companies.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
        $user_id = \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
        $user = \Auth::user();
18
        if (in_array($role, [1, 2])) {
19
            return Model::selectRaw('
20
                companies.id, companies.name,  companies.fiscal_code,  people.name as mandatary,
21
                companies.email, companies.website, companies.bank,  companies.pays_vat,
22
                companies.phone, companies.status, companies.is_tenant, companies.created_at
23
            ')->leftJoin('company_person', fn ($join) => $join
24
                ->on('companies.id', '=', 'company_person.company_id')
25
                ->where('company_person.is_mandatary', true))
26
                ->leftJoin('people', 'company_person.person_id', '=', 'people.id');
27
        }
28
29
        return Model::selectRaw('
30
                companies.id, companies.name,  companies.fiscal_code,  people.name as mandatary,
31
                companies.email, companies.website, companies.bank,  companies.pays_vat,
32
                companies.phone, companies.status, companies.is_tenant, companies.created_at
33
                ')->leftJoin('company_person', fn ($join) => $join
34
            ->on('companies.id', '=', 'company_person.company_id')
35
            ->where('company_person.is_mandatary', true))
36
            ->leftJoin('people', 'company_person.person_id', '=', 'people.id')
37
            ->where('companies.created_by', $user_id)->orWhere('companies.id', '=', $user->company()->id);
0 ignored issues
show
The method company() does not exist on Illuminate\Contracts\Auth\Authenticatable. It seems like you code against a sub-type of Illuminate\Contracts\Auth\Authenticatable such as Illuminate\Foundation\Auth\User. ( Ignorable by Annotation )

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

37
            ->where('companies.created_by', $user_id)->orWhere('companies.id', '=', $user->/** @scrutinizer ignore-call */ company()->id);
Loading history...
38
    }
39
40
    public function templatePath(): string
41
    {
42
        return self::TemplatePath;
43
    }
44
}
45