Passed
Push — master ( 4d2cf8...c611fa )
by Curtis
07:03
created

PersonTable::templatePath()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace App\Tables\Builders;
4
5
use App\Person;
6
use App\Traits\ConnectionTrait;
7
use Illuminate\Database\Eloquent\Builder;
8
use LaravelEnso\Tables\Contracts\Table;
9
10
11
class PersonTable extends \LaravelEnso\People\Tables\Builders\PersonTable
12
{
13
    use ConnectionTrait;
14
15
    protected const TemplatePath = __DIR__.'/../Templates/people.json';
16
17
    public function query(): Builder
18
    {
19
        $conn = $this->getConnection();
20
        $db = $this->getDB();
0 ignored issues
show
Unused Code introduced by
The assignment to $db is dead and can be removed.
Loading history...
21
22
        return Person::on($conn)->selectRaw('
0 ignored issues
show
Bug Best Practice introduced by
The expression return App\Person::on($c...ny_id', 'companies.id') 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...
23
            people.id
24
            , people.title, people.givn, people.surn,  people.appellative, people.email, people.phone,
25
            people.birthday, people.deathday, CASE WHEN users.id is null THEN 0 ELSE 1 END as "user",
26
            companies.name as company, people.created_at
27
        ')->leftJoin('users', 'people.id', '=', 'users.person_id')
28
            ->leftJoin(
29
                'company_person',
30
                fn ($join) => $join
31
                    ->on('people.id', '=', 'company_person.person_id')
32
                    ->where('company_person.is_main', true)
33
            )->leftJoin('companies', 'company_person.company_id', 'companies.id');
34
    }
35
36
    public function templatePath(): string
37
    {
38
        return static::TemplatePath;
39
    }
40
41
}
42