DualCacheHandler   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 1
dl 0
loc 20
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handle() 0 11 3
1
<?php
2
declare(strict_types=1);
3
4
namespace Istyle\LaravelDualCache;
5
6
use Throwable;
7
use Closure;
8
use Istyle\LaravelDualCache\Exception\DualCacheException;
9
10
/**
11
 * Class DualCacheHandler
12
 */
13
class DualCacheHandler implements DualCacheHandlerInterface
14
{
15
    /**
16
     * @param Closure      $function
17
     * @param Closure|null $secondary
18
     *
19
     * @return mixed
20
     */
21
    public function handle(Closure $function, Closure $secondary = null)
22
    {
23
        try {
24
            return call_user_func($function);
25
        } catch (Throwable $e) {
26
            if (is_callable($secondary)) {
27
                return call_user_func($secondary);
28
            }
29
            throw new DualCacheException($e->getMessage(), $e->getCode(), $e);
30
        }
31
    }
32
}
33