Callback::call()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 20
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 12
c 1
b 0
f 0
dl 0
loc 20
rs 9.8666
cc 4
nc 5
nop 0
1
<?php
2
namespace Health\Checks\Php;
3
4
use Health\Checks\BaseCheck;
5
use Health\Checks\HealthCheckInterface;
6
7
class Callback extends BaseCheck implements HealthCheckInterface
8
{
9
10
    /**
11
     *
12
     * {@inheritdoc}
13
     * @see \Health\Checks\HealthCheckInterface::call()
14
     */
15
    public function call()
16
    {
17
        $builder = $this->getBuilder();
18
19
        $callback = $this->getParam('callback', null);
20
        $params = $this->getParam('params', []);
21
22
        if (! is_callable($callback)) {
23
            $builder->down()->withData('error', 'Callback Error. Callback not callable');
24
        } else {
25
            try {
26
                if (! call_user_func_array($callback, $params)) {
27
                    $builder->down();
28
                }
29
            } catch (\Exception $e) {
30
                $builder->down()->withData('error', $e->getMessage());
31
            }
32
        }
33
34
        return $builder->build();
35
    }
36
}
37