ActiveableScope   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 17
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

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

1 Method

Rating   Name   Duplication   Size   Complexity  
A apply() 0 11 1
1
<?php
2
3
4
namespace Alish\ActiveableModel\Scopes;
5
6
use Alish\ActiveableModel\Models\ActiveableModel;
7
use Illuminate\Database\Eloquent\Builder;
8
use Illuminate\Database\Eloquent\Model;
9
use Illuminate\Database\Eloquent\Scope;
10
11
class ActiveableScope implements Scope
12
{
13
14
    public function apply(Builder $builder, Model $model)
15
    {
16
        $builder->addSelect([
17
            'is_active' => ActiveableModel::select('is_active')
18
                ->whereColumn('object_id', $model->getTable() . ".id")
19
                ->where('object_type', get_class($model))
20
                ->latest('created_at')
21
                ->latest('id')
22
                ->limit(1)
23
        ]);
24
    }
25
26
27
}
28