Log   A
last analyzed

Complexity

Total Complexity 17

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 17
lcom 1
cbo 1
dl 0
loc 103
c 0
b 0
f 0
rs 10

11 Methods

Rating   Name   Duplication   Size   Complexity  
A updateRoute() 0 16 5
A updateError() 0 12 2
A bySession() 0 12 2
A getCurrentLogId() 0 4 1
A setCurrentLogId() 0 4 1
A createLog() 0 8 1
A pageViews() 0 4 1
A pageViewsByCountry() 0 4 1
A getErrors() 0 4 1
A allByRouteName() 0 4 1
A delete() 0 6 1
1
<?php
2
3
namespace PragmaRX\Tracker\Data\Repositories;
4
5
class Log extends Repository
6
{
7
    protected $currentLogId;
8
9
    protected $route_path_id;
10
11
    public function updateRoute($route_path_id = null)
12
    {
13
        if ($route_path_id) {
14
            $this->route_path_id = $route_path_id;
15
        }
16
17
        $model = $this->getModel();
18
19
        if ($model->id && $this->route_path_id && !$model->route_path_id) {
20
            $model->route_path_id = $this->route_path_id;
21
22
            $model->save();
23
        }
24
25
        return $model;
26
    }
27
28
    public function updateError($error_id)
29
    {
30
        $model = $this->getModel();
31
32
        if ($model->id) {
33
            $model->error_id = $error_id;
34
35
            $model->save();
36
        }
37
38
        return $model;
39
    }
40
41
    public function bySession($sessionId, $results = true)
42
    {
43
        $query = $this
44
                    ->getModel()
45
                    ->where('session_id', $sessionId)->orderBy('updated_at', 'desc');
46
47
        if ($results) {
48
            return $query->get();
49
        }
50
51
        return $query;
52
    }
53
54
    /**
55
     * @return null
56
     */
57
    public function getCurrentLogId()
58
    {
59
        return $this->currentLogId;
60
    }
61
62
    /**
63
     * @param null|$currentLogId
64
     *
65
     * @return null|int
66
     */
67
    public function setCurrentLogId($currentLogId)
68
    {
69
        return $this->currentLogId = $currentLogId;
70
    }
71
72
    public function createLog($data)
73
    {
74
        $log = $this->create($data);
75
76
        $this->updateRoute();
77
78
        return $this->setCurrentLogId($log->id);
79
    }
80
81
    public function pageViews($minutes, $results)
82
    {
83
        return $this->getModel()->pageViews($minutes, $results);
84
    }
85
86
    public function pageViewsByCountry($minutes, $results)
87
    {
88
        return $this->getModel()->pageViewsByCountry($minutes, $results);
89
    }
90
91
    public function getErrors($minutes, $results)
92
    {
93
        return $this->getModel()->errors($minutes, $results);
94
    }
95
96
    public function allByRouteName($name, $minutes = null)
97
    {
98
        return $this->getModel()->allByRouteName($name, $minutes);
99
    }
100
101
    public function delete()
102
    {
103
        $this->currentLogId = null;
104
105
        $this->getModel()->delete();
106
    }
107
}
108