Base::scopePeriod()   A
last analyzed

Complexity

Conditions 4
Paths 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 10
c 0
b 0
f 0
cc 4
nc 2
nop 3
1
<?php
2
3
namespace PragmaRX\Tracker\Vendor\Laravel\Models;
4
5
use Illuminate\Database\Eloquent\Model as Eloquent;
6
use Symfony\Component\Console\Application;
7
8
class Base extends Eloquent
9
{
10
    protected $hidden = ['config'];
11
12
    private $config;
13
14
    public function __construct(array $attributes = [])
15
    {
16
        parent::__construct($attributes);
17
18
        $this->setConnection($this->getConfig()->get('connection'));
19
    }
20
21
    public function getConfig()
22
    {
23
        if ($this->config) {
24
            return $this->config;
25
        } elseif (isset($GLOBALS['app']) && $GLOBALS['app'] instanceof Application) {
26
            return $GLOBALS['app']['tracker.config'];
27
        }
28
29
        return app()->make('tracker.config');
30
    }
31
32
    public function save(array $options = [])
33
    {
34
        parent::save($options);
35
36
        app('tracker.cache')->makeKeyAndPut($this, $this->getKeyName());
37
    }
38
39
    public function setConfig($config)
40
    {
41
        $this->config = $config;
42
    }
43
44
    public function scopePeriod($query, $minutes, $alias = '')
45
    {
46
        $alias = $alias ? "$alias." : '';
47
48
        return $query
49
            ->where($alias.'updated_at', '>=', $minutes->getStart() ? $minutes->getStart() : 1)
50
            ->where($alias.'updated_at', '<=', $minutes->getEnd() ? $minutes->getEnd() : 1);
51
    }
52
}
53