Reset   A
last analyzed

Complexity

Total Complexity 22

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 49
dl 0
loc 125
rs 10
c 0
b 0
f 0
wmc 22

10 Methods

Rating   Name   Duplication   Size   Complexity  
A allOperatingSystems() 0 6 2
A allcountries() 0 6 2
A ips() 0 6 2
A allLanguages() 0 6 2
A periods() 0 6 2
A visits() 0 16 4
A __construct() 0 10 3
A factory() 0 10 1
A allrefs() 0 6 2
A lists() 0 6 2
1
<?php
2
3
namespace Awssat\Visits;
4
5
class Reset extends Visits
6
{
7
    protected $keys;
8
9
    public function __construct(Visits $parent, $method, $args)
10
    {
11
        parent::__construct($parent->subject);
12
        $this->keys = $parent->keys;
13
14
        if (method_exists($this, $method)) {
15
            if (empty($args)) {
16
                $this->$method();
17
            } else {
18
                $this->$method($args);
19
            }
20
        }
21
    }
22
23
    /**
24
     * Reset everything
25
     */
26
    public function factory()
27
    {
28
        $this->visits();
29
        $this->periods();
30
        $this->ips();
31
        $this->lists();
32
        $this->allcountries();
33
        $this->allrefs();
34
        $this->allOperatingSystems();
35
        $this->allLanguages();
36
    }
37
38
    /**
39
     * reset all time visits
40
     */
41
    public function visits()
42
    {
43
        if ($this->keys->id) {
44
            $this->connection->delete($this->keys->visits, $this->keys->id);
45
            foreach (['countries', 'referers', 'OSes', 'languages'] as $item) {
46
                $this->connection->delete($this->keys->visits."_{$item}:{$this->keys->id}");
47
            }
48
49
            foreach ($this->periods as $period => $_) {
50
                $this->connection->delete($this->keys->period($period), $this->keys->id);
51
            }
52
53
            $this->ips();
54
        } else {
55
            $this->connection->delete($this->keys->visits);
56
            $this->connection->delete($this->keys->visits.'_total');
57
        }
58
    }
59
60
    public function allrefs()
61
    {
62
        $cc = $this->connection->search($this->keys->visits.'_referers:*');
63
64
        if (count($cc)) {
65
            $this->connection->delete($cc);
66
        }
67
    }
68
69
    public function allOperatingSystems()
70
    {
71
        $cc = $this->connection->search($this->keys->visits.'_OSes:*');
72
73
        if (count($cc)) {
74
            $this->connection->delete($cc);
75
        }
76
    }
77
78
    public function allLanguages()
79
    {
80
        $cc = $this->connection->search($this->keys->visits.'_languages:*');
81
82
        if (count($cc)) {
83
            $this->connection->delete($cc);
84
        }
85
    }
86
87
    public function allcountries()
88
    {
89
        $cc = $this->connection->search($this->keys->visits.'_countries:*');
90
91
        if (count($cc)) {
92
            $this->connection->delete($cc);
93
        }
94
    }
95
96
    /**
97
     * reset day,week counters
98
     */
99
    public function periods()
100
    {
101
        foreach ($this->periods as $period => $_) {
102
            $periodKey = $this->keys->period($period);
103
            $this->connection->delete($periodKey);
104
            $this->connection->delete($periodKey.'_total');
105
        }
106
    }
107
108
    /**
109
     * reset ips protection
110
     * @param string $ips
111
     */
112
    public function ips($ips = '*')
113
    {
114
        $ips = $this->connection->search($this->keys->ip($ips));
115
116
        if (count($ips)) {
117
            $this->connection->delete($ips);
118
        }
119
    }
120
121
    /**
122
     * reset lists top/low
123
     */
124
    public function lists()
125
    {
126
        $lists = $this->connection->search($this->keys->cache());
127
128
        if (count($lists)) {
129
            $this->connection->delete($lists);
130
        }
131
    }
132
}
133