Data   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 109
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
c 1
b 0
f 0
dl 0
loc 109
ccs 18
cts 18
cp 1
rs 10
wmc 7

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getLimit() 0 3 1
A __construct() 0 6 1
A getIp() 0 3 1
A getTime() 0 3 1
A getKey() 0 7 2
A getRoute() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of Laravel Throttle.
7
 *
8
 * (c) Graham Campbell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace GrahamCampbell\Throttle;
15
16
/**
17
 * This is the data class.
18
 *
19
 * @author Graham Campbell <[email protected]>
20
 */
21
class Data
22
{
23
    /**
24
     * The ip.
25
     *
26
     * @var string
27
     */
28
    protected $ip;
29
30
    /**
31
     * The route.
32
     *
33
     * @var string
34
     */
35
    protected $route;
36
37
    /**
38
     * The request limit.
39
     *
40
     * @var int
41
     */
42
    protected $limit;
43
44
    /**
45
     * The expiration time.
46
     *
47
     * @var int
48
     */
49
    protected $time;
50
51
    /**
52
     * The unique key.
53
     *
54
     * @var string
55
     */
56
    protected $key;
57
58
    /**
59
     * Create a new instance.
60
     *
61
     * @param string $ip
62
     * @param string $route
63
     * @param int    $limit
64
     * @param int    $time
65
     *
66
     * @return void
67
     */
68 192
    public function __construct(string $ip, string $route, int $limit = 10, int $time = 60)
69
    {
70 192
        $this->ip = $ip;
71 192
        $this->route = $route;
72 192
        $this->limit = $limit;
73 192
        $this->time = $time;
74 192
    }
75
76
    /**
77
     * Get the ip.
78
     *
79
     * @return string
80
     */
81 12
    public function getIp()
82
    {
83 12
        return $this->ip;
84
    }
85
86
    /**
87
     * Get the route.
88
     *
89
     * @return string
90
     */
91 12
    public function getRoute()
92
    {
93 12
        return $this->route;
94
    }
95
96
    /**
97
     * Get the request limit.
98
     *
99
     * @return int
100
     */
101 84
    public function getLimit()
102
    {
103 84
        return $this->limit;
104
    }
105
106
    /**
107
     * Get the expiration time.
108
     *
109
     * @return int
110
     */
111 84
    public function getTime()
112
    {
113 84
        return $this->time;
114
    }
115
116
    /**
117
     * Get the unique key.
118
     *
119
     * This key is used to identify the data between requests.
120
     *
121
     * @return string
122
     */
123 120
    public function getKey()
124
    {
125 120
        if (!$this->key) {
126 120
            $this->key = sha1($this->ip.$this->route);
127
        }
128
129 120
        return $this->key;
130
    }
131
}
132