GeoScope::apply()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 2
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