Passed
Pull Request — master (#839)
by Alexander
16:59
created
src/Router/src/Loader/LoaderRegistryInterface.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -11,5 +11,5 @@
 block discarded – undo
11 11
      *
12 12
      * @param string|null $type The resource type or null if unknown
13 13
      */
14
-    public function resolve(mixed $resource, string $type = null): LoaderInterface|false;
14
+    public function resolve(mixed $resource, string $type = null): LoaderInterface | false;
15 15
 }
Please login to merge, or discard this patch.
src/Router/src/Loader/LoaderRegistry.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -16,15 +16,15 @@
 block discarded – undo
16 16
      */
17 17
     public function __construct(array $loaders = [])
18 18
     {
19
-        foreach ($loaders as $loader) {
19
+        foreach ($loaders as $loader){
20 20
             $this->addLoader($loader);
21 21
         }
22 22
     }
23 23
 
24
-    public function resolve(mixed $resource, string $type = null): LoaderInterface|false
24
+    public function resolve(mixed $resource, string $type = null): LoaderInterface | false
25 25
     {
26
-        foreach ($this->loaders as $loader) {
27
-            if ($loader->supports($resource, $type)) {
26
+        foreach ($this->loaders as $loader){
27
+            if ($loader->supports($resource, $type)){
28 28
                 return $loader;
29 29
             }
30 30
         }
Please login to merge, or discard this patch.
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,15 +16,18 @@
 block discarded – undo
16 16
      */
17 17
     public function __construct(array $loaders = [])
18 18
     {
19
-        foreach ($loaders as $loader) {
19
+        foreach ($loaders as $loader)
20
+        {
20 21
             $this->addLoader($loader);
21 22
         }
22 23
     }
23 24
 
24 25
     public function resolve(mixed $resource, string $type = null): LoaderInterface|false
25 26
     {
26
-        foreach ($this->loaders as $loader) {
27
-            if ($loader->supports($resource, $type)) {
27
+        foreach ($this->loaders as $loader)
28
+        {
29
+            if ($loader->supports($resource, $type))
30
+            {
28 31
                 return $loader;
29 32
             }
30 33
         }
Please login to merge, or discard this patch.
src/Router/src/Loader/PhpFileLoader.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -16,7 +16,7 @@  discard block
 block discarded – undo
16 16
     public function __construct(
17 17
         private readonly FactoryInterface $factory,
18 18
         private readonly ResolverInterface $resolver,
19
-    ) {
19
+    ){
20 20
     }
21 21
 
22 22
     /**
@@ -24,11 +24,11 @@  discard block
 block discarded – undo
24 24
      */
25 25
     public function load(mixed $resource, string $type = null): RouteCollection
26 26
     {
27
-        if (!\file_exists($resource)) {
27
+        if (!\file_exists($resource)){
28 28
             throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource));
29 29
         }
30 30
 
31
-        $load = static function (string $path) {
31
+        $load = static function (string $path){
32 32
             return include $path;
33 33
         };
34 34
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -24,11 +24,13 @@
 block discarded – undo
24 24
      */
25 25
     public function load(mixed $resource, string $type = null): RouteCollection
26 26
     {
27
-        if (!\file_exists($resource)) {
27
+        if (!\file_exists($resource))
28
+        {
28 29
             throw new LoaderLoadException(\sprintf('File [%s] does not exist.', $resource));
29 30
         }
30 31
 
31
-        $load = static function (string $path) {
32
+        $load = static function (string $path)
33
+        {
32 34
             return include $path;
33 35
         };
34 36
 
Please login to merge, or discard this patch.
src/Router/src/PipelineFactory.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -17,7 +17,7 @@  discard block
 block discarded – undo
17 17
     public function __construct(
18 18
         private readonly ContainerInterface $container,
19 19
         private readonly FactoryInterface $factory
20
-    ) {
20
+    ){
21 21
     }
22 22
 
23 23
     /**
@@ -26,27 +26,27 @@  discard block
 block discarded – undo
26 26
      */
27 27
     public function createWithMiddleware(array $middleware): Pipeline
28 28
     {
29
-        if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) {
29
+        if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline){
30 30
             return $middleware[0];
31 31
         }
32 32
 
33 33
         $pipeline = $this->factory->make(Pipeline::class);
34 34
         \assert($pipeline instanceof Pipeline);
35 35
 
36
-        foreach ($middleware as $item) {
37
-            if ($item instanceof MiddlewareInterface) {
36
+        foreach ($middleware as $item){
37
+            if ($item instanceof MiddlewareInterface){
38 38
                 $pipeline->pushMiddleware($item);
39
-            } elseif (\is_string($item)) {
39
+            } elseif (\is_string($item)){
40 40
                 $item = $this->container->get($item);
41 41
                 \assert($item instanceof MiddlewareInterface);
42 42
 
43 43
                 $pipeline->pushMiddleware($item);
44
-            } elseif ($item instanceof Autowire) {
44
+            } elseif ($item instanceof Autowire){
45 45
                 $item = $item->resolve($this->factory);
46 46
                 \assert($item instanceof MiddlewareInterface);
47 47
 
48 48
                 $pipeline->pushMiddleware($item);
49
-            } else {
49
+            }else{
50 50
                 $name = get_debug_type($item);
51 51
                 throw new RouteException(\sprintf('Invalid middleware `%s`', $name));
52 52
             }
Please login to merge, or discard this patch.
Braces   +15 added lines, -6 removed lines patch added patch discarded remove patch
@@ -26,27 +26,36 @@
 block discarded – undo
26 26
      */
27 27
     public function createWithMiddleware(array $middleware): Pipeline
28 28
     {
29
-        if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline) {
29
+        if (\count($middleware) === 1 && $middleware[0] instanceof Pipeline)
30
+        {
30 31
             return $middleware[0];
31 32
         }
32 33
 
33 34
         $pipeline = $this->factory->make(Pipeline::class);
34 35
         \assert($pipeline instanceof Pipeline);
35 36
 
36
-        foreach ($middleware as $item) {
37
-            if ($item instanceof MiddlewareInterface) {
37
+        foreach ($middleware as $item)
38
+        {
39
+            if ($item instanceof MiddlewareInterface)
40
+            {
38 41
                 $pipeline->pushMiddleware($item);
39
-            } elseif (\is_string($item)) {
42
+            }
43
+            elseif (\is_string($item))
44
+            {
40 45
                 $item = $this->container->get($item);
41 46
                 \assert($item instanceof MiddlewareInterface);
42 47
 
43 48
                 $pipeline->pushMiddleware($item);
44
-            } elseif ($item instanceof Autowire) {
49
+            }
50
+            elseif ($item instanceof Autowire)
51
+            {
45 52
                 $item = $item->resolve($this->factory);
46 53
                 \assert($item instanceof MiddlewareInterface);
47 54
 
48 55
                 $pipeline->pushMiddleware($item);
49
-            } else {
56
+            }
57
+            else
58
+            {
50 59
                 $name = get_debug_type($item);
51 60
                 throw new RouteException(\sprintf('Invalid middleware `%s`', $name));
52 61
             }
Please login to merge, or discard this patch.
src/Router/src/AbstractRoute.php 2 patches
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -20,7 +20,7 @@  discard block
 block discarded – undo
20 20
     public function __construct(
21 21
         protected string $pattern,
22 22
         array $defaults = []
23
-    ) {
23
+    ){
24 24
         $this->defaults = $defaults;
25 25
     }
26 26
 
@@ -39,12 +39,12 @@  discard block
 block discarded – undo
39 39
 
40 40
     public function match(Request $request): ?static
41 41
     {
42
-        if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) {
42
+        if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)){
43 43
             return null;
44 44
         }
45 45
 
46 46
         $matches = $this->uriHandler->match($request->getUri(), $this->defaults);
47
-        if ($matches === null) {
47
+        if ($matches === null){
48 48
             return null;
49 49
         }
50 50
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -39,12 +39,14 @@
 block discarded – undo
39 39
 
40 40
     public function match(Request $request): ?static
41 41
     {
42
-        if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true)) {
42
+        if (!\in_array(\strtoupper($request->getMethod()), $this->getVerbs(), true))
43
+        {
43 44
             return null;
44 45
         }
45 46
 
46 47
         $matches = $this->uriHandler->match($request->getUri(), $this->defaults);
47
-        if ($matches === null) {
48
+        if ($matches === null)
49
+        {
48 50
             return null;
49 51
         }
50 52
 
Please login to merge, or discard this patch.
src/Router/src/Route.php 2 patches
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -50,9 +50,9 @@  discard block
 block discarded – undo
50 50
      */
51 51
     public function __construct(
52 52
         string $pattern,
53
-        string|callable|RequestHandlerInterface|TargetInterface $target,
53
+        string | callable | RequestHandlerInterface | TargetInterface $target,
54 54
         array $defaults = []
55
-    ) {
55
+    ){
56 56
         parent::__construct(
57 57
             $pattern,
58 58
             $target instanceof TargetInterface
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
     public function withUriHandler(UriHandler $uriHandler): static
67 67
     {
68 68
         $route = parent::withUriHandler($uriHandler);
69
-        if ($this->target instanceof TargetInterface) {
69
+        if ($this->target instanceof TargetInterface){
70 70
             $route->uriHandler = $route->uriHandler->withConstrains(
71 71
                 $this->target->getConstrains(),
72 72
                 $this->defaults
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
         $route = clone $this;
85 85
         $route->container = $container;
86 86
 
87
-        if ($route->target instanceof TargetInterface) {
87
+        if ($route->target instanceof TargetInterface){
88 88
             $route->target = clone $route->target;
89 89
         }
90 90
 
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      */
112 112
     public function handle(ServerRequestInterface $request): ResponseInterface
113 113
     {
114
-        if (empty($this->requestHandler)) {
114
+        if (empty($this->requestHandler)){
115 115
             $this->requestHandler = $this->requestHandler();
116 116
         }
117 117
 
@@ -126,28 +126,28 @@  discard block
 block discarded – undo
126 126
      */
127 127
     protected function requestHandler(): RequestHandlerInterface
128 128
     {
129
-        if (!$this->hasContainer()) {
129
+        if (!$this->hasContainer()){
130 130
             throw new RouteException('Unable to configure route pipeline without associated container');
131 131
         }
132 132
 
133
-        if ($this->target instanceof TargetInterface) {
134
-            try {
133
+        if ($this->target instanceof TargetInterface){
134
+            try{
135 135
                 return $this->target->getHandler($this->container, $this->matches);
136
-            } catch (TargetException $e) {
136
+            }catch (TargetException $e){
137 137
                 throw new RouteException('Invalid target resolution', $e->getCode(), $e);
138 138
             }
139 139
         }
140 140
 
141
-        if ($this->target instanceof RequestHandlerInterface) {
141
+        if ($this->target instanceof RequestHandlerInterface){
142 142
             return $this->target;
143 143
         }
144 144
 
145
-        try {
145
+        try{
146 146
             $target = \is_string($this->target)
147 147
                 ? $this->container->get($this->target)
148 148
                 : $this->target;
149 149
 
150
-            if ($target instanceof RequestHandlerInterface) {
150
+            if ($target instanceof RequestHandlerInterface){
151 151
                 return $target;
152 152
             }
153 153
 
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
                 $target,
156 156
                 $this->container->get(ResponseFactoryInterface::class)
157 157
             );
158
-        } catch (ContainerExceptionInterface $e) {
158
+        }catch (ContainerExceptionInterface $e){
159 159
             throw new RouteException($e->getMessage(), $e->getCode(), $e);
160 160
         }
161 161
     }
Please login to merge, or discard this patch.
Braces   +24 added lines, -11 removed lines patch added patch discarded remove patch
@@ -66,7 +66,8 @@  discard block
 block discarded – undo
66 66
     public function withUriHandler(UriHandler $uriHandler): static
67 67
     {
68 68
         $route = parent::withUriHandler($uriHandler);
69
-        if ($this->target instanceof TargetInterface) {
69
+        if ($this->target instanceof TargetInterface)
70
+        {
70 71
             $route->uriHandler = $route->uriHandler->withConstrains(
71 72
                 $this->target->getConstrains(),
72 73
                 $this->defaults
@@ -84,7 +85,8 @@  discard block
 block discarded – undo
84 85
         $route = clone $this;
85 86
         $route->container = $container;
86 87
 
87
-        if ($route->target instanceof TargetInterface) {
88
+        if ($route->target instanceof TargetInterface)
89
+        {
88 90
             $route->target = clone $route->target;
89 91
         }
90 92
 
@@ -111,7 +113,8 @@  discard block
 block discarded – undo
111 113
      */
112 114
     public function handle(ServerRequestInterface $request): ResponseInterface
113 115
     {
114
-        if (empty($this->requestHandler)) {
116
+        if (empty($this->requestHandler))
117
+        {
115 118
             $this->requestHandler = $this->requestHandler();
116 119
         }
117 120
 
@@ -126,28 +129,36 @@  discard block
 block discarded – undo
126 129
      */
127 130
     protected function requestHandler(): RequestHandlerInterface
128 131
     {
129
-        if (!$this->hasContainer()) {
132
+        if (!$this->hasContainer())
133
+        {
130 134
             throw new RouteException('Unable to configure route pipeline without associated container');
131 135
         }
132 136
 
133
-        if ($this->target instanceof TargetInterface) {
134
-            try {
137
+        if ($this->target instanceof TargetInterface)
138
+        {
139
+            try
140
+            {
135 141
                 return $this->target->getHandler($this->container, $this->matches);
136
-            } catch (TargetException $e) {
142
+            }
143
+            catch (TargetException $e)
144
+            {
137 145
                 throw new RouteException('Invalid target resolution', $e->getCode(), $e);
138 146
             }
139 147
         }
140 148
 
141
-        if ($this->target instanceof RequestHandlerInterface) {
149
+        if ($this->target instanceof RequestHandlerInterface)
150
+        {
142 151
             return $this->target;
143 152
         }
144 153
 
145
-        try {
154
+        try
155
+        {
146 156
             $target = \is_string($this->target)
147 157
                 ? $this->container->get($this->target)
148 158
                 : $this->target;
149 159
 
150
-            if ($target instanceof RequestHandlerInterface) {
160
+            if ($target instanceof RequestHandlerInterface)
161
+            {
151 162
                 return $target;
152 163
             }
153 164
 
@@ -155,7 +166,9 @@  discard block
 block discarded – undo
155 166
                 $target,
156 167
                 $this->container->get(ResponseFactoryInterface::class)
157 168
             );
158
-        } catch (ContainerExceptionInterface $e) {
169
+        }
170
+        catch (ContainerExceptionInterface $e)
171
+        {
159 172
             throw new RouteException($e->getMessage(), $e->getCode(), $e);
160 173
         }
161 174
     }
Please login to merge, or discard this patch.
src/Router/src/Exception/RouteNotFoundException.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -12,8 +12,8 @@
 block discarded – undo
12 12
         private readonly UriInterface $uri,
13 13
         int $code = 0,
14 14
         \Throwable $previous = null
15
-    ) {
16
-        parent::__construct(\sprintf('Unable to route `%s`.', (string) $uri), $code, $previous);
15
+    ){
16
+        parent::__construct(\sprintf('Unable to route `%s`.', (string)$uri), $code, $previous);
17 17
     }
18 18
 
19 19
     public function getUri(): UriInterface
Please login to merge, or discard this patch.
src/Router/src/RouteCollection.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
 
14 14
     public function __clone()
15 15
     {
16
-        foreach ($this->routes as $name => $route) {
16
+        foreach ($this->routes as $name => $route){
17 17
             $this->routes[$name] = clone $route;
18 18
         }
19 19
     }
@@ -72,16 +72,16 @@  discard block
 block discarded – undo
72 72
      *
73 73
      * @param string|string[] $name The route name or an array of route names
74 74
      */
75
-    public function remove(string|array $name)
75
+    public function remove(string | array $name)
76 76
     {
77
-        foreach ((array) $name as $n) {
77
+        foreach ((array)$name as $n){
78 78
             unset($this->routes[$n]);
79 79
         }
80 80
     }
81 81
 
82 82
     public function addCollection(self $collection)
83 83
     {
84
-        foreach ($collection->all() as $name => $route) {
84
+        foreach ($collection->all() as $name => $route){
85 85
             $this->routes[$name] = $route;
86 86
         }
87 87
     }
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
      */
92 92
     public function group(string $group)
93 93
     {
94
-        foreach ($this->routes as $route) {
94
+        foreach ($this->routes as $route){
95 95
             $route->group($group);
96 96
         }
97 97
     }
Please login to merge, or discard this patch.
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -13,7 +13,8 @@  discard block
 block discarded – undo
13 13
 
14 14
     public function __clone()
15 15
     {
16
-        foreach ($this->routes as $name => $route) {
16
+        foreach ($this->routes as $name => $route)
17
+        {
17 18
             $this->routes[$name] = clone $route;
18 19
         }
19 20
     }
@@ -74,14 +75,16 @@  discard block
 block discarded – undo
74 75
      */
75 76
     public function remove(string|array $name)
76 77
     {
77
-        foreach ((array) $name as $n) {
78
+        foreach ((array) $name as $n)
79
+        {
78 80
             unset($this->routes[$n]);
79 81
         }
80 82
     }
81 83
 
82 84
     public function addCollection(self $collection)
83 85
     {
84
-        foreach ($collection->all() as $name => $route) {
86
+        foreach ($collection->all() as $name => $route)
87
+        {
85 88
             $this->routes[$name] = $route;
86 89
         }
87 90
     }
@@ -91,7 +94,8 @@  discard block
 block discarded – undo
91 94
      */
92 95
     public function group(string $group)
93 96
     {
94
-        foreach ($this->routes as $route) {
97
+        foreach ($this->routes as $route)
98
+        {
95 99
             $route->group($group);
96 100
         }
97 101
     }
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
@@ -19,9 +19,9 @@
 block discarded – undo
19 19
      */
20 20
     public function withVerbs(string ...$verbs): RouteInterface
21 21
     {
22
-        foreach ($verbs as &$verb) {
22
+        foreach ($verbs as &$verb){
23 23
             $verb = \strtoupper($verb);
24
-            if (!\in_array($verb, RouteInterface::VERBS, true)) {
24
+            if (!\in_array($verb, RouteInterface::VERBS, true)){
25 25
                 throw new RouteException(\sprintf('Invalid HTTP verb `%s`', $verb));
26 26
             }
27 27
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -19,9 +19,11 @@
 block discarded – undo
19 19
      */
20 20
     public function withVerbs(string ...$verbs): RouteInterface
21 21
     {
22
-        foreach ($verbs as &$verb) {
22
+        foreach ($verbs as &$verb)
23
+        {
23 24
             $verb = \strtoupper($verb);
24
-            if (!\in_array($verb, RouteInterface::VERBS, true)) {
25
+            if (!\in_array($verb, RouteInterface::VERBS, true))
26
+            {
25 27
                 throw new RouteException(\sprintf('Invalid HTTP verb `%s`', $verb));
26 28
             }
27 29
 
Please login to merge, or discard this patch.