Component::shouldntHandle()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4222
c 0
b 0
f 0
ccs 9
cts 9
cp 1
cc 5
nc 5
nop 1
crap 5
1
<?php
2
3
namespace Tylercd100\LERN\Components;
4
5
use Throwable;
6
use Illuminate\Support\Facades\Cache;
7
use Carbon\Carbon;
8
9
abstract class Component {
10
11
    /**
12
     * @var array
13
     */
14
    protected $dontHandle = [];
15
16
    /**
17
     * This array is overwritten in each component
18
     * 
19
     * @var array
20
     */
21
    protected $absolutelyDontHandle = [];
22
23
    /**
24
     * Determine if the exception is in the "do not handle" list.
25
     *
26
     * @param  \Throwable  $e
27
     * @return bool
28
     */
29 39
    protected function shouldntHandle(Throwable $e) {
30 39
        $dontHandle = array_merge($this->dontHandle, $this->absolutelyDontHandle);
31
32 39
        foreach ($dontHandle as $type) {
33 39
            if ($e instanceof $type) {
34 39
                return true;
35
            }
36
        }
37
38 33
        $sent_at = Cache::get($this->getCacheKey($e));
39 33
        if (empty($sent_at) || $sent_at->addSeconds(config('lern.ratelimit', 1))->lte(Carbon::now())) {
40 33
            return false; // The cache is empty or enough time has passed, so lets continue
41
        } else {
42 6
            return true;
43
        }
44
    }
45
46
    /**
47
     * Returns the cache key for the exception with the current component
48
     * 
49
     * @param \Throwable $e
50
     * @return string
51
     */
52 33
    protected function getCacheKey(Throwable $e)
53
    {
54 33
        return "LERN::".static::class."::".get_class($e);
55
    }
56
}