Completed
Push — master ( 93721c...427d4b )
by Sinnarasa
04:49
created
src/Routing/Router.php 2 patches
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -46,13 +46,13 @@  discard block
 block discarded – undo
46 46
      * @param ResponseInterface $response
47 47
      * @param Route $route
48 48
      */
49
-    public function __construct(RouteCollection $collection,ResponseInterface $response = null,Route $route = null)
49
+    public function __construct(RouteCollection $collection, ResponseInterface $response = null, Route $route = null)
50 50
     {
51 51
         $this->collection = $collection;
52
-        $this->response = is_null($response)? new Response() : $response;
52
+        $this->response = is_null($response) ? new Response() : $response;
53 53
         $this->response->setStatusCode(404);
54
-        $this->route = is_null($route)? new Route() : $route;
55
-        $this->config['di'] = function($class){
54
+        $this->route = is_null($route) ? new Route() : $route;
55
+        $this->config['di'] = function($class) {
56 56
             return new $class;
57 57
         };
58 58
     }
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
     /**
77 77
      * @param string $matcher
78 78
      */
79
-    public function addMatcher($matcher){
79
+    public function addMatcher($matcher) {
80 80
         $this->config['matcher'][] = $matcher;
81 81
     }
82 82
 
@@ -123,7 +123,7 @@  discard block
 block discarded – undo
123 123
     public function callTarget()
124 124
     {
125 125
         $target = $this->route->getTarget('dispatcher');
126
-        if(!empty($target)) {
126
+        if (!empty($target)) {
127 127
             $this->dispatcher = new $target($this->route, $this->response);
128 128
             return call_user_func([$this->dispatcher, 'call']);
129 129
         }
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
     {
158 158
         if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) {
159 159
             $this->route->setCallback($this->route->getDetail()['response_templates'][$code]);
160
-            if(!isset($this->config['matcherInstance']))
160
+            if (!isset($this->config['matcherInstance']))
161 161
                 foreach ($this->config['matcher'] as $matcher)
162 162
                     $this->config['matcherInstance'][$matcher] = new $matcher($this);
163
-            foreach($this->config['matcherInstance'] as $instance) {
163
+            foreach ($this->config['matcherInstance'] as $instance) {
164 164
                 foreach (call_user_func([$instance, 'getMatcher']) as $match)
165
-                    if (call_user_func([$instance, $match])){ $this->callTarget(); break; }
165
+                    if (call_user_func([$instance, $match])) { $this->callTarget(); break; }
166 166
             }
167 167
             $this->response->setStatusCode($code);
168 168
         }
Please login to merge, or discard this patch.
Braces   +17 added lines, -10 removed lines patch added patch discarded remove patch
@@ -86,7 +86,9 @@  discard block
 block discarded – undo
86 86
     public function run()
87 87
     {
88 88
         $this->setUrl();
89
-        if ($this->config['generateRoutesPath']) $this->collection->generateRoutesPath();
89
+        if ($this->config['generateRoutesPath']) {
90
+            $this->collection->generateRoutesPath();
91
+        }
90 92
         if ($this->match()) {
91 93
             $this->handle();
92 94
             $this->callTarget();
@@ -99,8 +101,9 @@  discard block
 block discarded – undo
99 101
      */
100 102
     public function setUrl($url = null)
101 103
     {
102
-        if (is_null($url))
103
-            $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
104
+        if (is_null($url)) {
105
+                    $url = (isset($_GET['url'])) ? $_GET['url'] : substr(str_replace(str_replace('/index.php', '', $_SERVER['SCRIPT_NAME']), '', $_SERVER['REQUEST_URI']), 1);
106
+        }
104 107
         $this->route->setUrl('/' . trim(explode('?', $url)[0], '/'));
105 108
     }
106 109
 
@@ -111,8 +114,9 @@  discard block
 block discarded – undo
111 114
     {
112 115
         foreach ($this->config['matcher'] as $matcher) {
113 116
             $this->config['matcherInstance'][$matcher] = new $matcher($this);
114
-            if (call_user_func([$this->config['matcherInstance'][$matcher], 'match']))
115
-                return true;
117
+            if (call_user_func([$this->config['matcherInstance'][$matcher], 'match'])) {
118
+                            return true;
119
+            }
116 120
         }
117 121
         return false;
118 122
     }
@@ -157,12 +161,15 @@  discard block
 block discarded – undo
157 161
     {
158 162
         if (isset($this->route->getDetail()['response_templates']) && isset($this->route->getDetail()['response_templates'][$code = $this->response->getStatusCode()])) {
159 163
             $this->route->setCallback($this->route->getDetail()['response_templates'][$code]);
160
-            if(!isset($this->config['matcherInstance']))
161
-                foreach ($this->config['matcher'] as $matcher)
162
-                    $this->config['matcherInstance'][$matcher] = new $matcher($this);
164
+            if(!isset($this->config['matcherInstance'])) {
165
+                            foreach ($this->config['matcher'] as $matcher)
166
+                    $this->config['matcherInstance'][$matcher] = new $matcher($this);
167
+            }
163 168
             foreach($this->config['matcherInstance'] as $instance) {
164
-                foreach (call_user_func([$instance, 'getMatcher']) as $match)
165
-                    if (call_user_func([$instance, $match])){ $this->callTarget(); break; }
169
+                foreach (call_user_func([$instance, 'getMatcher']) as $match) {
170
+                                    if (call_user_func([$instance, $match])){ $this->callTarget();
171
+                }
172
+                break; }
166 173
             }
167 174
             $this->response->setStatusCode($code);
168 175
         }
Please login to merge, or discard this patch.