Base   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getConfig() 0 10 4
A save() 0 6 1
A setConfig() 0 4 1
A scopePeriod() 0 8 4
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