Passed
Push — master ( 769a42...f90141 )
by Sinnarasa
04:20
created
src/Routing/RouteCollection.php 1 patch
Spacing   +25 added lines, -25 removed lines patch added patch discarded remove patch
@@ -43,12 +43,12 @@  discard block
 block discarded – undo
43 43
     public function addRoutes($routes = null, $options = [])
44 44
     {
45 45
         if (!is_null($routes) && !is_array($routes)) {
46
-            if (strpos($routes, '.php') === false) $routes = trim($routes, '/') . '/';
47
-            if (is_file($routes . '/routes.php') && is_array($routesFile = include $routes . '/routes.php')) $routes = $routesFile;
46
+            if (strpos($routes, '.php') === false) $routes = trim($routes, '/').'/';
47
+            if (is_file($routes.'/routes.php') && is_array($routesFile = include $routes.'/routes.php')) $routes = $routesFile;
48 48
             elseif (is_file($routes) && is_array($routesFile = include $routes)) $routes = $routesFile;
49
-            else throw new \InvalidArgumentException('Argument for "' . get_called_class() . '" constructor is not recognized. Expected argument array or file containing array but "' . $routes . '" given');
49
+            else throw new \InvalidArgumentException('Argument for "'.get_called_class().'" constructor is not recognized. Expected argument array or file containing array but "'.$routes.'" given');
50 50
         }
51
-        $this->routes['routes_' . $this->countRoutes] = is_array($routes) ? $routes : [];
51
+        $this->routes['routes_'.$this->countRoutes] = is_array($routes) ? $routes : [];
52 52
         $this->setRoutes($options, $this->countRoutes);
53 53
         $this->countRoutes++;
54 54
     }
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
         if (is_array($args)) {
73 73
             $nbrArgs = count($args);
74 74
             for ($i = 0; $i < $nbrArgs; ++$i)
75
-                $this->routes['prefix_' . $i] = '/' . trim($args[$i], '/');
75
+                $this->routes['prefix_'.$i] = '/'.trim($args[$i], '/');
76 76
         } elseif (is_string($args))
77 77
             for ($i = 0; $i < $this->countRoutes; ++$i)
78
-                $this->routes['prefix_' . $i] = '/' . trim($args, '/');
78
+                $this->routes['prefix_'.$i] = '/'.trim($args, '/');
79 79
         if ($this->countRoutes == 0) $this->countRoutes++;
80 80
     }
81 81
 
@@ -88,7 +88,7 @@  discard block
 block discarded – undo
88 88
         for ($i = 0; $i < $nbrArgs; ++$i) {
89 89
             if (is_array($args[$i])) {
90 90
                 $this->setRoutes($args[$i], $i);
91
-                if (!isset($this->routes['routes_' . $i])) $this->routes['routes_' . $i] = [];
91
+                if (!isset($this->routes['routes_'.$i])) $this->routes['routes_'.$i] = [];
92 92
             }
93 93
         }
94 94
         if ($this->countRoutes == 0) $this->countRoutes++;
@@ -100,11 +100,11 @@  discard block
 block discarded – undo
100 100
      */
101 101
     private function setRoutes($args = [], $i)
102 102
     {
103
-        $this->routes['block_' . $i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/') . '/' : '';
104
-        $this->routes['view_dir_' . $i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/') . '/' : '';
105
-        $this->routes['ctrl_namespace_' . $i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\') . '\\' : '';
106
-        $this->routes['prefix_' . $i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/' . trim($args['prefix'], '/') : '';
107
-        $this->routes['subdomain_' . $i] = (isset($args['subdomain'])) ? $args['subdomain'] : '';
103
+        $this->routes['block_'.$i] = (isset($args['block']) && !empty($args['block'])) ? rtrim($args['block'], '/').'/' : '';
104
+        $this->routes['view_dir_'.$i] = (isset($args['view_dir']) && !empty($args['view_dir'])) ? rtrim($args['view_dir'], '/').'/' : '';
105
+        $this->routes['ctrl_namespace_'.$i] = (isset($args['ctrl_namespace']) && !empty($args['ctrl_namespace'])) ? trim($args['ctrl_namespace'], '\\').'\\' : '';
106
+        $this->routes['prefix_'.$i] = (isset($args['prefix']) && !empty($args['prefix'])) ? '/'.trim($args['prefix'], '/') : '';
107
+        $this->routes['subdomain_'.$i] = (isset($args['subdomain'])) ? $args['subdomain'] : '';
108 108
     }
109 109
 
110 110
     /**
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
         $protocol = isset($_SERVER['REQUEST_SCHEME']) ? $_SERVER['REQUEST_SCHEME'] : $protocol;
119 119
         $domain = isset($_SERVER['SERVER_NAME']) ? $_SERVER['SERVER_NAME'] : null;
120 120
         $root = (is_null($root))
121
-            ? $protocol . '://' . $domain . ((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':' . $_SERVER['SERVER_PORT'] : '') . str_replace('/' . $script_file, '', $_SERVER['SCRIPT_NAME'])
121
+            ? $protocol.'://'.$domain.((!empty($_SERVER['SERVER_PORT']) && $_SERVER['SERVER_PORT'] != 80) ? ':'.$_SERVER['SERVER_PORT'] : '').str_replace('/'.$script_file, '', $_SERVER['SCRIPT_NAME'])
122 122
             : $root;
123 123
         $new_domain = $this->getDomain($root);
124 124
         if (!is_null($domain) && strpos($domain, $new_domain) !== false) {
@@ -126,27 +126,27 @@  discard block
 block discarded – undo
126 126
         }
127 127
         $count = 0;
128 128
         for ($i = 0; $i < $this->countRoutes; ++$i) {
129
-            $prefix = (isset($this->routes['prefix_' . $i])) ? $this->routes['prefix_' . $i] : '';
130
-            $subdomain = (isset($this->routes['subdomain_' . $i])) ? $this->routes['subdomain_' . $i] : '';
131
-            $url = (!empty($subdomain)) ? str_replace($protocol.'://',$protocol.'://'.$subdomain.'.' ,$root) : $root;
132
-            if (isset($this->routes['routes_' . $i]))
133
-                foreach ($this->routes['routes_' . $i] as $route => $dependencies) {
129
+            $prefix = (isset($this->routes['prefix_'.$i])) ? $this->routes['prefix_'.$i] : '';
130
+            $subdomain = (isset($this->routes['subdomain_'.$i])) ? $this->routes['subdomain_'.$i] : '';
131
+            $url = (!empty($subdomain)) ? str_replace($protocol.'://', $protocol.'://'.$subdomain.'.', $root) : $root;
132
+            if (isset($this->routes['routes_'.$i]))
133
+                foreach ($this->routes['routes_'.$i] as $route => $dependencies) {
134 134
                     if (is_array($dependencies) && isset($dependencies['use']) && !is_array($dependencies['use'])) {
135
-                        $use = (is_callable($dependencies['use'])) ? 'closure-' . $count : trim($dependencies['use'], '/');
135
+                        $use = (is_callable($dependencies['use'])) ? 'closure-'.$count : trim($dependencies['use'], '/');
136 136
                     } elseif (!is_array($dependencies)) {
137
-                        $use = (is_callable($dependencies)) ? 'closure-' . $count : trim($dependencies, '/');
137
+                        $use = (is_callable($dependencies)) ? 'closure-'.$count : trim($dependencies, '/');
138 138
                     } else {
139 139
                         $use = $route;
140 140
                     }
141 141
                     if (isset($route[0]) && $route[0] == '/') {
142
-                        $full_url = rtrim($url, '/') . '/' . trim($prefix, '/') . '/' . ltrim($route, '/');
142
+                        $full_url = rtrim($url, '/').'/'.trim($prefix, '/').'/'.ltrim($route, '/');
143 143
                         (!is_callable($dependencies) && isset($dependencies['name']))
144
-                            ? $this->routesByName[$use . '#' . $dependencies['name']] = $full_url
144
+                            ? $this->routesByName[$use.'#'.$dependencies['name']] = $full_url
145 145
                             : $this->routesByName[$use] = $full_url;
146 146
                     } else {
147 147
                         (!is_callable($dependencies) && isset($dependencies['name']))
148
-                            ? $this->routesByName[$use . '#' . $dependencies['name']] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix
149
-                            : $this->routesByName[$use] = $protocol . '://' . str_replace('{host}', $new_domain, $route) . $prefix;
148
+                            ? $this->routesByName[$use.'#'.$dependencies['name']] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix
149
+                            : $this->routesByName[$use] = $protocol.'://'.str_replace('{host}', $new_domain, $route).$prefix;
150 150
                     }
151 151
                     $count++;
152 152
                 }
@@ -179,7 +179,7 @@  discard block
 block discarded – undo
179 179
         foreach ($this->routesByName as $key => $route) {
180 180
             $param = explode('#', $key);
181 181
             $route = str_replace('{subdomain}', $subdomain, $route);
182
-            foreach ($params as $key2 => $value) $route = str_replace(':' . $key2, $value, $route);
182
+            foreach ($params as $key2 => $value) $route = str_replace(':'.$key2, $value, $route);
183 183
             if ($param[0] == trim($name, '/')) return $route;
184 184
             else if (isset($param[1]) && $param[1] == $name) return $route;
185 185
         }
Please login to merge, or discard this patch.