Test Failed
Push — master ( afae9d...56ac77 )
by Php Easy Api
04:28
created
src/resta/Middleware/MiddlewareProvider.php 1 patch
Spacing   +35 added lines, -37 removed lines patch added patch discarded remove patch
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
      */
61 61
     public function getResolveServiceMiddleware()
62 62
     {
63
-        if(!is_null($this->serviceMiddleware)){
63
+        if (!is_null($this->serviceMiddleware)) {
64 64
             return $this->app->resolve($this->serviceMiddleware);
65 65
         }
66 66
 
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
     public function handle()
96 96
     {
97 97
         //set define for middleware
98
-        define('middleware',true);
98
+        define('middleware', true);
99 99
 
100 100
         //middleware handle process
101 101
         $this->handleMiddlewareProcess();
@@ -107,7 +107,7 @@  discard block
 block discarded – undo
107 107
      * @param string $method
108 108
      * @return void|mixed
109 109
      */
110
-    public function handleMiddlewareProcess($method='handle')
110
+    public function handleMiddlewareProcess($method = 'handle')
111 111
     {
112 112
         // the app instance is a global application example,
113 113
         // and a hash is loaded as this hash.
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
 
116 116
         // the middleware class must be subject to
117 117
         // the ServiceMiddlewareManagerContracts interface rule to be implemented.
118
-        if(!$this->getResolveServiceMiddleware() instanceof ServiceMiddlewareManagerContracts){
118
+        if (!$this->getResolveServiceMiddleware() instanceof ServiceMiddlewareManagerContracts) {
119 119
             exception()->badMethodCall('Service middleware does not have ServiceMiddlewareManagerContracts');
120 120
         }
121 121
 
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
      * @param $key null
133 133
      * @return array
134 134
      */
135
-    public function middlewareKeyOdds($key=null)
135
+    public function middlewareKeyOdds($key = null)
136 136
     {
137 137
         $route = Route::getRouteResolve();
138 138
 
@@ -141,12 +141,10 @@  discard block
 block discarded – undo
141 141
             : (defined('endpoint')) ? endpoint : null;
142 142
 
143 143
         $method = (isset($route['method']))
144
-            ? $route['method'] :
145
-            ($this->app->has('routeParameters')) ? implode("/",$this->app['routeParameters']) : '';
144
+            ? $route['method'] : ($this->app->has('routeParameters')) ? implode("/", $this->app['routeParameters']) : '';
146 145
 
147 146
         $http = (isset($route['http']))
148
-            ? $route['http'] :
149
-            ($this->app->has('httpMethod')) ? $this->app['httpMethod'] : null ;
147
+            ? $route['http'] : ($this->app->has('httpMethod')) ? $this->app['httpMethod'] : null;
150 148
 
151 149
         // identifying constants for the middleware layer.
152 150
         // with the property of the user, the user is free to determine the constants that the middleware layer wants.
@@ -155,8 +153,8 @@  discard block
 block discarded – undo
155 153
         $http       = $this->odds['http'] ?? $http;
156 154
 
157 155
         //method can only return fixed.
158
-        if(!is_null($key)){
159
-            if(isset($$key)) return $$key;
156
+        if (!is_null($key)) {
157
+            if (isset($$key)) return $$key;
160 158
         }
161 159
 
162 160
         //middleware key odds
@@ -174,21 +172,21 @@  discard block
 block discarded – undo
174 172
      *
175 173
      * @param array $middleware
176 174
      */
177
-    public function serviceMiddleware($middleware=array())
175
+    public function serviceMiddleware($middleware = array())
178 176
     {
179 177
         $this->show = [];
180 178
 
181 179
         //It will be run individually according to the rules of
182 180
         //the middleware classes specified for the service middleware middleware.
183
-        foreach($middleware as $middleVal=>$middleKey){
181
+        foreach ($middleware as $middleVal=>$middleKey) {
184 182
 
185 183
             // if the keys in the array in the service middleware class represent a class,
186 184
             // this value is checked, if it does not represent the class,
187 185
             // it is detected as a short name and is searched in the middleware directory.
188
-            if(Utils::isNamespaceExists($middleVal)){
186
+            if (Utils::isNamespaceExists($middleVal)) {
189 187
                 $middlewareNamespace = $middleVal;
190 188
             }
191
-            else{
189
+            else {
192 190
                 $middlewareNamespace = app()->namespace()->middleware().'\\'.ucfirst($middleVal);
193 191
             }
194 192
 
@@ -207,12 +205,12 @@  discard block
 block discarded – undo
207 205
             //it will be handled according to the following rule.
208 206
             //The exclude class will return a callback and allocate the result as bool to the exclude variable.
209 207
             //If the exclude variable is true then the middleware will be run.
210
-            $excludeClass->exclude($this->middleware,function($exclude) use ($middleVal){
208
+            $excludeClass->exclude($this->middleware, function($exclude) use ($middleVal){
211 209
 
212
-                if($exclude){
210
+                if ($exclude) {
213 211
 
214 212
                     //the condition of a specific statement to be handled
215
-                    if($this->checkNamespaceAndSpecificCondition()){
213
+                    if ($this->checkNamespaceAndSpecificCondition()) {
216 214
                         $this->pointer($middleVal);
217 215
 
218 216
                         //directly registered to the middleware name show property.
@@ -220,8 +218,8 @@  discard block
 block discarded – undo
220 218
 
221 219
                         // the middleware namespace must have handletraitcontract interface property.
222 220
                         // otherwise, middleware will not work.
223
-                        if(false === $this->app->runningInConsole()
224
-                            && $this->app->resolve($this->middleware['namespace']) instanceof HandleContracts){
221
+                        if (false===$this->app->runningInConsole()
222
+                            && $this->app->resolve($this->middleware['namespace']) instanceof HandleContracts) {
225 223
                             $this->app->resolve($this->middleware['namespace'])->handle();
226 224
                         }
227 225
                     }
@@ -237,10 +235,10 @@  discard block
 block discarded – undo
237 235
      * @param null $key
238 236
      * @param null $value
239 237
      */
240
-    public function setKeyOdds($key=null,$value=null)
238
+    public function setKeyOdds($key = null, $value = null)
241 239
     {
242 240
         //user-defined middleware constants.
243
-        if(!is_null($key) && !is_null($value)){
241
+        if (!is_null($key) && !is_null($value)) {
244 242
             $this->odds[$key] = $value;
245 243
         }
246 244
     }
@@ -257,13 +255,13 @@  discard block
 block discarded – undo
257 255
 
258 256
         // if the service middleware does not represent a class,
259 257
         // then in this case core support is assigned as a class service middleware.
260
-        if(Utils::isNamespaceExists($serviceMiddleware)===false){
258
+        if (Utils::isNamespaceExists($serviceMiddleware)===false) {
261 259
             $serviceMiddleware = ServiceMiddlewareManager::class;
262 260
         }
263 261
 
264 262
         //We are logging the kernel for the middleware class and the exclude class
265
-        $this->app->register('middlewareClass',$this->app->resolve($serviceMiddleware));
266
-        $this->app->register('excludeClass',$this->app->resolve(ExcludeMiddleware::class));
263
+        $this->app->register('middlewareClass', $this->app->resolve($serviceMiddleware));
264
+        $this->app->register('excludeClass', $this->app->resolve(ExcludeMiddleware::class));
267 265
     }
268 266
 
269 267
     /**
@@ -271,9 +269,9 @@  discard block
 block discarded – undo
271 269
      *
272 270
      * @param null $serviceMiddleware
273 271
      */
274
-    public function setserviceMiddleware($serviceMiddleware=null)
272
+    public function setserviceMiddleware($serviceMiddleware = null)
275 273
     {
276
-        if(!is_null($serviceMiddleware)){
274
+        if (!is_null($serviceMiddleware)) {
277 275
             $this->serviceMiddleware = $serviceMiddleware;
278 276
         }
279 277
     }
@@ -288,11 +286,11 @@  discard block
 block discarded – undo
288 286
     {
289 287
         //If the all option is present,
290 288
         //it is automatically injected into all services for the middleware application.
291
-        if($key==="all") return true;
289
+        if ($key==="all") return true;
292 290
 
293 291
         //service middleware key
294 292
         //if it is array,check odds
295
-        if(is_array($key)){
293
+        if (is_array($key)) {
296 294
 
297 295
             //get middleware odd keys
298 296
             $odds = $this->middlewareKeyOdds();
@@ -301,8 +299,8 @@  discard block
 block discarded – undo
301 299
             //then the middleware is conditioned and the services are individually checked according to
302 300
             //the degree of conformity with the middlewareOdds method and
303 301
             //the middleware is executed under the specified condition.
304
-            foreach($key as $item){
305
-                if(in_array($item,$odds)){
302
+            foreach ($key as $item) {
303
+                if (in_array($item, $odds)) {
306 304
                     return true;
307 305
                 }
308 306
             }
@@ -320,17 +318,17 @@  discard block
 block discarded – undo
320 318
      */
321 319
     private function pointer($middleValue)
322 320
     {
323
-        if(isset($this->app['pointer']['middlewareList'])){
321
+        if (isset($this->app['pointer']['middlewareList'])) {
324 322
 
325 323
             $middlewareList = $this->app['pointer']['middlewareList'];
326 324
 
327
-            if(is_array($middlewareList)){
328
-                $middlewareList = array_merge($middlewareList,[$middleValue]);
329
-                $this->app->register('pointer','middlewareList',$middlewareList);
325
+            if (is_array($middlewareList)) {
326
+                $middlewareList = array_merge($middlewareList, [$middleValue]);
327
+                $this->app->register('pointer', 'middlewareList', $middlewareList);
330 328
             }
331 329
         }
332
-        else{
333
-            $this->app->register('pointer','middlewareList',[$middleValue]);
330
+        else {
331
+            $this->app->register('pointer', 'middlewareList', [$middleValue]);
334 332
         }
335 333
     }
336 334
 }
337 335
\ No newline at end of file
Please login to merge, or discard this patch.