Test Failed
Push — master ( 84b62e...bba9ba )
by Php Easy Api
05:58 queued 01:53
created
src/resta/Middleware/MiddlewareProvider.php 1 patch
Spacing   +37 added lines, -39 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
 
@@ -142,17 +142,15 @@  discard block
 block discarded – undo
142 142
             ? $route['namespace']
143 143
             : $endPointTernary;
144 144
 
145
-        $routeParameterContainer = ($this->app->has('routeParameters')) ? implode("/",$this->app['routeParameters']) : '';
145
+        $routeParameterContainer = ($this->app->has('routeParameters')) ? implode("/", $this->app['routeParameters']) : '';
146 146
 
147 147
         $method = (isset($route['method']))
148
-            ? $route['method'] :
149
-            $routeParameterContainer;
148
+            ? $route['method'] : $routeParameterContainer;
150 149
 
151
-        $routeHttpContainer = ($this->app->has('httpMethod')) ? $this->app['httpMethod'] : null ;
150
+        $routeHttpContainer = ($this->app->has('httpMethod')) ? $this->app['httpMethod'] : null;
152 151
 
153 152
         $http = (isset($route['http']))
154
-            ? $route['http'] :
155
-            $routeHttpContainer;
153
+            ? $route['http'] : $routeHttpContainer;
156 154
 
157 155
         // identifying constants for the middleware layer.
158 156
         // with the property of the user, the user is free to determine the constants that the middleware layer wants.
@@ -161,8 +159,8 @@  discard block
 block discarded – undo
161 159
         $http       = $this->odds['http'] ?? $http;
162 160
 
163 161
         //method can only return fixed.
164
-        if(!is_null($key)){
165
-            if(isset($$key)) return $$key;
162
+        if (!is_null($key)) {
163
+            if (isset($$key)) return $$key;
166 164
         }
167 165
 
168 166
         //middleware key odds
@@ -180,21 +178,21 @@  discard block
 block discarded – undo
180 178
      *
181 179
      * @param array $middleware
182 180
      */
183
-    public function serviceMiddleware($middleware=array())
181
+    public function serviceMiddleware($middleware = array())
184 182
     {
185 183
         $this->show = [];
186 184
 
187 185
         //It will be run individually according to the rules of
188 186
         //the middleware classes specified for the service middleware middleware.
189
-        foreach($middleware as $middleVal=>$middleKey){
187
+        foreach ($middleware as $middleVal=>$middleKey) {
190 188
 
191 189
             // if the keys in the array in the service middleware class represent a class,
192 190
             // this value is checked, if it does not represent the class,
193 191
             // it is detected as a short name and is searched in the middleware directory.
194
-            if(Utils::isNamespaceExists($middleVal)){
192
+            if (Utils::isNamespaceExists($middleVal)) {
195 193
                 $middlewareNamespace = $middleVal;
196 194
             }
197
-            else{
195
+            else {
198 196
                 $middlewareNamespace = app()->namespace()->middleware().'\\'.ucfirst($middleVal);
199 197
             }
200 198
 
@@ -213,12 +211,12 @@  discard block
 block discarded – undo
213 211
             //it will be handled according to the following rule.
214 212
             //The exclude class will return a callback and allocate the result as bool to the exclude variable.
215 213
             //If the exclude variable is true then the middleware will be run.
216
-            $excludeClass->exclude($this->middleware,function($exclude) use ($middleVal){
214
+            $excludeClass->exclude($this->middleware, function($exclude) use ($middleVal){
217 215
 
218
-                if($exclude){
216
+                if ($exclude) {
219 217
 
220 218
                     //the condition of a specific statement to be handled
221
-                    if($this->checkNamespaceAndSpecificCondition()){
219
+                    if ($this->checkNamespaceAndSpecificCondition()) {
222 220
                         $this->pointer($middleVal);
223 221
 
224 222
                         //directly registered to the middleware name show property.
@@ -226,8 +224,8 @@  discard block
 block discarded – undo
226 224
 
227 225
                         // the middleware namespace must have handletraitcontract interface property.
228 226
                         // otherwise, middleware will not work.
229
-                        if(false === $this->app->runningInConsole()
230
-                            && $this->app->resolve($this->middleware['namespace']) instanceof HandleContracts){
227
+                        if (false===$this->app->runningInConsole()
228
+                            && $this->app->resolve($this->middleware['namespace']) instanceof HandleContracts) {
231 229
                             $this->app->resolve($this->middleware['namespace'])->handle();
232 230
                         }
233 231
                     }
@@ -243,10 +241,10 @@  discard block
 block discarded – undo
243 241
      * @param null $key
244 242
      * @param null $value
245 243
      */
246
-    public function setKeyOdds($key=null,$value=null)
244
+    public function setKeyOdds($key = null, $value = null)
247 245
     {
248 246
         //user-defined middleware constants.
249
-        if(!is_null($key) && !is_null($value)){
247
+        if (!is_null($key) && !is_null($value)) {
250 248
             $this->odds[$key] = $value;
251 249
         }
252 250
     }
@@ -263,13 +261,13 @@  discard block
 block discarded – undo
263 261
 
264 262
         // if the service middleware does not represent a class,
265 263
         // then in this case core support is assigned as a class service middleware.
266
-        if(Utils::isNamespaceExists($serviceMiddleware)===false){
264
+        if (Utils::isNamespaceExists($serviceMiddleware)===false) {
267 265
             $serviceMiddleware = ServiceMiddlewareManager::class;
268 266
         }
269 267
 
270 268
         //We are logging the kernel for the middleware class and the exclude class
271
-        $this->app->register('middlewareClass',$this->app->resolve($serviceMiddleware));
272
-        $this->app->register('excludeClass',$this->app->resolve(ExcludeMiddleware::class));
269
+        $this->app->register('middlewareClass', $this->app->resolve($serviceMiddleware));
270
+        $this->app->register('excludeClass', $this->app->resolve(ExcludeMiddleware::class));
273 271
     }
274 272
 
275 273
     /**
@@ -277,9 +275,9 @@  discard block
 block discarded – undo
277 275
      *
278 276
      * @param null $serviceMiddleware
279 277
      */
280
-    public function setserviceMiddleware($serviceMiddleware=null)
278
+    public function setserviceMiddleware($serviceMiddleware = null)
281 279
     {
282
-        if(!is_null($serviceMiddleware)){
280
+        if (!is_null($serviceMiddleware)) {
283 281
             $this->serviceMiddleware = $serviceMiddleware;
284 282
         }
285 283
     }
@@ -294,11 +292,11 @@  discard block
 block discarded – undo
294 292
     {
295 293
         //If the all option is present,
296 294
         //it is automatically injected into all services for the middleware application.
297
-        if($key==="all") return true;
295
+        if ($key==="all") return true;
298 296
 
299 297
         //service middleware key
300 298
         //if it is array,check odds
301
-        if(is_array($key)){
299
+        if (is_array($key)) {
302 300
 
303 301
             //get middleware odd keys
304 302
             $odds = $this->middlewareKeyOdds();
@@ -307,8 +305,8 @@  discard block
 block discarded – undo
307 305
             //then the middleware is conditioned and the services are individually checked according to
308 306
             //the degree of conformity with the middlewareOdds method and
309 307
             //the middleware is executed under the specified condition.
310
-            foreach($key as $item){
311
-                if(in_array($item,$odds)){
308
+            foreach ($key as $item) {
309
+                if (in_array($item, $odds)) {
312 310
                     return true;
313 311
                 }
314 312
             }
@@ -326,17 +324,17 @@  discard block
 block discarded – undo
326 324
      */
327 325
     private function pointer($middleValue)
328 326
     {
329
-        if(isset($this->app['pointer']['middlewareList'])){
327
+        if (isset($this->app['pointer']['middlewareList'])) {
330 328
 
331 329
             $middlewareList = $this->app['pointer']['middlewareList'];
332 330
 
333
-            if(is_array($middlewareList)){
334
-                $middlewareList = array_merge($middlewareList,[$middleValue]);
335
-                $this->app->register('pointer','middlewareList',$middlewareList);
331
+            if (is_array($middlewareList)) {
332
+                $middlewareList = array_merge($middlewareList, [$middleValue]);
333
+                $this->app->register('pointer', 'middlewareList', $middlewareList);
336 334
             }
337 335
         }
338
-        else{
339
-            $this->app->register('pointer','middlewareList',[$middleValue]);
336
+        else {
337
+            $this->app->register('pointer', 'middlewareList', [$middleValue]);
340 338
         }
341 339
     }
342 340
 }
343 341
\ No newline at end of file
Please login to merge, or discard this patch.