Completed
Push — master ( 46d590...b6440b )
by bader
19s queued 10s
created

Reset::allOperatingSystems()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 0
dl 0
loc 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace awssat\Visits;
4
5
class Reset extends Visits
6
{
7
    protected $keys;
8
9
    /**
10
     * Reset constructor.
11
     * @param Visits $parent
12
     * @param Keys $keys
13
     * @param $method
14
     * @param $args
15
     */
16
    public function __construct(Visits $parent, $method, $args)
17
    {
18
        parent::__construct($parent->subject);
19
        $this->keys = $parent->keys;
20
21
        if (method_exists($this, $method)) {
22
            if (empty($args)) {
23
                $this->$method();
24
            } else {
25
                $this->$method($args);
26
            }
27
        }
28
    }
29
30
    /**
31
     * Reset everything
32
     *
33
     */
34
    public function factory()
35
    {
36
        $this->visits();
37
        $this->periods();
38
        $this->ips();
39
        $this->lists();
40
        $this->allcountries();
41
        $this->allrefs();
42
        $this->allOperatingSystems();
43
        $this->allLanguages();
44
    }
45
46
    /**
47
     * reset all time visits
48
     */
49
    public function visits()
50
    {
51
        if ($this->keys->id) {
52
            $this->redis->zrem($this->keys->visits, $this->keys->id);
0 ignored issues
show
Bug introduced by
The method zrem() does not exist on Illuminate\Support\Facades\Redis. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

52
            $this->redis->/** @scrutinizer ignore-call */ 
53
                          zrem($this->keys->visits, $this->keys->id);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
53
            $this->redis->del($this->keys->visits . "_countries:{$this->keys->id}");
0 ignored issues
show
Bug introduced by
The method del() does not exist on Illuminate\Support\Facades\Redis. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
            $this->redis->/** @scrutinizer ignore-call */ 
54
                          del($this->keys->visits . "_countries:{$this->keys->id}");

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
54
            $this->redis->del($this->keys->visits . "_referers:{$this->keys->id}");
55
            $this->redis->del($this->keys->visits . "_OSes:{$this->keys->id}");
56
            $this->redis->del($this->keys->visits . "_languages:{$this->keys->id}");
57
58
            foreach ($this->periods as $period => $_) {
59
                $this->redis->zrem($this->keys->period($period), $this->keys->id);
60
            }
61
62
            $this->ips();
63
        } else {
64
            $this->redis->del($this->keys->visits);
65
            $this->redis->del($this->keys->visits . '_total');
66
        }
67
68
    }
69
70
    public function allrefs()
71
    {
72
        $cc = $this->redis->keys($this->keys->visits . '_referers:*');
0 ignored issues
show
Bug introduced by
The method keys() does not exist on Illuminate\Support\Facades\Redis. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

72
        /** @scrutinizer ignore-call */ 
73
        $cc = $this->redis->keys($this->keys->visits . '_referers:*');

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
73
74
        if (count($cc)) {
75
            $this->redis->del($cc);
76
        }
77
    }
78
79
    public function allOperatingSystems()
80
    {
81
        $cc = $this->redis->keys($this->keys->visits . '_OSes:*');
82
83
        if (count($cc)) {
84
            $this->redis->del($cc);
85
        }
86
    }
87
88
    public function allLanguages()
89
    {
90
        $cc = $this->redis->keys($this->keys->visits . '_languages:*');
91
92
        if (count($cc)) {
93
            $this->redis->del($cc);
94
        }
95
    }
96
97
    public function allcountries()
98
    {
99
        $cc = $this->redis->keys($this->keys->visits . '_countries:*');
100
101
        if (count($cc)) {
102
            $this->redis->del($cc);
103
        }
104
    }
105
106
    /**
107
     * reset day,week counters
108
     */
109
    public function periods()
110
    {
111
        foreach ($this->periods as $period => $days) {
112
            $periodKey = $this->keys->period($period);
113
            $this->redis->del($periodKey);
114
            $this->redis->del($periodKey . '_total');
115
        }
116
    }
117
118
    /**
119
     * reset ips protection
120
     * @param string $ips
121
     */
122
    public function ips($ips = '*')
123
    {
124
        $ips = $this->redis->keys($this->keys->ip($ips));
125
126
        if (count($ips)) {
127
            $this->redis->del($ips);
128
        }
129
    }
130
131
    /**
132
     * reset lists top/low
133
     */
134
    public function lists()
135
    {
136
        $lists = $this->redis->keys($this->keys->cache());
137
        if (count($lists)) {
138
            $this->redis->del($lists);
139
        }
140
    }
141
}
142