Passed
Push — main ( 46acb9...99a2be )
by Michael
02:57
created

isForwardingEnabled()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
use MichaelRubel\EnhancedContainer\Call;
6
use MichaelRubel\EnhancedContainer\Core\BindingBuilder;
7
8
if (! function_exists('call')) {
9
    /**
10
     * @param string|object $class
11
     * @param array         $parameters
12
     *
13
     * @return mixed
14
     */
15
    function call(string|object $class, array $parameters = []): mixed
16
    {
17
        return app(Call::class, [$class, $parameters]);
18
    }
19
}
20
21
if (! function_exists('bind')) {
22
    /**
23
     * @param string|object $abstract
24
     *
25
     * @return BindingBuilder
26
     */
27
    function bind(string|object $abstract): BindingBuilder
0 ignored issues
show
Best Practice introduced by
It is generally recommended to explicitly declare the visibility for methods.

Adding explicit visibility (private, protected, or public) is generally recommend to communicate to other developers how, and from where this method is intended to be used.

Loading history...
28
    {
29
        return new BindingBuilder($abstract);
30
    }
31
}
32
33
if (! function_exists('singleton')) {
34
    /**
35
     * @param string              $abstract
36
     * @param Closure|string|null $concrete
37
     *
38
     * @return void
39
     */
40
    function singleton(string $abstract, \Closure|string $concrete = null): void
41
    {
42
        app()->singleton($abstract, $concrete);
43
    }
44
}
45
46
if (! function_exists('scoped')) {
47
    /**
48
     * @param string              $abstract
49
     * @param Closure|string|null $concrete
50
     *
51
     * @return void
52
     */
53
    function scoped(string $abstract, \Closure|string $concrete = null): void
54
    {
55
        app()->scoped($abstract, $concrete);
56
    }
57
}
58
59
if (! function_exists('extend')) {
60
    /**
61
     * @param string  $abstract
62
     * @param Closure $closure
63
     *
64
     * @return void
65
     */
66
    function extend(string $abstract, \Closure $closure): void
67
    {
68
        app()->extend($abstract, $closure);
69
    }
70
}
71
72
if (! function_exists('isForwardingEnabled')) {
73
    /**
74
     * @return bool
75
     */
76
    function isForwardingEnabled(): bool
77
    {
78
        return config('enhanced-container.forwarding_enabled');
79
    }
80
}
81
82
if (! function_exists('enableMethodForwarding')) {
83
    /**
84
     * @return void
85
     */
86
    function enableMethodForwarding(): void
87
    {
88
        config(['enhanced-container.forwarding_enabled' => true]);
89
    }
90
}
91
92
if (! function_exists('disableMethodForwarding')) {
93
    /**
94
     * @return void
95
     */
96
    function disableMethodForwarding(): void
97
    {
98
        config(['enhanced-container.forwarding_enabled' => false]);
99
    }
100
}
101
102
if (! function_exists('runWithoutForwarding')) {
103
    /**
104
     * @param Closure $closure
105
     *
106
     * @return mixed
107
     */
108
    function runWithoutForwarding(\Closure $closure): mixed
109
    {
110
        disableMethodForwarding();
111
112
        $callback = $closure();
113
114
        enableMethodForwarding();
115
116
        return $callback;
117
    }
118
}
119
120
if (! function_exists('runWithForwarding')) {
121
    /**
122
     * @param Closure $closure
123
     *
124
     * @return mixed
125
     */
126
    function runWithForwarding(\Closure $closure): mixed
127
    {
128
        enableMethodForwarding();
129
130
        $callback = $closure();
131
132
        disableMethodForwarding();
133
134
        return $callback;
135
    }
136
}
137