Passed
Push — master ( 95726c...2a33fd )
by Stephen
02:51
created

TrackSpamQuery::cacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
4
namespace Sfneal\Honeypot\Queries;
5
6
7
use Illuminate\Database\Eloquent\Builder;
8
use Sfneal\Caching\Traits\Cacheable;
9
use Sfneal\Honeypot\Models\TrackSpam;
10
use Sfneal\Queries\Query;
11
12
// todo: add tests
13
class TrackSpamQuery extends Query
14
{
15
    use Cacheable;
16
17
    /**
18
     * @var int
19
     */
20
    private $limit;
21
22
    /**
23
     * TrackSpamQuery constructor.
24
     *
25
     * @param int $limit
26
     */
27
    public function __construct(int $limit = 200)
28
    {
29
        $this->limit = $limit;
30
    }
31
32
    /**
33
     * Retrieve a Query builder.
34
     *
35
     * @return Builder
36
     */
37
    protected function builder(): Builder
38
    {
39
        return TrackSpam::query();
40
    }
41
42
    /**
43
     * Execute a DB query.
44
     *
45
     * @return mixed
46
     */
47
    public function execute()
48
    {
49
        return $this->builder()
50
            ->limit($this->limit)
51
            ->get();
52
    }
53
54
    /**
55
     * Retrieve the Query cache key.
56
     *
57
     * @return string
58
     */
59
    public function cacheKey(): string
60
    {
61
        return TrackSpam::getTableName() . ':recent#' . $this->limit;
62
    }
63
}
64