Completed
Push — fix/56 ( a550dc...7991aa )
by Tyler
26:27 queued 15:05
created

Component::shouldntHandle()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 17

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5.025

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 9
cts 10
cp 0.9
rs 9.3888
cc 5
nc 5
nop 1
crap 5.025
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 27
    protected function shouldntHandle(Exception $e) {
30 27
        $dontHandle = array_merge($this->dontHandle, $this->absolutelyDontHandle);
31
32 27
        foreach ($dontHandle as $type) {
33 27
            if ($e instanceof $type) {
34 27
                return true;
35
            }
36
        }
37
38 24
        $sent_at = Cache::store('file')->get($this->getCacheKey($e));
39 24
        if (empty($sent_at) || $sent_at->addSeconds(1)->lte(Carbon::now())) {
40 24
            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 24
            return false; // The cache is empty or enough time has passed
42
        } else {
43
            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 24
    protected function getCacheKey(Exception $e)
54
    {
55 24
        return "LERN::".static::class."::".get_class($e);
56
    }
57
}