Passed
Push — master ( e8b00c...89139c )
by Anton
07:46
created
src/Router/tests/TestCore.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,6 +24,6 @@
 block discarded – undo
24 24
 
25 25
     public function callAction(string $controller, string $action = null, array $parameters = [])
26 26
     {
27
-        return '@wrapped.' . $this->core->callAction($controller, $action, $parameters);
27
+        return '@wrapped.'.$this->core->callAction($controller, $action, $parameters);
28 28
     }
29 29
 }
Please login to merge, or discard this patch.
src/Router/src/Target/Action.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function __construct(string $controller, $action, int $options = 0)
41 41
     {
42
-        if (!is_string($action) && !is_array($action)) {
42
+        if (!is_string($action) && !is_array($action)){
43 43
             throw new InvalidArgumentException(
44 44
                 sprintf(
45 45
                     'Action parameter must type string or array, `%s` given',
@@ -51,13 +51,13 @@  discard block
 block discarded – undo
51 51
         $this->controller = $controller;
52 52
         $this->action = $action;
53 53
 
54
-        if (is_string($action)) {
54
+        if (is_string($action)){
55 55
             parent::__construct(
56 56
                 ['action' => $action],
57 57
                 ['action' => new Autofill($action)],
58 58
                 $options
59 59
             );
60
-        } else {
60
+        }else{
61 61
             parent::__construct(
62 62
                 ['action' => null],
63 63
                 ['action' => $action],
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
     protected function resolveAction(array $matches): string
81 81
     {
82 82
         $action = $this->action;
83
-        if (is_string($action)) {
83
+        if (is_string($action)){
84 84
             return $action;
85 85
         }
86 86
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -39,7 +39,8 @@  discard block
 block discarded – undo
39 39
      */
40 40
     public function __construct(string $controller, $action, int $options = 0)
41 41
     {
42
-        if (!is_string($action) && !is_array($action)) {
42
+        if (!is_string($action) && !is_array($action))
43
+        {
43 44
             throw new InvalidArgumentException(
44 45
                 sprintf(
45 46
                     'Action parameter must type string or array, `%s` given',
@@ -51,13 +52,16 @@  discard block
 block discarded – undo
51 52
         $this->controller = $controller;
52 53
         $this->action = $action;
53 54
 
54
-        if (is_string($action)) {
55
+        if (is_string($action))
56
+        {
55 57
             parent::__construct(
56 58
                 ['action' => $action],
57 59
                 ['action' => new Autofill($action)],
58 60
                 $options
59 61
             );
60
-        } else {
62
+        }
63
+        else
64
+        {
61 65
             parent::__construct(
62 66
                 ['action' => null],
63 67
                 ['action' => $action],
@@ -80,7 +84,8 @@  discard block
 block discarded – undo
80 84
     protected function resolveAction(array $matches): string
81 85
     {
82 86
         $action = $this->action;
83
-        if (is_string($action)) {
87
+        if (is_string($action))
88
+        {
84 89
             return $action;
85 90
         }
86 91
 
Please login to merge, or discard this patch.
src/Router/src/Target/Namespaced.php 2 patches
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -58,7 +58,8 @@
 block discarded – undo
58 58
      */
59 59
     protected function resolveController(array $matches): string
60 60
     {
61
-        if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])) {
61
+        if (preg_match('/[^a-z_0-9\-]/i', $matches['controller']))
62
+        {
62 63
             throw new TargetException('Invalid namespace target, controller name not allowed.');
63 64
         }
64 65
 
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@  discard block
 block discarded – undo
33 33
         string $namespace,
34 34
         string $postfix = 'Controller',
35 35
         int $options = 0
36
-    ) {
36
+    ){
37 37
         $this->namespace = rtrim($namespace, '\\');
38 38
         $this->postfix = ucfirst($postfix);
39 39
 
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
      */
52 52
     protected function resolveController(array $matches): string
53 53
     {
54
-        if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])) {
54
+        if (preg_match('/[^a-z_0-9\-]/i', $matches['controller'])){
55 55
             throw new TargetException('Invalid namespace target, controller name not allowed.');
56 56
         }
57 57
 
Please login to merge, or discard this patch.
src/Router/src/Router.php 2 patches
Braces   +32 added lines, -14 removed lines patch added patch discarded remove patch
@@ -69,13 +69,17 @@  discard block
 block discarded – undo
69 69
      */
70 70
     public function handle(ServerRequestInterface $request): ResponseInterface
71 71
     {
72
-        try {
72
+        try
73
+        {
73 74
             $route = $this->matchRoute($request, $routeName);
74
-        } catch (RouteException $e) {
75
+        }
76
+        catch (RouteException $e)
77
+        {
75 78
             throw new RouterException('Invalid route definition', $e->getCode(), $e);
76 79
         }
77 80
 
78
-        if ($route === null) {
81
+        if ($route === null)
82
+        {
79 83
             throw new RouteNotFoundException($request->getUri());
80 84
         }
81 85
 
@@ -120,7 +124,8 @@  discard block
 block discarded – undo
120 124
      */
121 125
     public function getRoute(string $name): RouteInterface
122 126
     {
123
-        if (isset($this->routes[$name])) {
127
+        if (isset($this->routes[$name]))
128
+        {
124 129
             return $this->routes[$name];
125 130
         }
126 131
 
@@ -132,7 +137,8 @@  discard block
 block discarded – undo
132 137
      */
133 138
     public function getRoutes(): array
134 139
     {
135
-        if (!empty($this->default)) {
140
+        if (!empty($this->default))
141
+        {
136 142
             return $this->routes + [null => $this->default];
137 143
         }
138 144
 
@@ -144,9 +150,12 @@  discard block
 block discarded – undo
144 150
      */
145 151
     public function uri(string $route, $parameters = []): UriInterface
146 152
     {
147
-        try {
153
+        try
154
+        {
148 155
             return $this->getRoute($route)->uri($parameters);
149
-        } catch (UndefinedRouteException $e) {
156
+        }
157
+        catch (UndefinedRouteException $e)
158
+        {
150 159
             //In some cases route name can be provided as controller:action pair, we can try to
151 160
             //generate such route automatically based on our default/fallback route
152 161
             return $this->castRoute($route)->uri($parameters);
@@ -161,17 +170,20 @@  discard block
 block discarded – undo
161 170
      */
162 171
     protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface
163 172
     {
164
-        foreach ($this->routes as $name => $route) {
173
+        foreach ($this->routes as $name => $route)
174
+        {
165 175
             // Matched route will return new route instance with matched parameters
166 176
             $matched = $route->match($request);
167 177
 
168
-            if ($matched !== null) {
178
+            if ($matched !== null)
179
+            {
169 180
                 $routeName = $name;
170 181
                 return $matched;
171 182
             }
172 183
         }
173 184
 
174
-        if ($this->default !== null) {
185
+        if ($this->default !== null)
186
+        {
175 187
             return $this->default->match($request);
176 188
         }
177 189
 
@@ -187,7 +199,8 @@  discard block
 block discarded – undo
187 199
      */
188 200
     protected function configure(RouteInterface $route): RouteInterface
189 201
     {
190
-        if ($route instanceof ContainerizedInterface && !$route->hasContainer()) {
202
+        if ($route instanceof ContainerizedInterface && !$route->hasContainer())
203
+        {
191 204
             // isolating route in a given container
192 205
             $route = $route->withContainer($this->container);
193 206
         }
@@ -220,11 +233,16 @@  discard block
 block discarded – undo
220 233
             );
221 234
         }
222 235
 
223
-        if (!empty($matches['name'])) {
236
+        if (!empty($matches['name']))
237
+        {
224 238
             $routeObject = $this->getRoute($matches['name']);
225
-        } elseif ($this->default !== null) {
239
+        }
240
+        elseif ($this->default !== null)
241
+        {
226 242
             $routeObject = $this->default;
227
-        } else {
243
+        }
244
+        else
245
+        {
228 246
             throw new UndefinedRouteException("Unable to locate route candidate for `{$route}`");
229 247
         }
230 248
 
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function __construct(string $basePath, UriHandler $uriHandler, ContainerInterface $container)
53 53
     {
54
-        $this->basePath = '/' . ltrim($basePath, '/');
54
+        $this->basePath = '/'.ltrim($basePath, '/');
55 55
         $this->uriHandler = $uriHandler;
56 56
         $this->container = $container;
57 57
     }
@@ -64,13 +64,13 @@  discard block
 block discarded – undo
64 64
      */
65 65
     public function handle(ServerRequestInterface $request): ResponseInterface
66 66
     {
67
-        try {
67
+        try{
68 68
             $route = $this->matchRoute($request, $routeName);
69
-        } catch (RouteException $e) {
69
+        }catch (RouteException $e){
70 70
             throw new RouterException('Invalid route definition', $e->getCode(), $e);
71 71
         }
72 72
 
73
-        if ($route === null) {
73
+        if ($route === null){
74 74
             throw new RouteNotFoundException($request->getUri());
75 75
         }
76 76
 
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
      */
116 116
     public function getRoute(string $name): RouteInterface
117 117
     {
118
-        if (isset($this->routes[$name])) {
118
+        if (isset($this->routes[$name])){
119 119
             return $this->routes[$name];
120 120
         }
121 121
 
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
      */
128 128
     public function getRoutes(): array
129 129
     {
130
-        if (!empty($this->default)) {
130
+        if (!empty($this->default)){
131 131
             return $this->routes + [null => $this->default];
132 132
         }
133 133
 
@@ -139,9 +139,9 @@  discard block
 block discarded – undo
139 139
      */
140 140
     public function uri(string $route, $parameters = []): UriInterface
141 141
     {
142
-        try {
142
+        try{
143 143
             return $this->getRoute($route)->uri($parameters);
144
-        } catch (UndefinedRouteException $e) {
144
+        }catch (UndefinedRouteException $e){
145 145
             //In some cases route name can be provided as controller:action pair, we can try to
146 146
             //generate such route automatically based on our default/fallback route
147 147
             return $this->castRoute($route)->uri($parameters);
@@ -153,17 +153,17 @@  discard block
 block discarded – undo
153 153
      */
154 154
     protected function matchRoute(ServerRequestInterface $request, string &$routeName = null): ?RouteInterface
155 155
     {
156
-        foreach ($this->routes as $name => $route) {
156
+        foreach ($this->routes as $name => $route){
157 157
             // Matched route will return new route instance with matched parameters
158 158
             $matched = $route->match($request);
159 159
 
160
-            if ($matched !== null) {
160
+            if ($matched !== null){
161 161
                 $routeName = $name;
162 162
                 return $matched;
163 163
             }
164 164
         }
165 165
 
166
-        if ($this->default !== null) {
166
+        if ($this->default !== null){
167 167
             return $this->default->match($request);
168 168
         }
169 169
 
@@ -176,7 +176,7 @@  discard block
 block discarded – undo
176 176
      */
177 177
     protected function configure(RouteInterface $route): RouteInterface
178 178
     {
179
-        if ($route instanceof ContainerizedInterface && !$route->hasContainer()) {
179
+        if ($route instanceof ContainerizedInterface && !$route->hasContainer()){
180 180
             // isolating route in a given container
181 181
             $route = $route->withContainer($this->container);
182 182
         }
@@ -201,17 +201,17 @@  discard block
 block discarded – undo
201 201
                 $route,
202 202
                 $matches
203 203
             )
204
-        ) {
204
+        ){
205 205
             throw new UndefinedRouteException(
206 206
                 "Unable to locate route or use default route with 'name/controller:action' pattern"
207 207
             );
208 208
         }
209 209
 
210
-        if (!empty($matches['name'])) {
210
+        if (!empty($matches['name'])){
211 211
             $routeObject = $this->getRoute($matches['name']);
212
-        } elseif ($this->default !== null) {
212
+        } elseif ($this->default !== null){
213 213
             $routeObject = $this->default;
214
-        } else {
214
+        }else{
215 215
             throw new UndefinedRouteException("Unable to locate route candidate for `{$route}`");
216 216
         }
217 217
 
Please login to merge, or discard this patch.
src/Router/src/Traits/PipelineTrait.php 2 patches
Spacing   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
         $route = clone $this;
47 47
 
48 48
         // array fallback
49
-        if (count($middleware) === 1 && is_array($middleware[0])) {
49
+        if (count($middleware) === 1 && is_array($middleware[0])){
50 50
             $middleware = $middleware[0];
51 51
         }
52 52
 
53
-        foreach ($middleware as $item) {
54
-            if (!is_string($item) && !$item instanceof MiddlewareInterface) {
55
-                if (is_object($item)) {
53
+        foreach ($middleware as $item){
54
+            if (!is_string($item) && !$item instanceof MiddlewareInterface){
55
+                if (is_object($item)){
56 56
                     $name = get_class($item);
57
-                } else {
57
+                }else{
58 58
                     $name = gettype($item);
59 59
                 }
60 60
 
@@ -64,7 +64,7 @@  discard block
 block discarded – undo
64 64
             $route->middleware[] = $item;
65 65
         }
66 66
 
67
-        if ($route->pipeline !== null) {
67
+        if ($route->pipeline !== null){
68 68
             $route->pipeline = $route->makePipeline();
69 69
         }
70 70
 
@@ -81,22 +81,22 @@  discard block
 block discarded – undo
81 81
     protected function makePipeline(): Pipeline
82 82
     {
83 83
         // pre-aggregated
84
-        if (count($this->middleware) === 1 && $this->middleware[0] instanceof Pipeline) {
84
+        if (count($this->middleware) === 1 && $this->middleware[0] instanceof Pipeline){
85 85
             return $this->middleware[0];
86 86
         }
87 87
 
88
-        try {
88
+        try{
89 89
             $pipeline = $this->container->get(Pipeline::class);
90 90
 
91
-            foreach ($this->middleware as $middleware) {
92
-                if ($middleware instanceof MiddlewareInterface) {
91
+            foreach ($this->middleware as $middleware){
92
+                if ($middleware instanceof MiddlewareInterface){
93 93
                     $pipeline->pushMiddleware($middleware);
94
-                } else {
94
+                }else{
95 95
                     // dynamically resolved
96 96
                     $pipeline->pushMiddleware($this->container->get($middleware));
97 97
                 }
98 98
             }
99
-        } catch (ContainerExceptionInterface $e) {
99
+        }catch (ContainerExceptionInterface $e){
100 100
             throw new RouteException($e->getMessage(), $e->getCode(), $e);
101 101
         }
102 102
 
Please login to merge, or discard this patch.
Braces   +27 added lines, -12 removed lines patch added patch discarded remove patch
@@ -46,15 +46,21 @@  discard block
 block discarded – undo
46 46
         $route = clone $this;
47 47
 
48 48
         // array fallback
49
-        if (count($middleware) === 1 && is_array($middleware[0])) {
49
+        if (count($middleware) === 1 && is_array($middleware[0]))
50
+        {
50 51
             $middleware = $middleware[0];
51 52
         }
52 53
 
53
-        foreach ($middleware as $item) {
54
-            if (!is_string($item) && !$item instanceof MiddlewareInterface) {
55
-                if (is_object($item)) {
54
+        foreach ($middleware as $item)
55
+        {
56
+            if (!is_string($item) && !$item instanceof MiddlewareInterface)
57
+            {
58
+                if (is_object($item))
59
+                {
56 60
                     $name = get_class($item);
57
-                } else {
61
+                }
62
+                else
63
+                {
58 64
                     $name = gettype($item);
59 65
                 }
60 66
 
@@ -64,7 +70,8 @@  discard block
 block discarded – undo
64 70
             $route->middleware[] = $item;
65 71
         }
66 72
 
67
-        if ($route->pipeline !== null) {
73
+        if ($route->pipeline !== null)
74
+        {
68 75
             $route->pipeline = $route->makePipeline();
69 76
         }
70 77
 
@@ -81,22 +88,30 @@  discard block
 block discarded – undo
81 88
     protected function makePipeline(): Pipeline
82 89
     {
83 90
         // pre-aggregated
84
-        if (count($this->middleware) === 1 && $this->middleware[0] instanceof Pipeline) {
91
+        if (count($this->middleware) === 1 && $this->middleware[0] instanceof Pipeline)
92
+        {
85 93
             return $this->middleware[0];
86 94
         }
87 95
 
88
-        try {
96
+        try
97
+        {
89 98
             $pipeline = $this->container->get(Pipeline::class);
90 99
 
91
-            foreach ($this->middleware as $middleware) {
92
-                if ($middleware instanceof MiddlewareInterface) {
100
+            foreach ($this->middleware as $middleware)
101
+            {
102
+                if ($middleware instanceof MiddlewareInterface)
103
+                {
93 104
                     $pipeline->pushMiddleware($middleware);
94
-                } else {
105
+                }
106
+                else
107
+                {
95 108
                     // dynamically resolved
96 109
                     $pipeline->pushMiddleware($this->container->get($middleware));
97 110
                 }
98 111
             }
99
-        } catch (ContainerExceptionInterface $e) {
112
+        }
113
+        catch (ContainerExceptionInterface $e)
114
+        {
100 115
             throw new RouteException($e->getMessage(), $e->getCode(), $e);
101 116
         }
102 117
 
Please login to merge, or discard this patch.
src/Router/src/Traits/VerbsTrait.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,9 +30,9 @@
 block discarded – undo
30 30
      */
31 31
     public function withVerbs(string ...$verbs): RouteInterface
32 32
     {
33
-        foreach ($verbs as &$verb) {
33
+        foreach ($verbs as &$verb){
34 34
             $verb = strtoupper($verb);
35
-            if (!in_array($verb, RouteInterface::VERBS, true)) {
35
+            if (!in_array($verb, RouteInterface::VERBS, true)){
36 36
                 throw new RouteException("Invalid HTTP verb `{$verb}`");
37 37
             }
38 38
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -30,9 +30,11 @@
 block discarded – undo
30 30
      */
31 31
     public function withVerbs(string ...$verbs): RouteInterface
32 32
     {
33
-        foreach ($verbs as &$verb) {
33
+        foreach ($verbs as &$verb)
34
+        {
34 35
             $verb = strtoupper($verb);
35
-            if (!in_array($verb, RouteInterface::VERBS, true)) {
36
+            if (!in_array($verb, RouteInterface::VERBS, true))
37
+            {
36 38
                 throw new RouteException("Invalid HTTP verb `{$verb}`");
37 39
             }
38 40
 
Please login to merge, or discard this patch.
src/Router/src/AbstractRoute.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,12 +65,12 @@
 block discarded – undo
65 65
      */
66 66
     public function match(Request $request): ?RouteInterface
67 67
     {
68
-        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true)) {
68
+        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true)){
69 69
             return null;
70 70
         }
71 71
 
72 72
         $matches = $this->uriHandler->match($request->getUri(), $this->defaults);
73
-        if ($matches === null) {
73
+        if ($matches === null){
74 74
             return null;
75 75
         }
76 76
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -65,12 +65,14 @@
 block discarded – undo
65 65
      */
66 66
     public function match(Request $request): ?RouteInterface
67 67
     {
68
-        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true)) {
68
+        if (!in_array(strtoupper($request->getMethod()), $this->getVerbs(), true))
69
+        {
69 70
             return null;
70 71
         }
71 72
 
72 73
         $matches = $this->uriHandler->match($request->getUri(), $this->defaults);
73
-        if ($matches === null) {
74
+        if ($matches === null)
75
+        {
74 76
             return null;
75 77
         }
76 78
 
Please login to merge, or discard this patch.
src/Session/tests/FactoryTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,7 @@
 block discarded – undo
24 24
 {
25 25
     public function tearDown(): void
26 26
     {
27
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
27
+        if ((int)session_status() === PHP_SESSION_ACTIVE){
28 28
             session_abort();
29 29
         }
30 30
     }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -24,7 +24,8 @@
 block discarded – undo
24 24
 {
25 25
     public function tearDown(): void
26 26
     {
27
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
27
+        if ((int)session_status() === PHP_SESSION_ACTIVE)
28
+        {
28 29
             session_abort();
29 30
         }
30 31
     }
Please login to merge, or discard this patch.
src/Session/tests/SessionTest.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,7 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function tearDown(): void
53 53
     {
54
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
54
+        if ((int)session_status() === PHP_SESSION_ACTIVE){
55 55
             session_abort();
56 56
         }
57 57
     }
@@ -125,7 +125,7 @@  discard block
 block discarded – undo
125 125
         $this->assertSame('default', $section->getName());
126 126
 
127 127
         $section->set('key', 'value');
128
-        foreach ($section as $key => $value) {
128
+        foreach ($section as $key => $value){
129 129
             $this->assertSame('key', $key);
130 130
             $this->assertSame('value', $value);
131 131
         }
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -51,7 +51,8 @@  discard block
 block discarded – undo
51 51
 
52 52
     public function tearDown(): void
53 53
     {
54
-        if ((int)session_status() === PHP_SESSION_ACTIVE) {
54
+        if ((int)session_status() === PHP_SESSION_ACTIVE)
55
+        {
55 56
             session_abort();
56 57
         }
57 58
     }
@@ -125,7 +126,8 @@  discard block
 block discarded – undo
125 126
         $this->assertSame('default', $section->getName());
126 127
 
127 128
         $section->set('key', 'value');
128
-        foreach ($section as $key => $value) {
129
+        foreach ($section as $key => $value)
130
+        {
129 131
             $this->assertSame('key', $key);
130 132
             $this->assertSame('value', $value);
131 133
         }
Please login to merge, or discard this patch.