Passed
Push — master ( 03804a...32a61a )
by Curtis
04:47
created

PersonTable   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 10
dl 0
loc 17
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A query() 0 13 1
1
<?php
2
3
namespace App\Tables\Builders;
4
5
use App\Person;
6
use Illuminate\Database\Eloquent\Builder;
7
use LaravelEnso\Tables\App\Contracts\Table;
8
9
class PersonTable extends \LaravelEnso\People\App\Tables\Builders\PersonTable
10
{
11
    protected const TemplatePath = __DIR__.'/../Templates/people.json';
12
13
    public function query(): Builder
14
    {
15
        return Person::selectRaw('
16
            people.id, people.title, people.givn, people.surn,  people.appellative, people.email, people.phone,
17
            people.birthday, CASE WHEN users.id is null THEN 0 ELSE 1 END as "user",
18
            companies.name as company, people.created_at
19
        ')->leftJoin('users', 'people.id', '=', 'users.person_id')
20
            ->leftJoin(
21
                'company_person',
22
                fn ($join) => $join
23
                    ->on('people.id', '=', 'company_person.person_id')
24
                    ->where('company_person.is_main', true)
25
            )->leftJoin('companies', 'company_person.company_id', 'companies.id');
26
    }
27
28
29
}
30