CacheFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 5
c 3
b 0
f 0
dl 0
loc 41
ccs 7
cts 7
cp 1
rs 10
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A getCache() 0 3 1
A make() 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\Factories;
15
16
use GrahamCampbell\Throttle\Data;
17
use GrahamCampbell\Throttle\Throttlers\CacheThrottler;
18
use Illuminate\Contracts\Cache\Repository;
19
20
/**
21
 * This is the cache throttler factory class.
22
 *
23
 * @author Graham Campbell <[email protected]>
24
 */
25
class CacheFactory implements FactoryInterface
26
{
27
    /**
28
     * The cache instance.
29
     *
30
     * @var \Illuminate\Contracts\Cache\Repository
31
     */
32
    protected $cache;
33
34
    /**
35
     * Create a new instance.
36
     *
37
     * @param \Illuminate\Contracts\Cache\Repository $cache
38
     *
39
     * @return void
40
     */
41 132
    public function __construct(Repository $cache)
42
    {
43 132
        $this->cache = $cache;
44 132
    }
45
46
    /**
47
     * Make a new cache throttler instance.
48
     *
49
     * @param \GrahamCampbell\Throttle\Data $data
50
     *
51
     * @return \GrahamCampbell\Throttle\Throttlers\CacheThrottler
52
     */
53 84
    public function make(Data $data)
54
    {
55 84
        return new CacheThrottler($this->cache->getStore(), $data->getKey(), $data->getLimit(), $data->getTime());
56
    }
57
58
    /**
59
     * Get the cache instance.
60
     *
61
     * @return \Illuminate\Contracts\Cache\Repository
62
     */
63 12
    public function getCache()
64
    {
65 12
        return $this->cache;
66
    }
67
}
68