Passed
Push — master ( 723c8d...5629e4 )
by Ch
02:31
created
Router.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 		$this->setRoutes($routes);
30 30
 		$this->setBasePath($basePath);
31 31
         $this->parser = $parser;
32
-		if(!$server) {
32
+		if (!$server) {
33 33
 			$this->server = $_SERVER;
34 34
 		}
35 35
     }
@@ -87,11 +87,11 @@  discard block
 block discarded – undo
87 87
 
88 88
 		foreach ($this->routes as $handler) {
89 89
 
90
-			if(!$this->parser->methodMatch($handler[0], $requestMethod, $handler[1], $requestUrl)) continue;
90
+			if (!$this->parser->methodMatch($handler[0], $requestMethod, $handler[1], $requestUrl)) continue;
91 91
 
92 92
 			return array(
93 93
                 'target' => $handler[2],
94
-                'params' => array_filter($this->parser->getParams(), function ($k) { return !is_numeric($k); }, ARRAY_FILTER_USE_KEY),
94
+                'params' => array_filter($this->parser->getParams(), function($k) { return !is_numeric($k); }, ARRAY_FILTER_USE_KEY),
95 95
                 'name'   => $handler[3]
96 96
             );
97 97
 		}
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
      */
107 107
     public function __call($method, $arguments)
108 108
 	{
109
-		if(!in_array($method, array('get', 'post', 'delete', 'put', 'patch', 'update', 'all'))) {
110
-			throw new RouterException($method . ' not exist in the '. __CLASS__);
109
+		if (!in_array($method, array('get', 'post', 'delete', 'put', 'patch', 'update', 'all'))) {
110
+			throw new RouterException($method . ' not exist in the ' . __CLASS__);
111 111
 		}
112 112
 
113 113
 		$methods = $method == 'all' ? implode('|', $this->all) : $method;
@@ -143,7 +143,7 @@  discard block
 block discarded – undo
143 143
         if (!is_array($routes) && !$routes instanceof Traversable) {
144 144
             throw new RouterException('Routes should be an array or an instance of Traversable');
145 145
         }
146
-        if(!empty($routes)) {
146
+        if (!empty($routes)) {
147 147
             foreach ($routes as $route) {
148 148
                 call_user_func_array(array($this, 'map'), $route);
149 149
             }
Please login to merge, or discard this patch.
RouterParser.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -81,11 +81,11 @@  discard block
 block discarded – undo
81 81
         $requestMethod = strtolower($requestMethod);
82 82
         $methods = explode('|', $method);
83 83
 
84
-        if(in_array($requestMethod, $methods)) {
85
-            if($routeString == '*') {
84
+        if (in_array($requestMethod, $methods)) {
85
+            if ($routeString == '*') {
86 86
                 return true;
87 87
             }
88
-            elseif(isset($routeString[0]) && $routeString[0] == '@') {
88
+            elseif (isset($routeString[0]) && $routeString[0] == '@') {
89 89
                 $match = preg_match('`' . substr($routeString, 1) . '`u', $requestUrl, $this->params);
90 90
                 return $match;
91 91
             }
@@ -160,7 +160,7 @@  discard block
 block discarded – undo
160 160
                 break;
161 161
             }
162 162
             if ($regex === false) {
163
-                if(!$this->getRouteRegexCheck($nPointer, $jPointer, $iPointer, $routeString, $requestUrl)) {
163
+                if (!$this->getRouteRegexCheck($nPointer, $jPointer, $iPointer, $routeString, $requestUrl)) {
164 164
                     continue;
165 165
                 }
166 166
                 $jPointer++;
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
     {
176 176
         $cPointer = $nPointer;
177 177
         $regex = in_array($cPointer, array('[', '(', '.'));
178
-        if (!$regex && isset($routeString[$iPointer+1])) {
178
+        if (!$regex && isset($routeString[$iPointer + 1])) {
179 179
             $nPointer = $routeString[$iPointer + 1];
180 180
             $regex = in_array($nPointer, array('?', '+', '*', '{'));
181 181
         }
Please login to merge, or discard this patch.
examples/basic/index.php 1 patch
Spacing   +9 added lines, -9 removed lines patch added patch discarded remove patch
@@ -11,10 +11,10 @@  discard block
 block discarded – undo
11 11
 $parser = new \HakimCh\Http\RouterParser();
12 12
 $router = new \HakimCh\Http\Router($parser);
13 13
 $router->setBasePath('/examples/basic');
14
-$router->map('GET|POST','/', 'home#index', 'home');
15
-$router->map('GET','/users/', array('c' => 'UserController', 'a' => 'ListAction'));
16
-$router->map('GET','/users/[i:id]', 'users#show', 'users_show');
17
-$router->map('POST','/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');
14
+$router->map('GET|POST', '/', 'home#index', 'home');
15
+$router->map('GET', '/users/', array('c' => 'UserController', 'a' => 'ListAction'));
16
+$router->map('GET', '/users/[i:id]', 'users#show', 'users_show');
17
+$router->map('POST', '/users/[i:id]/[delete|update:action]', 'usersController#doAction', 'users_do');
18 18
 $router->map('GET', '/foo/[:controller]/[:action]', 'foo_action', 'foo_route');
19 19
 
20 20
 // match current request
@@ -27,13 +27,13 @@  discard block
 block discarded – undo
27 27
 <h3>Current request: </h3>
28 28
 <pre>
29 29
      <?php
30
-     if($match) {
31
-         foreach($match as $key => $value) {
30
+     if ($match) {
31
+         foreach ($match as $key => $value) {
32 32
              echo '<p>' . $key . ': ';
33
-             if(is_array($value)) {
33
+             if (is_array($value)) {
34 34
                  echo '<ul>';
35
-                 foreach($value as $k => $v) {
36
-                     echo '<li>'.$k.': '.$v.'</li>';
35
+                 foreach ($value as $k => $v) {
36
+                     echo '<li>' . $k . ': ' . $v . '</li>';
37 37
                  }
38 38
                  echo '</ul>';
39 39
              }
Please login to merge, or discard this patch.