Completed
Push — fix/56 ( d15d50...729cbd )
by Tyler
26:35 queued 21:43
created

Component::getCacheKey()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace Tylercd100\LERN\Components;
4
5
use Exception;
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  \Exception  $e
27
     * @return bool
28
     */
29 12
    protected function shouldntHandle(Exception $e) {
30 12
        $dontHandle = array_merge($this->dontHandle, $this->absolutelyDontHandle);
31
32 12
        foreach ($dontHandle as $type) {
33 12
            if ($e instanceof $type) {
34 12
                return true;
35
            }
36
        }
37
38 12
        $sent_at = Cache::get($this->getCacheKey($e));
39 12
        if (empty($sent_at) || $sent_at->addSeconds(1)->lte(Carbon::now())) {
40 12
            var_dump([$this->getCacheKey($e), $sent_at]);
0 ignored issues
show
Security Debugging Code introduced by
var_dump(array($this->ge...cheKey($e), $sent_at)); looks like debug code. Are you sure you do not want to remove it? This might expose sensitive data.
Loading history...
41 12
            return false; // The cache is empty or enough time has passed
42
        } else {
43 3
            return true;
44
        }
45
    }
46
47
    /**
48
     * Returns the cache key for the exception with the current component
49
     * 
50
     * @param \Exception $e
51
     * @return string
52
     */
53 12
    protected function getCacheKey(Exception $e)
54
    {
55 12
        return "LERN::".static::class."::".get_class($e);
56
    }
57
}