RivetTypeScope   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
c 2
b 0
f 0
lcom 1
cbo 2
dl 0
loc 27
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A apply() 0 4 1
A remove() 0 12 3
1
<?php
2
3
namespace Luminark\Rivet\Models\Scopes;
4
5
use Illuminate\Database\Eloquent\ScopeInterface;
6
use Illuminate\Database\Eloquent\Builder;
7
use Illuminate\Database\Eloquent\Model;
8
9
class RivetTypeScope implements ScopeInterface
10
{
11
    protected $type;
12
13
    public function __construct($type)
14
    {
15
        $this->type = $type;
16
    }
17
18
    public function apply(Builder $builder, Model $model)
19
    {
20
        $builder->where('type', $this->type);
21
    }
22
23
    public function remove(Builder $builder, Model $model)
24
    {
25
        $query = $builder->getQuery();
26
27
        foreach ((array) $query->wheres as $key => $where) {
28
            if ($key == 'type') {
29
                unset($query->wheres[$key]);
30
            }
31
        }
32
33
        $query->wheres = array_values($query->wheres);
34
    }
35
}
36