Completed
Push — master ( 3afbe4...79027c )
by Oleg
07:17
created

helpers.php ➔ call_if_callable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 7
rs 9.4285
c 0
b 0
f 0
1
<?php
2
use Illuminate\Container\Container;
3
use Malezha\Menu\Contracts\Builder;
4
use Malezha\Menu\Contracts\Menu;
5
6
if (!function_exists('call_if_callable')) {
7
    /**
8
     * Call function if it callable
9
     *
10
     * @param callable $callable
11
     * @param array ...$params
12
     * @return mixed
13
     */
14
    function call_if_callable($callable, ...$params) {
0 ignored issues
show
Coding Style introduced by
As per coding-style, this function should be in camelCase.

CamelCase (...) is the practice of writing compound words or phrases such that
each word or abbreviation begins with a capital letter.

Learn more about camelCase.

Loading history...
15
        if (is_callable($callable)) {
16
            return call_user_func_array($callable, $params);
17
        }
18
19
        return null;
20
    }
21
}
22
23
if (!function_exists('menu')) {
24
    /**
25
     * @param string|null $name
26
     * @return Builder|Menu
27
     */
28
    function menu($name = null) {
29
        /** @var Menu $menu */
30
        $menu = Container::getInstance()->make(Menu::class);
31
32
        if (is_null($name)) {
33
            return $menu;
34
        }
35
36
        return $menu->make($name);
37
    }
38
}