Passed
Push — master ( b8147c...403ced )
by Curtis
11:47 queued 05:39
created

CompanyTableIndi::query()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 12
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 7
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 12
rs 10
1
<?php
2
3
namespace App\Tables\Builders\enso\Companies;
4
5
use Illuminate\Database\Eloquent\Builder;
6
use LaravelEnso\Companies\Models\Company;
7
use LaravelEnso\Tables\Contracts\Table;
8
use Auth;
9
10
class CompanyTableIndi implements Table
11
{
12
    protected const TemplatePath = __DIR__.'/../../../Templates/enso/company/companies.json';
13
14
    public function query(): Builder
15
    {
16
        return Company::selectRaw('
17
            companies.id, companies.name,  companies.fiscal_code,  people.name as mandatary,
18
            companies.email, companies.website, companies.bank,  companies.pays_vat, 
19
            companies.phone,  companies.status, companies.is_tenant, companies.created_at
20
        ')->leftJoin(
21
            'company_person',
22
            fn ($join) => $join
23
                ->on('companies.id', '=', 'company_person.company_id')
24
        )->leftJoin('people', 'company_person.person_id', '=', 'people.id')
25
        ->where('company_person.person_id', Auth::user()->person_id);
0 ignored issues
show
Bug introduced by
Accessing person_id on the interface Illuminate\Contracts\Auth\Authenticatable suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
26
    }
27
28
    public function templatePath(): string
29
    {
30
        return static::TemplatePath;
31
    }
32
}
33