app()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 8
ccs 5
cts 5
cp 1
crap 3
rs 9.4285
c 0
b 0
f 0
1
<?php
2
use Illuminate\Container\Container;
3
4
if (! function_exists('config')) {
5
    /**
6
     * Get / set the specified configuration value.
7
     *
8
     * If an array is passed as the key, we will assume you want to set an array of values.
9
     *
10
     * @param  array|string  $key
11
     * @param  mixed  $default
12
     * @return mixed
13
     */
14
    function config($key = null, $default = null)
15
    {
16 19
        if (is_null($key)) {
17 1
            return app('config');
18
        }
19 19
        if (is_array($key)) {
20 1
            return app('config')->set($key);
0 ignored issues
show
Bug introduced by
The method set() does not exist on Illuminate\Container\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

20
            return app('config')->/** @scrutinizer ignore-call */ set($key);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
21
        }
22 18
        return app('config')->get($key, $default);
0 ignored issues
show
Bug introduced by
The method get() does not exist on Illuminate\Container\Container. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

22
        return app('config')->/** @scrutinizer ignore-call */ get($key, $default);

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
23
    }
24
}
25
26
if (! function_exists('app')) {
27
    /**
28
     * Get the available container instance.
29
     *
30
     * @param  string  $abstract
31
     * @param  array   $parameters
32
     * @return Illuminate\Container\Container
33
     */
34
    function app($abstract = null, array $parameters = [])
35
    {
36 23
        if (is_null($abstract)) {
37 23
            return Container::getInstance();
38
        }
39 19
        return empty($parameters)
40 19
            ? Container::getInstance()->make($abstract)
41 19
            : Container::getInstance()->makeWith($abstract, $parameters);
42
    }
43
}
44
45
if (! function_exists('inJson')) {
46
    /**
47
     * Sugar json_encode
48
     *
49
     * @param array $values
50
     * @return string
51
     */
52
    function inJson(array $values = []) : string
53
    {
54 7
        return json_encode($values);
55
    }
56
}
57
58
if (! function_exists('fromJson')) {
59
    /**
60
     * Sugar json_encode
61
     *
62
     * @param string $json
63
     * @param bool   $assoc
64
     * @param int    $depth
65
     * @return mixed
66
     */
67
    function fromJson(string $json = '', bool $assoc = false, int $depth = 512)
68
    {
69 9
        return json_decode($json, $assoc, $depth);
70
    }
71
}