Passed
Push — master ( 66da72...5cd9b7 )
by Sinnarasa
02:50
created
src/Routing/Response.php 2 patches
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -166,8 +166,9 @@
 block discarded – undo
166 166
      */
167 167
     public function sendHeaders()
168 168
     {
169
-        foreach($this->headers as $key => $content)
170
-            header($key.' : '.$content);
169
+        foreach($this->headers as $key => $content) {
170
+                    header($key.' : '.$content);
171
+        }
171 172
         http_response_code($this->getStatusCode());
172 173
         return $this;
173 174
     }
Please login to merge, or discard this patch.
Spacing   +21 added lines, -21 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * Class Response
8 8
  * @package JetFire\Routing
9 9
  */
10
-class Response implements ResponseInterface{
10
+class Response implements ResponseInterface {
11 11
 
12 12
     /**
13 13
      * @var array
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
     public static $statusTexts = array(
54 54
         100 => 'Continue',
55 55
         101 => 'Switching Protocols',
56
-        102 => 'Processing',            // RFC2518
56
+        102 => 'Processing', // RFC2518
57 57
         200 => 'OK',
58 58
         201 => 'Created',
59 59
         202 => 'Accepted',
@@ -61,9 +61,9 @@  discard block
 block discarded – undo
61 61
         204 => 'No Content',
62 62
         205 => 'Reset Content',
63 63
         206 => 'Partial Content',
64
-        207 => 'Multi-Status',          // RFC4918
65
-        208 => 'Already Reported',      // RFC5842
66
-        226 => 'IM Used',               // RFC3229
64
+        207 => 'Multi-Status', // RFC4918
65
+        208 => 'Already Reported', // RFC5842
66
+        226 => 'IM Used', // RFC3229
67 67
         300 => 'Multiple Choices',
68 68
         301 => 'Moved Permanently',
69 69
         302 => 'Found',
@@ -71,7 +71,7 @@  discard block
 block discarded – undo
71 71
         304 => 'Not Modified',
72 72
         305 => 'Use Proxy',
73 73
         307 => 'Temporary Redirect',
74
-        308 => 'Permanent Redirect',    // RFC7238
74
+        308 => 'Permanent Redirect', // RFC7238
75 75
         400 => 'Bad Request',
76 76
         401 => 'Unauthorized',
77 77
         402 => 'Payment Required',
@@ -90,26 +90,26 @@  discard block
 block discarded – undo
90 90
         415 => 'Unsupported Media Type',
91 91
         416 => 'Range Not Satisfiable',
92 92
         417 => 'Expectation Failed',
93
-        418 => 'I\'m a teapot',                                               // RFC2324
94
-        422 => 'Unprocessable Entity',                                        // RFC4918
95
-        423 => 'Locked',                                                      // RFC4918
96
-        424 => 'Failed Dependency',                                           // RFC4918
97
-        425 => 'Reserved for WebDAV advanced collections expired proposal',   // RFC2817
98
-        426 => 'Upgrade Required',                                            // RFC2817
99
-        428 => 'Precondition Required',                                       // RFC6585
100
-        429 => 'Too Many Requests',                                           // RFC6585
101
-        431 => 'Request Header Fields Too Large',                             // RFC6585
93
+        418 => 'I\'m a teapot', // RFC2324
94
+        422 => 'Unprocessable Entity', // RFC4918
95
+        423 => 'Locked', // RFC4918
96
+        424 => 'Failed Dependency', // RFC4918
97
+        425 => 'Reserved for WebDAV advanced collections expired proposal', // RFC2817
98
+        426 => 'Upgrade Required', // RFC2817
99
+        428 => 'Precondition Required', // RFC6585
100
+        429 => 'Too Many Requests', // RFC6585
101
+        431 => 'Request Header Fields Too Large', // RFC6585
102 102
         500 => 'Internal Server Error',
103 103
         501 => 'Not Implemented',
104 104
         502 => 'Bad Gateway',
105 105
         503 => 'Service Unavailable',
106 106
         504 => 'Gateway Timeout',
107 107
         505 => 'HTTP Version Not Supported',
108
-        506 => 'Variant Also Negotiates (Experimental)',                      // RFC2295
109
-        507 => 'Insufficient Storage',                                        // RFC4918
110
-        508 => 'Loop Detected',                                               // RFC5842
111
-        510 => 'Not Extended',                                                // RFC2774
112
-        511 => 'Network Authentication Required',                             // RFC6585
108
+        506 => 'Variant Also Negotiates (Experimental)', // RFC2295
109
+        507 => 'Insufficient Storage', // RFC4918
110
+        508 => 'Loop Detected', // RFC5842
111
+        510 => 'Not Extended', // RFC2774
112
+        511 => 'Network Authentication Required', // RFC6585
113 113
     );
114 114
 
115 115
     /**
@@ -166,7 +166,7 @@  discard block
 block discarded – undo
166 166
      */
167 167
     public function sendHeaders()
168 168
     {
169
-        foreach($this->headers as $key => $content)
169
+        foreach ($this->headers as $key => $content)
170 170
             header($key.' : '.$content);
171 171
         http_response_code($this->getStatusCode());
172 172
         return $this;
Please login to merge, or discard this patch.
src/Routing/Route.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function setDetail($detail)
129 129
     {
130
-        $this->detail = array_merge($detail,$this->detail);
130
+        $this->detail = array_merge($detail, $this->detail);
131 131
     }
132 132
 
133 133
     /**
@@ -173,8 +173,8 @@  discard block
 block discarded – undo
173 173
     /**
174 174
      * @return array
175 175
      */
176
-    public function getData(){
177
-        return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data']))?$this->getDetail()['data']:[];
176
+    public function getData() {
177
+        return (isset($this->getDetail()['data']) && is_array($this->getDetail()['data'])) ? $this->getDetail()['data'] : [];
178 178
     }
179 179
 
180 180
     /**
Please login to merge, or discard this patch.
Braces   +18 added lines, -8 removed lines patch added patch discarded remove patch
@@ -52,10 +52,18 @@  discard block
 block discarded – undo
52 52
      */
53 53
     public function set($args = [])
54 54
     {
55
-        if (isset($args['name'])) $this->name = $args['name'];
56
-        if (isset($args['callback'])) $this->callback = $args['callback'];
57
-        if (isset($args['target'])) $this->target = $args['target'];
58
-        if (isset($args['detail'])) $this->detail = $args['detail'];
55
+        if (isset($args['name'])) {
56
+            $this->name = $args['name'];
57
+        }
58
+        if (isset($args['callback'])) {
59
+            $this->callback = $args['callback'];
60
+        }
61
+        if (isset($args['target'])) {
62
+            $this->target = $args['target'];
63
+        }
64
+        if (isset($args['detail'])) {
65
+            $this->detail = $args['detail'];
66
+        }
59 67
     }
60 68
 
61 69
     /**
@@ -145,8 +153,9 @@  discard block
 block discarded – undo
145 153
      */
146 154
     public function getTarget($key = null)
147 155
     {
148
-        if (!is_null($key))
149
-            return isset($this->target[$key]) ? $this->target[$key] : '';
156
+        if (!is_null($key)) {
157
+                    return isset($this->target[$key]) ? $this->target[$key] : '';
158
+        }
150 159
         return empty($this->target) ? '' : $this->target;
151 160
     }
152 161
 
@@ -165,8 +174,9 @@  discard block
 block discarded – undo
165 174
      */
166 175
     public function hasTarget($key = null)
167 176
     {
168
-        if (!is_null($key))
169
-            return isset($this->target[$key]) ? true : false;
177
+        if (!is_null($key)) {
178
+                    return isset($this->target[$key]) ? true : false;
179
+        }
170 180
         return empty($this->target) ? false : true;
171 181
     }
172 182
 
Please login to merge, or discard this patch.
src/Routing/Matcher/UriMatcher.php 3 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@
 block discarded – undo
83 83
     }
84 84
 
85 85
     /**
86
-     * @return bool
86
+     * @return null|boolean
87 87
      */
88 88
     public function match()
89 89
     {
Please login to merge, or discard this patch.
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -90,8 +90,9 @@
 block discarded – undo
90 90
         foreach($this->resolver as $resolver){
91 91
             if(is_array($target = call_user_func([$this,$resolver]))) {
92 92
                 $this->setTarget($target);
93
-                if($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
94
-                    return null;
93
+                if($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false) {
94
+                                    return null;
95
+                }
95 96
                 $this->router->response->setStatusCode(202);
96 97
                 return true;
97 98
             }
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -32,7 +32,7 @@  discard block
 block discarded – undo
32 32
     private $dispatcher = [
33 33
         'isTemplate' => 'JetFire\Routing\Dispatcher\TemplateDispatcher',
34 34
         'isController' => 'JetFire\Routing\Dispatcher\ControllerDispatcher',
35
-        'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher','JetFire\Routing\Dispatcher\TemplateDispatcher'],
35
+        'isControllerAndTemplate' => ['JetFire\Routing\Dispatcher\ControllerDispatcher', 'JetFire\Routing\Dispatcher\TemplateDispatcher'],
36 36
     ];
37 37
 
38 38
     /**
@@ -46,14 +46,14 @@  discard block
 block discarded – undo
46 46
     /**
47 47
      * @param array $resolver
48 48
      */
49
-    public function setResolver($resolver = []){
49
+    public function setResolver($resolver = []) {
50 50
         $this->resolver = $resolver;
51 51
     }
52 52
 
53 53
     /**
54 54
      * @param string $resolver
55 55
      */
56
-    public function addResolver($resolver){
56
+    public function addResolver($resolver) {
57 57
         $this->resolver[] = $resolver;
58 58
     }
59 59
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
      * @param $method
78 78
      * @param $class
79 79
      */
80
-    public function addDispatcher($method,$class){
80
+    public function addDispatcher($method, $class) {
81 81
         $this->dispatcher[$method] = $class;
82 82
     }
83 83
 
@@ -86,10 +86,10 @@  discard block
 block discarded – undo
86 86
      */
87 87
     public function match()
88 88
     {
89
-        foreach($this->resolver as $resolver){
90
-            if(is_array($target = call_user_func([$this,$resolver]))) {
89
+        foreach ($this->resolver as $resolver) {
90
+            if (is_array($target = call_user_func([$this, $resolver]))) {
91 91
                 $this->setTarget($target);
92
-                if($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
92
+                if ($this->router->middleware->globalMiddleware() === false || $this->router->middleware->blockMiddleware() === false || $this->router->middleware->classMiddleware() === false || $this->router->middleware->routeMiddleware() === false)
93 93
                     return null;
94 94
                 $this->router->response->setStatusCode(202);
95 95
                 return true;
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
     /**
102 102
      * @param array $target
103 103
      */
104
-    public function setTarget($target = []){
104
+    public function setTarget($target = []) {
105 105
         $index = isset($this->request['collection_index']) ? $this->request['collection_index'] : 0;
106 106
         $this->router->route->setDetail($this->request);
107 107
         $this->router->route->setTarget($target);
@@ -112,10 +112,10 @@  discard block
 block discarded – undo
112 112
     /**
113 113
      * @return array|bool
114 114
      */
115
-    public function isControllerAndTemplate(){
116
-        if(is_array($ctrl = $this->isController())) {
115
+    public function isControllerAndTemplate() {
116
+        if (is_array($ctrl = $this->isController())) {
117 117
             if (is_array($tpl = $this->isTemplate())) {
118
-                return array_merge(array_merge($ctrl, $tpl),[
118
+                return array_merge(array_merge($ctrl, $tpl), [
119 119
                     'dispatcher' => $this->dispatcher['isControllerAndTemplate']
120 120
                 ]);
121 121
             }
@@ -131,10 +131,10 @@  discard block
 block discarded – undo
131 131
     {
132 132
         foreach ($this->router->getConfig()['templateExtension'] as $extension) {
133 133
             for ($i = 0; $i < $this->router->collection->countRoutes; ++$i) {
134
-                $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_' . $i), '',$this->router->route->getUrl()));
134
+                $url = explode('/', str_replace($this->router->collection->getRoutes('prefix_'.$i), '', $this->router->route->getUrl()));
135 135
                 $end = array_pop($url);
136 136
                 $url = implode('/', array_map('ucwords', $url)).'/'.$end;
137
-                if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_' . $i), '/') . $url . $extension))) {
137
+                if (is_file(($template = rtrim($this->router->collection->getRoutes('view_dir_'.$i), '/').$url.$extension))) {
138 138
                     $this->request['collection_index'] = $i;
139 139
                     return [
140 140
                         'dispatcher' => $this->dispatcher['isTemplate'],
@@ -155,13 +155,13 @@  discard block
 block discarded – undo
155 155
     {
156 156
         $routes = array_slice(explode('/', $this->router->route->getUrl()), 1);
157 157
         $i = 0;
158
-        do{
159
-            $route =  ('/' . $routes[0] == $this->router->collection->getRoutes('prefix_' . $i)) ? array_slice($routes, 1) : $routes;
158
+        do {
159
+            $route = ('/'.$routes[0] == $this->router->collection->getRoutes('prefix_'.$i)) ? array_slice($routes, 1) : $routes;
160 160
             if (isset($route[0])) {
161
-                $class =  (class_exists($this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller'))
162
-                    ? $this->router->collection->getRoutes('ctrl_namespace_' . $i). ucfirst($route[0]) . 'Controller'
163
-                    : ucfirst($route[0]) . 'Controller';
164
-                $route[1] = isset($route[1])?$route[1]:'index';
161
+                $class = (class_exists($this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller'))
162
+                    ? $this->router->collection->getRoutes('ctrl_namespace_'.$i).ucfirst($route[0]).'Controller'
163
+                    : ucfirst($route[0]).'Controller';
164
+                $route[1] = isset($route[1]) ? $route[1] : 'index';
165 165
                 if (method_exists($class, $route[1])) {
166 166
                     $this->request['parameters'] = array_slice($route, 2);
167 167
                     $this->request['collection_index'] = $i;
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
                 }
175 175
             }
176 176
             ++$i;
177
-        }while($i < $this->router->collection->countRoutes);
177
+        }while ($i < $this->router->collection->countRoutes);
178 178
         return false;
179 179
     }
180 180
 
Please login to merge, or discard this patch.
src/Routing/Middleware.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,7 +46,7 @@  discard block
 block discarded – undo
46 46
                 if (is_array($blocks)) {
47 47
                     foreach ($blocks as $block)
48 48
                         if (class_exists($block))
49
-                            if($this->callHandler($block) === false) return false;
49
+                            if ($this->callHandler($block) === false) return false;
50 50
                 }
51 51
                 elseif (is_string($blocks) && class_exists($blocks))
52 52
                     return $this->callHandler($blocks);
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
             $ctrl = str_replace('\\', '/', $this->router->route->getTarget('controller'));
64 64
             if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) {
65 65
                 $classes = $this->router->collection->middleware['class_middleware'][$ctrl];
66
-                if(is_array($classes)){
66
+                if (is_array($classes)) {
67 67
                     foreach ($classes as $class)
68
-                        if($this->callHandler($class) === false)return false;
69
-                }elseif(is_string($classes))
68
+                        if ($this->callHandler($class) === false)return false;
69
+                }elseif (is_string($classes))
70 70
                     return $this->callHandler($classes);
71 71
             }
72 72
         }
@@ -81,10 +81,10 @@  discard block
 block discarded – undo
81 81
         if (isset($this->router->collection->middleware['route_middleware']))
82 82
             if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
83 83
                 $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
84
-                if(is_array($classes)){
84
+                if (is_array($classes)) {
85 85
                     foreach ($classes as $class)
86
-                        if($this->callHandler($class) === false)return false;
87
-                }elseif(is_string($classes))
86
+                        if ($this->callHandler($class) === false)return false;
87
+                }elseif (is_string($classes))
88 88
                     return $this->callHandler($classes);
89 89
             }
90 90
         return null;
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
      * @param $class
95 95
      * @return mixed
96 96
      */
97
-    private function callHandler($class){
98
-        $instance = call_user_func($this->router->getConfig()['di'],$class);
97
+    private function callHandler($class) {
98
+        $instance = call_user_func($this->router->getConfig()['di'], $class);
99 99
         if (method_exists($instance, 'handle')) {
100 100
             $reflectionMethod = new ReflectionMethod($instance, 'handle');
101 101
             $dependencies = [];
@@ -112,8 +112,8 @@  discard block
 block discarded – undo
112 112
      * @param $class
113 113
      * @return Route|RouteCollection|Router|mixed
114 114
      */
115
-    private function getClass($class){
116
-        switch($class){
115
+    private function getClass($class) {
116
+        switch ($class) {
117 117
             case 'JetFire\Routing\Route':
118 118
                 return $this->router->route;
119 119
             case 'JetFire\Routing\Router':
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
             case 'JetFire\Routing\RouteCollection':
122 122
                 return $this->router->collection;
123 123
             default:
124
-                return call_user_func_array($this->router->getConfig()['di'],[$class]);
124
+                return call_user_func_array($this->router->getConfig()['di'], [$class]);
125 125
         }
126 126
     }
127 127
 }
Please login to merge, or discard this patch.
Braces   +35 added lines, -26 removed lines patch added patch discarded remove patch
@@ -29,9 +29,10 @@  discard block
 block discarded – undo
29 29
      */
30 30
     public function globalMiddleware()
31 31
     {
32
-        if (isset($this->router->collection->middleware['global_middleware']))
33
-            foreach ($this->router->collection->middleware['global_middleware'] as $class)
34
-                if (class_exists($class)) return $this->callHandler($class);
32
+        if (isset($this->router->collection->middleware['global_middleware'])) {
33
+                    foreach ($this->router->collection->middleware['global_middleware'] as $class)
34
+                if (class_exists($class)) return $this->callHandler($class);
35
+        }
35 36
         return null;
36 37
     }
37 38
 
@@ -40,16 +41,18 @@  discard block
 block discarded – undo
40 41
      */
41 42
     public function blockMiddleware()
42 43
     {
43
-        if (isset($this->router->collection->middleware['block_middleware']))
44
-            if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')])) {
45
-                $blocks = $this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')];
44
+        if (isset($this->router->collection->middleware['block_middleware'])) {
45
+                    if (isset($this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')])) {
46
+                $blocks = $this->router->collection->middleware['block_middleware'][$this->router->route->getTarget('block')];
47
+        }
46 48
                 if (is_array($blocks)) {
47
-                    foreach ($blocks as $block)
48
-                        if (class_exists($block))
49
-                            if($this->callHandler($block) === false) return false;
50
-                }
51
-                elseif (is_string($blocks) && class_exists($blocks))
52
-                    return $this->callHandler($blocks);
49
+                    foreach ($blocks as $block) {
50
+                                            if (class_exists($block))
51
+                            if($this->callHandler($block) === false) return false;
52
+                    }
53
+                } elseif (is_string($blocks) && class_exists($blocks)) {
54
+                                    return $this->callHandler($blocks);
55
+                }
53 56
             }
54 57
         return null;
55 58
     }
@@ -64,10 +67,12 @@  discard block
 block discarded – undo
64 67
             if (isset($this->router->collection->middleware['class_middleware'][$ctrl]) && class_exists($this->router->route->getTarget('controller'))) {
65 68
                 $classes = $this->router->collection->middleware['class_middleware'][$ctrl];
66 69
                 if(is_array($classes)){
67
-                    foreach ($classes as $class)
68
-                        if($this->callHandler($class) === false)return false;
69
-                }elseif(is_string($classes))
70
-                    return $this->callHandler($classes);
70
+                    foreach ($classes as $class) {
71
+                                            if($this->callHandler($class) === false)return false;
72
+                    }
73
+                } elseif(is_string($classes)) {
74
+                                    return $this->callHandler($classes);
75
+                }
71 76
             }
72 77
         }
73 78
         return null;
@@ -78,14 +83,17 @@  discard block
 block discarded – undo
78 83
      */
79 84
     public function routeMiddleware()
80 85
     {
81
-        if (isset($this->router->collection->middleware['route_middleware']))
82
-            if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
83
-                $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
86
+        if (isset($this->router->collection->middleware['route_middleware'])) {
87
+                    if (isset($this->router->route->getPath()['middleware']) && class_exists($this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']])) {
88
+                $classes = $this->router->collection->middleware['route_middleware'][$this->router->route->getPath()['middleware']];
89
+        }
84 90
                 if(is_array($classes)){
85
-                    foreach ($classes as $class)
86
-                        if($this->callHandler($class) === false)return false;
87
-                }elseif(is_string($classes))
88
-                    return $this->callHandler($classes);
91
+                    foreach ($classes as $class) {
92
+                                            if($this->callHandler($class) === false)return false;
93
+                    }
94
+                } elseif(is_string($classes)) {
95
+                                    return $this->callHandler($classes);
96
+                }
89 97
             }
90 98
         return null;
91 99
     }
@@ -99,9 +107,10 @@  discard block
 block discarded – undo
99 107
         if (method_exists($instance, 'handle')) {
100 108
             $reflectionMethod = new ReflectionMethod($instance, 'handle');
101 109
             $dependencies = [];
102
-            foreach ($reflectionMethod->getParameters() as $arg)
103
-                if (!is_null($arg->getClass()))
104
-                    $dependencies[] = $this->getClass($arg->getClass()->name);
110
+            foreach ($reflectionMethod->getParameters() as $arg) {
111
+                            if (!is_null($arg->getClass()))
112
+                    $dependencies[] = $this->getClass($arg->getClass()->name);
113
+            }
105 114
             $dependencies = array_merge($dependencies, [$this->router->route]);
106 115
             return $reflectionMethod->invokeArgs($instance, $dependencies);
107 116
         }
Please login to merge, or discard this patch.
src/Routing/Dispatcher/TemplateDispatcher.php 1 patch
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -47,14 +47,19 @@
 block discarded – undo
47 47
      */
48 48
     public function call()
49 49
     {
50
-        if ($this->response->getStatusCode() == 202)
51
-            $this->setContentType($this->route->getTarget('extension'));
52
-        if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')]))
53
-            $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route]));
54
-        else {
50
+        if ($this->response->getStatusCode() == 202) {
51
+                    $this->setContentType($this->route->getTarget('extension'));
52
+        }
53
+        if (isset($this->route->getTarget('callback')[$this->route->getTarget('extension')])) {
54
+                    $this->response->setContent(call_user_func_array($this->route->getTarget('callback')[$this->route->getTarget('extension')], [$this->route]));
55
+        } else {
55 56
             ob_start();
56
-            if (isset($this->route->getTarget()['data'])) extract($this->route->getTarget('data'));
57
-            if (isset($this->route->getParams()['data'])) extract($this->route->getParams()['data']);
57
+            if (isset($this->route->getTarget()['data'])) {
58
+                extract($this->route->getTarget('data'));
59
+            }
60
+            if (isset($this->route->getParams()['data'])) {
61
+                extract($this->route->getParams()['data']);
62
+            }
58 63
             require($this->route->getTarget('template'));
59 64
             $this->response->setContent(ob_get_clean());
60 65
         }
Please login to merge, or discard this patch.
src/Routing/Dispatcher/ClosureDispatcher.php 1 patch
Braces   +5 added lines, -2 removed lines patch added patch discarded remove patch
@@ -43,8 +43,11 @@
 block discarded – undo
43 43
             $this->response->setHeaders(['Content-Type' => 'text/html']);
44 44
         }
45 45
         $params = ($this->route->getParameters() == '') ? [] : $this->route->getParameters();
46
-        if (is_array($content = call_user_func_array($this->route->getTarget('closure'), $params))) $this->route->addTarget('data', $content);
47
-        elseif (!is_null($content)) $this->response->setContent($content);
46
+        if (is_array($content = call_user_func_array($this->route->getTarget('closure'), $params))) {
47
+            $this->route->addTarget('data', $content);
48
+        } elseif (!is_null($content)) {
49
+            $this->response->setContent($content);
50
+        }
48 51
     }
49 52
 
50 53
 }
Please login to merge, or discard this patch.
src/Routing/Dispatcher/ControllerDispatcher.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -72,7 +72,7 @@
 block discarded – undo
72 72
     {
73 73
         $reflector = new ReflectionClass($this->route->getTarget('controller'));
74 74
         if (!$reflector->isInstantiable())
75
-            throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
75
+            throw new \Exception('Target ['.$this->route->getTarget('controller').'] is not instantiable.');
76 76
         $constructor = $reflector->getConstructor();
77 77
         if (is_null($constructor)) {
78 78
             $class = $this->route->getTarget('controller');
Please login to merge, or discard this patch.
Braces   +12 added lines, -7 removed lines patch added patch discarded remove patch
@@ -51,17 +51,21 @@  discard block
 block discarded – undo
51 51
 
52 52
         if ($count == count($this->route->getParameters()) || ($this->route->getParameters() == '' && $count == 0)) {
53 53
             $dependencies = array_merge($dependencies, ($this->route->getParameters() == '') ? [] : $this->route->getParameters());
54
-            if ($this->response->getStatusCode() == 202)
55
-                $this->response->setStatusCode(200);
54
+            if ($this->response->getStatusCode() == 202) {
55
+                            $this->response->setStatusCode(200);
56
+            }
56 57
             if (is_array($content = $reflectionMethod->invokeArgs($this->getController(), $dependencies))) {
57 58
                 $this->route->addTarget('data', $content);
58 59
                 if (isset($this->route->getParams()['ajax']) && $this->route->getParams()['ajax'] === true) {
59 60
                     $this->response->setContent(json_encode($content));
60 61
                     $this->response->setHeaders(['Content-Type' => 'application/json']);
61 62
                 }
62
-            } elseif (!is_null($content)) $this->response->setContent($content);
63
-        } else
64
-            $this->response->setStatusCode(404);
63
+            } elseif (!is_null($content)) {
64
+                $this->response->setContent($content);
65
+            }
66
+        } else {
67
+                    $this->response->setStatusCode(404);
68
+        }
65 69
     }
66 70
 
67 71
 
@@ -72,8 +76,9 @@  discard block
 block discarded – undo
72 76
     private function getController()
73 77
     {
74 78
         $reflector = new ReflectionClass($this->route->getTarget('controller'));
75
-        if (!$reflector->isInstantiable())
76
-            throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
79
+        if (!$reflector->isInstantiable()) {
80
+                    throw new \Exception('Target [' . $this->route->getTarget('controller') . '] is not instantiable.');
81
+        }
77 82
         $constructor = $reflector->getConstructor();
78 83
         if (is_null($constructor)) {
79 84
             $class = $this->route->getTarget('controller');
Please login to merge, or discard this patch.
src/Routing/Matcher/MatcherInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,7 @@
 block discarded – undo
41 41
      * @param $method
42 42
      * @param $class
43 43
      */
44
-    public function addDispatcher($method,$class);
44
+    public function addDispatcher($method, $class);
45 45
 
46 46
     /**
47 47
      * @return mixed
Please login to merge, or discard this patch.
src/Routing/RouteCollection.php 2 patches
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -47,12 +47,12 @@  discard block
 block discarded – undo
47 47
     public function addRoutes($routes = null, $options = [])
48 48
     {
49 49
         if (!is_null($routes) && !is_array($routes)) {
50
-            if (strpos($routes, '.php') === false) $routes = trim($routes, '/') . '/';
51
-            if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) $routes = $routesFile;
50
+            if (strpos($routes, '.php') === false) $routes = trim($routes, '/').'/';
51
+            if (is_file($routes.'/routes.php') && is_array($routesFile = include $routes.'/routes.php')) $routes = $routesFile;
52 52
             elseif (is_file($routes) && is_array($routesFile = include $routes)) $routes = $routesFile;
53
-            else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given');
53
+            else throw new \InvalidArgumentException('Argument for "'.get_called_class().'" constructor is not recognized. Expected argument array or file containing array but "'.$routes.'" given');
54 54
         }
55
-        $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : [];
55
+        $this->routes['routes_'.$this->countRoutes] = is_array($routes) ? $routes : [];
56 56
         $this->setRoutes($options, $this->countRoutes);
57 57
         $this->countRoutes++;
58 58
     }
@@ -76,10 +76,10 @@  discard block
 block discarded – undo
76 76
         if (is_array($args)) {
77 77
             $nbrArgs = count($args);
78 78
             for ($i = 0; $i < $nbrArgs; ++$i)
79
-                $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/');
79
+                $this->routes['prefix_'.$i] = '/'.trim($args[$i], '/');
80 80
         } elseif (is_string($args))
81 81
             for ($i = 0; $i < $this->countRoutes; ++$i)
82
-                $this->routes['prefix_' . $i] = '/' . trim($args, '/');
82
+                $this->routes['prefix_'.$i] = '/'.trim($args, '/');
83 83
         if ($this->countRoutes == 0) $this->countRoutes++;
84 84
     }
85 85
 
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
         for ($i = 0; $i < $nbrArgs; ++$i) {
93 93
             if (is_array($args[$i])) {
94 94
                 $this->setRoutes($args[$i], $i);
95
-                if (!isset($this->routes['routes_' . $i])) $this->routes['routes_' . $i] = [];
95
+                if (!isset($this->routes['routes_'.$i])) $this->routes['routes_'.$i] = [];
96 96
             }
97 97
         }
98 98
         if ($this->countRoutes == 0) $this->countRoutes++;
@@ -104,11 +104,11 @@  discard block
 block discarded – undo
104 104
      */
105 105
     private function setRoutes($args = [], $i)
106 106
     {
107
-        $this->routes['block_' . $i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/') . '/' : '';
108
-        $this->routes['view_dir_' . $i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/') . '/' : '';
109
-        $this->routes['ctrl_namespace_' . $i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\') . '\\' : '';
110
-        $this->routes['prefix_' . $i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/' . trim($args['prefix'], '/') : '';
111
-        $this->routes['subdomain_' . $i] = (isset($args['subdomain'])) ? $args['subdomain'] : '';
107
+        $this->routes['block_'.$i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/').'/' : '';
108
+        $this->routes['view_dir_'.$i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/').'/' : '';
109
+        $this->routes['ctrl_namespace_'.$i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\').'\\' : '';
110
+        $this->routes['prefix_'.$i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/'.trim($args['prefix'], '/') : '';
111
+        $this->routes['subdomain_'.$i] = (isset($args['subdomain'])) ? $args['subdomain'] : '';
112 112
     }
113 113
 
114 114
     /**
@@ -135,32 +135,32 @@  discard block
 block discarded – undo
135 135
         $protocol = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : 'http';
136 136
         $domain = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
137 137
         $root = (is_null($root))
138
-            ? $protocol . '://' . $domain . ((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/' . $script_file, '', $_SERVER['SCRIPT_NAME'])
138
+            ? $protocol.'://'.$domain.((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').str_replace('/'.$script_file, '', $_SERVER['SCRIPT_NAME'])
139 139
             : $root;
140 140
         $new_domain = $this->getDomain($root);
141 141
         if (!is_null($domain) && strpos($domain, $new_domain) !== false)
142 142
             $root = str_replace($domain, $new_domain, $root);
143 143
         $count = 0;
144 144
         for ($i = 0; $i < $this->countRoutes; ++$i) {
145
-            $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : '';
146
-            $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : '';
147
-            $url = (!empty($subdomain)) ? str_replace($protocol.'://',$protocol.'://'.$subdomain.'.' ,$root) : $root;
148
-            if (isset($this->routes['routes_' . $i]))
149
-                foreach ($this->routes['routes_' . $i] as $route => $dependencies) {
145
+            $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : '';
146
+            $subdomain = (isset($this->routes['subdomain_'.$i])) ? $this->routes['subdomain_'.$i] : '';
147
+            $url = (!empty($subdomain)) ? str_replace($protocol.'://', $protocol.'://'.$subdomain.'.', $root) : $root;
148
+            if (isset($this->routes['routes_'.$i]))
149
+                foreach ($this->routes['routes_'.$i] as $route => $dependencies) {
150 150
                     if (is_array($dependencies) && isset($dependencies['use']))
151
-                        $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/');
151
+                        $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/');
152 152
                     elseif (!is_array($dependencies))
153
-                        $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/');
153
+                        $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/');
154 154
                     else
155 155
                         $use = $route;
156 156
                     if (isset($route[0]) && $route[0] == '/') {
157 157
                         (!is_callable($dependencies) && isset($dependencies['name']))
158
-                            ? $this->routesByName[$use . '#' . $dependencies['name']] = $url . $prefix . $route
159
-                            : $this->routesByName[$use] = $url . $prefix . $route;
158
+                            ? $this->routesByName[$use.'#'.$dependencies['name']] = $url.$prefix.$route
159
+                            : $this->routesByName[$use] = $url.$prefix.$route;
160 160
                     } else {
161 161
                         (!is_callable($dependencies) && isset($dependencies['name']))
162
-                            ? $this->routesByName[$use . '#' . $dependencies['name']] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix
163
-                            : $this->routesByName[$use] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix;
162
+                            ? $this->routesByName[$use.'#'.$dependencies['name']] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix
163
+                            : $this->routesByName[$use] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix;
164 164
                     }
165 165
                     $count++;
166 166
                 }
@@ -193,7 +193,7 @@  discard block
 block discarded – undo
193 193
         foreach ($this->routesByName as $key => $route) {
194 194
             $param = explode('#', $key);
195 195
             $route = str_replace('{subdomain}', $subdomain, $route);
196
-            foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route);
196
+            foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route);
197 197
             if ($param[0] == trim($name, '/')) return $route;
198 198
             else if (isset($param[1]) && $param[1] == $name) return $route;
199 199
         }
Please login to merge, or discard this patch.
Braces   +63 added lines, -33 removed lines patch added patch discarded remove patch
@@ -37,7 +37,9 @@  discard block
 block discarded – undo
37 37
      */
38 38
     public function __construct($routes = null, $options = [])
39 39
     {
40
-        if (!is_null($routes) || !empty($options)) $this->addRoutes($routes, $options);
40
+        if (!is_null($routes) || !empty($options)) {
41
+            $this->addRoutes($routes, $options);
42
+        }
41 43
     }
42 44
 
43 45
     /**
@@ -47,10 +49,16 @@  discard block
 block discarded – undo
47 49
     public function addRoutes($routes = null, $options = [])
48 50
     {
49 51
         if (!is_null($routes) && !is_array($routes)) {
50
-            if (strpos($routes, '.php') === false) $routes = trim($routes, '/') . '/';
51
-            if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) $routes = $routesFile;
52
-            elseif (is_file($routes) && is_array($routesFile = include $routes)) $routes = $routesFile;
53
-            else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given');
52
+            if (strpos($routes, '.php') === false) {
53
+                $routes = trim($routes, '/') . '/';
54
+            }
55
+            if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) {
56
+                $routes = $routesFile;
57
+            } elseif (is_file($routes) && is_array($routesFile = include $routes)) {
58
+                $routes = $routesFile;
59
+            } else {
60
+                throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given');
61
+            }
54 62
         }
55 63
         $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : [];
56 64
         $this->setRoutes($options, $this->countRoutes);
@@ -63,8 +71,9 @@  discard block
 block discarded – undo
63 71
      */
64 72
     public function getRoutes($key = null)
65 73
     {
66
-        if (!is_null($key))
67
-            return isset($this->routes[$key]) ? $this->routes[$key] : '';
74
+        if (!is_null($key)) {
75
+                    return isset($this->routes[$key]) ? $this->routes[$key] : '';
76
+        }
68 77
         return $this->routes;
69 78
     }
70 79
 
@@ -75,12 +84,18 @@  discard block
 block discarded – undo
75 84
     {
76 85
         if (is_array($args)) {
77 86
             $nbrArgs = count($args);
78
-            for ($i = 0; $i < $nbrArgs; ++$i)
79
-                $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/');
80
-        } elseif (is_string($args))
81
-            for ($i = 0; $i < $this->countRoutes; ++$i)
82
-                $this->routes['prefix_' . $i] = '/' . trim($args, '/');
83
-        if ($this->countRoutes == 0) $this->countRoutes++;
87
+            for ($i = 0; $i < $nbrArgs; ++$i) {
88
+                            $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/');
89
+            }
90
+        } elseif (is_string($args)) {
91
+                    for ($i = 0;
92
+        }
93
+        $i < $this->countRoutes; ++$i) {
94
+                            $this->routes['prefix_' . $i] = '/' . trim($args, '/');
95
+            }
96
+        if ($this->countRoutes == 0) {
97
+            $this->countRoutes++;
98
+        }
84 99
     }
85 100
 
86 101
     /**
@@ -92,10 +107,14 @@  discard block
 block discarded – undo
92 107
         for ($i = 0; $i < $nbrArgs; ++$i) {
93 108
             if (is_array($args[$i])) {
94 109
                 $this->setRoutes($args[$i], $i);
95
-                if (!isset($this->routes['routes_' . $i])) $this->routes['routes_' . $i] = [];
110
+                if (!isset($this->routes['routes_' . $i])) {
111
+                    $this->routes['routes_' . $i] = [];
112
+                }
96 113
             }
97 114
         }
98
-        if ($this->countRoutes == 0) $this->countRoutes++;
115
+        if ($this->countRoutes == 0) {
116
+            $this->countRoutes++;
117
+        }
99 118
     }
100 119
 
101 120
     /**
@@ -117,12 +136,16 @@  discard block
 block discarded – undo
117 136
      */
118 137
     public function setMiddleware($middleware)
119 138
     {
120
-        if (is_string($middleware)) $middleware = rtrim($middleware, '/');
121
-        if (is_array($middleware))
122
-            $this->middleware = $middleware;
123
-        elseif (is_file($middleware) && is_array($mid = include $middleware))
124
-            $this->middleware = $mid;
125
-        else throw new \InvalidArgumentException('Accepted argument for setMiddleware are array and array file');
139
+        if (is_string($middleware)) {
140
+            $middleware = rtrim($middleware, '/');
141
+        }
142
+        if (is_array($middleware)) {
143
+                    $this->middleware = $middleware;
144
+        } elseif (is_file($middleware) && is_array($mid = include $middleware)) {
145
+                    $this->middleware = $mid;
146
+        } else {
147
+            throw new \InvalidArgumentException('Accepted argument for setMiddleware are array and array file');
148
+        }
126 149
     }
127 150
 
128 151
     /**
@@ -138,21 +161,23 @@  discard block
 block discarded – undo
138 161
             ? $protocol . '://' . $domain . ((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/' . $script_file, '', $_SERVER['SCRIPT_NAME'])
139 162
             : $root;
140 163
         $new_domain = $this->getDomain($root);
141
-        if (!is_null($domain) && strpos($domain, $new_domain) !== false)
142
-            $root = str_replace($domain, $new_domain, $root);
164
+        if (!is_null($domain) && strpos($domain, $new_domain) !== false) {
165
+                    $root = str_replace($domain, $new_domain, $root);
166
+        }
143 167
         $count = 0;
144 168
         for ($i = 0; $i < $this->countRoutes; ++$i) {
145 169
             $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : '';
146 170
             $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : '';
147 171
             $url = (!empty($subdomain)) ? str_replace($protocol.'://',$protocol.'://'.$subdomain.'.' ,$root) : $root;
148
-            if (isset($this->routes['routes_' . $i]))
149
-                foreach ($this->routes['routes_' . $i] as $route => $dependencies) {
172
+            if (isset($this->routes['routes_' . $i])) {
173
+                            foreach ($this->routes['routes_' . $i] as $route => $dependencies) {
150 174
                     if (is_array($dependencies) && isset($dependencies['use']))
151
-                        $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/');
152
-                    elseif (!is_array($dependencies))
153
-                        $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/');
154
-                    else
155
-                        $use = $route;
175
+                        $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/');
176
+            } elseif (!is_array($dependencies)) {
177
+                                            $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/');
178
+                    } else {
179
+                                            $use = $route;
180
+                    }
156 181
                     if (isset($route[0]) && $route[0] == '/') {
157 182
                         (!is_callable($dependencies) && isset($dependencies['name']))
158 183
                             ? $this->routesByName[$use . '#' . $dependencies['name']] = $url . $prefix . $route
@@ -193,9 +218,14 @@  discard block
 block discarded – undo
193 218
         foreach ($this->routesByName as $key => $route) {
194 219
             $param = explode('#', $key);
195 220
             $route = str_replace('{subdomain}', $subdomain, $route);
196
-            foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route);
197
-            if ($param[0] == trim($name, '/')) return $route;
198
-            else if (isset($param[1]) && $param[1] == $name) return $route;
221
+            foreach ($params as $key2 => $value) {
222
+                $route = str_replace(':' . $key2, $value, $route);
223
+            }
224
+            if ($param[0] == trim($name, '/')) {
225
+                return $route;
226
+            } else if (isset($param[1]) && $param[1] == $name) {
227
+                return $route;
228
+            }
199 229
         }
200 230
         return null;
201 231
     }
Please login to merge, or discard this patch.