DualCacheHandler::handle()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 11
rs 9.9
c 0
b 0
f 0
cc 3
nc 3
nop 2
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