1
1
<?php
2
+
3
+
4
+ declare (strict_types = 1 );
5
+
6
+
7
+ namespace WpFacade ;
2
8
3
- namespace WpFacade ;
4
-
9
+ use Contracts \ ContainerAdapter ;
10
+ use Mockery ;
5
11
use Mockery \MockInterface ;
12
+ use RuntimeException ;
6
13
7
14
abstract class WpFacade {
8
- /** @var \BetterWpHooks\Contracts\EventContainerAdapter */
9
- private static $ container ;
10
-
11
15
16
+
17
+ /** @var ContainerAdapter */
18
+ private static $ container ;
19
+
12
20
/**
13
21
* The resolved object instances.
14
22
*
15
23
* @var array
16
24
*/
17
25
private static $ resolvedInstance ;
18
-
19
-
26
+
20
27
/**
21
28
* Get the root object behind the facade.
22
29
*
@@ -26,8 +33,7 @@ public static function getFacadeRoot() {
26
33
27
34
return static ::resolveFacadeInstance ( static ::getFacadeAccessor () );
28
35
}
29
-
30
-
36
+
31
37
/**
32
38
* Get the registered name of the component.
33
39
*
@@ -39,9 +45,7 @@ protected static function getFacadeAccessor() {
39
45
40
46
throw new RuntimeException ( 'Facade does not implement getFacadeAccessor method. ' );
41
47
}
42
-
43
-
44
-
48
+
45
49
/**
46
50
* Resolve the facade root instance from the container.
47
51
*
@@ -75,7 +79,7 @@ protected static function resolveFacadeInstance( $name ) {
75
79
*
76
80
* @return void
77
81
*/
78
- public static function clearResolvedInstance ( $ name ) {
82
+ public static function clearResolvedInstance ( string $ name ) {
79
83
unset( static ::$ resolvedInstance [ $ name ] );
80
84
}
81
85
@@ -91,24 +95,15 @@ public static function clearResolvedInstances() {
91
95
}
92
96
93
97
94
- /**
95
- *
96
- * @return \BetterWpHooks\Contracts\EventContainerAdapter
97
- */
98
- public static function getFacadeContainer (): Contracts \EventContainerAdapter {
98
+ public static function getFacadeContainer (): ContainerAdapter {
99
99
100
100
return static ::$ container ;
101
101
102
102
}
103
103
104
- /**
105
- * Set the application instance.
106
- *
107
- * @param \BetterWpHooks\Contracts\EventContainerAdapter $container
108
- *
109
- * @return void
110
- */
111
- public static function setFacadeContainer ( $ container ) {
104
+
105
+
106
+ public static function setFacadeContainer ( ContainerAdapter $ container ) {
112
107
static ::$ container = $ container ;
113
108
}
114
109
@@ -121,7 +116,7 @@ public static function setFacadeContainer( $container ) {
121
116
*
122
117
* @return mixed
123
118
*
124
- * @throws \ RuntimeException
119
+ * @throws RuntimeException
125
120
*/
126
121
public static function __callStatic ( string $ method , array $ args ) {
127
122
@@ -135,8 +130,7 @@ public static function __callStatic( string $method, array $args ) {
135
130
return $ instance ->$ method ( ...$ args );
136
131
137
132
}
138
-
139
-
133
+
140
134
/**
141
135
* Convert the facade into a Mockery spy.
142
136
*
@@ -147,14 +141,15 @@ public static function spy() {
147
141
if ( ! static ::isMock () ) {
148
142
149
143
$ class = static ::getMockableClass ();
150
-
151
- return tap ( $ class ? Mockery::spy ( $ class ) : Mockery::spy (), function ( $ spy ) {
152
- static ::swap ( $ spy );
153
- } );
144
+
145
+ $ spy = $ class ? Mockery::spy ($ class ) : Mockery::spy ();
146
+ static ::swap ($ spy );
147
+
148
+ return $ spy ;
149
+
154
150
}
155
151
}
156
-
157
-
152
+
158
153
/**
159
154
* Initiate a partial mock on the facade.
160
155
*
@@ -192,11 +187,14 @@ public static function shouldReceive() {
192
187
* @return \Mockery\MockInterface
193
188
*/
194
189
protected static function createFreshMockInstance () {
195
- return tap ( static ::createMock (), function ( $ mock ) {
196
- static ::swap ( $ mock );
197
-
198
- $ mock ->shouldAllowMockingProtectedMethods ();
199
- } );
190
+
191
+ $ mock = static ::createMock ();
192
+ static ::swap ($ mock );
193
+ $ mock ->shouldAllowMockingProtectedMethods ();
194
+
195
+ return $ mock ;
196
+
197
+
200
198
}
201
199
202
200
/**
@@ -216,6 +214,7 @@ protected static function createMock() {
216
214
* @return bool
217
215
*/
218
216
protected static function isMock () {
217
+
219
218
$ name = static ::getFacadeAccessor ();
220
219
221
220
return isset ( static ::$ resolvedInstance [ $ name ] ) &&
0 commit comments