LifetimeHelper   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
c 1
b 0
f 0
dl 0
loc 29
ccs 8
cts 8
cp 1
rs 10
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A computeLifetime() 0 3 2
A isLegacy() 0 10 2
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\Throttlers;
15
16
use Illuminate\Contracts\Cache\Store;
17
use ReflectionClass;
18
19
class LifetimeHelper
20
{
21
    /**
22
     * Determine the lifetime.
23
     *
24
     * @param int $minutes
25
     *
26
     * @return int
27
     */
28 108
    public static function computeLifetime(int $minutes)
29
    {
30 108
        return static::isLegacy() ? $minutes : $minutes * 60;
31
    }
32
33
    /**
34
     * Determine if the cache store is legacy.
35
     *
36
     * @return bool
37
     */
38 108
    public static function isLegacy()
39
    {
40 108
        static $legacy;
41
42 108
        if ($legacy === null) {
43 12
            $params = (new ReflectionClass(Store::class))->getMethod('put')->getParameters();
44 12
            $legacy = $params[2]->getName() === 'minutes';
45
        }
46
47 108
        return $legacy;
48
    }
49
}
50