GeoScope   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 3
dl 0
loc 24
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A apply() 0 4 1
A extend() 0 16 3
1
<?php
2
3
namespace Leitom\Geo;
4
5
use Leitom\Geo\Events\ModelsRemoved;
6
use Leitom\Geo\Events\ModelsImported;
7
use Illuminate\Database\Eloquent\Model;
8
use Illuminate\Database\Eloquent\Scope;
9
use Illuminate\Database\Eloquent\Builder as EloquentBuilder;
10
11
class GeoScope implements Scope
12
{
13
    public function apply(EloquentBuilder $builder, Model $model)
14
    {
15
        //
16
    }
17
18
    public function extend(EloquentBuilder $builder)
19
    {
20
        $builder->macro('addGeo', function (EloquentBuilder $builder, $chunk = null) {
21
            $builder->chunk($chunk ?: config('geo.chunk', 500), function ($models) {
22
                $models->filter->geoEnabled()->addGeo();
23
                event(new ModelsImported($models));
24
            });
25
        });
26
27
        $builder->macro('removeGeo', function (EloquentBuilder $builder, $chunk = null) {
28
            $builder->chunk($chunk ?: config('geo.chunk', 500), function ($models) {
29
                $models->removeGeo();
30
                event(new ModelsRemoved($models));
31
            });
32
        });
33
    }
34
}
35