Passed
Pull Request — master (#451)
by Kirill
09:09 queued 24s
created
src/Csrf/src/Middleware/CsrfMiddleware.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -46,9 +46,9 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function process(Request $request, RequestHandlerInterface $handler): Response
48 48
     {
49
-        if (isset($request->getCookieParams()[$this->config->getCookie()])) {
49
+        if (isset($request->getCookieParams()[$this->config->getCookie()])){
50 50
             $token = $request->getCookieParams()[$this->config->getCookie()];
51
-        } else {
51
+        }else{
52 52
             //Making new token
53 53
             $token = $this->random($this->config->getTokenLength());
54 54
 
@@ -59,7 +59,7 @@  discard block
 block discarded – undo
59 59
         //CSRF issues must be handled by Firewall middleware
60 60
         $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $token));
61 61
 
62
-        if (!empty($cookie)) {
62
+        if (!empty($cookie)){
63 63
             return $response->withAddedHeader('Set-Cookie', $cookie);
64 64
         }
65 65
 
@@ -94,11 +94,11 @@  discard block
 block discarded – undo
94 94
      */
95 95
     private function random(int $length = 32): string
96 96
     {
97
-        try {
98
-            if (empty($string = random_bytes($length))) {
97
+        try{
98
+            if (empty($string = random_bytes($length))){
99 99
                 throw new \RuntimeException('Unable to generate random string');
100 100
             }
101
-        } catch (\Throwable $e) {
101
+        }catch (\Throwable $e){
102 102
             throw new \RuntimeException('Unable to generate random string', $e->getCode(), $e);
103 103
         }
104 104
 
Please login to merge, or discard this patch.
Braces   +14 added lines, -6 removed lines patch added patch discarded remove patch
@@ -46,9 +46,12 @@  discard block
 block discarded – undo
46 46
      */
47 47
     public function process(Request $request, RequestHandlerInterface $handler): Response
48 48
     {
49
-        if (isset($request->getCookieParams()[$this->config->getCookie()])) {
49
+        if (isset($request->getCookieParams()[$this->config->getCookie()]))
50
+        {
50 51
             $token = $request->getCookieParams()[$this->config->getCookie()];
51
-        } else {
52
+        }
53
+        else
54
+        {
52 55
             //Making new token
53 56
             $token = $this->random($this->config->getTokenLength());
54 57
 
@@ -59,7 +62,8 @@  discard block
 block discarded – undo
59 62
         //CSRF issues must be handled by Firewall middleware
60 63
         $response = $handler->handle($request->withAttribute(static::ATTRIBUTE, $token));
61 64
 
62
-        if (!empty($cookie)) {
65
+        if (!empty($cookie))
66
+        {
63 67
             return $response->withAddedHeader('Set-Cookie', $cookie);
64 68
         }
65 69
 
@@ -94,11 +98,15 @@  discard block
 block discarded – undo
94 98
      */
95 99
     private function random(int $length = 32): string
96 100
     {
97
-        try {
98
-            if (empty($string = random_bytes($length))) {
101
+        try
102
+        {
103
+            if (empty($string = random_bytes($length)))
104
+            {
99 105
                 throw new \RuntimeException('Unable to generate random string');
100 106
             }
101
-        } catch (\Throwable $e) {
107
+        }
108
+        catch (\Throwable $e)
109
+        {
102 110
             throw new \RuntimeException('Unable to generate random string', $e->getCode(), $e);
103 111
         }
104 112
 
Please login to merge, or discard this patch.
src/Csrf/src/Middleware/CsrfFirewall.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,11 +61,11 @@  discard block
 block discarded – undo
61 61
     {
62 62
         $token = $request->getAttribute(CsrfMiddleware::ATTRIBUTE);
63 63
 
64
-        if (empty($token)) {
64
+        if (empty($token)){
65 65
             throw new \LogicException('Unable to apply CSRF firewall, attribute is missing');
66 66
         }
67 67
 
68
-        if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))) {
68
+        if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))){
69 69
             return $this->responseFactory->createResponse(412, 'Bad CSRF Token');
70 70
         }
71 71
 
@@ -91,12 +91,12 @@  discard block
 block discarded – undo
91 91
      */
92 92
     protected function fetchToken(Request $request): string
93 93
     {
94
-        if ($request->hasHeader(self::HEADER)) {
94
+        if ($request->hasHeader(self::HEADER)){
95 95
             return (string)$request->getHeaderLine(self::HEADER);
96 96
         }
97 97
 
98 98
         $data = $request->getParsedBody();
99
-        if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])) {
99
+        if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])){
100 100
             return $data[self::PARAMETER];
101 101
         }
102 102
 
Please login to merge, or discard this patch.
Braces   +8 added lines, -4 removed lines patch added patch discarded remove patch
@@ -61,11 +61,13 @@  discard block
 block discarded – undo
61 61
     {
62 62
         $token = $request->getAttribute(CsrfMiddleware::ATTRIBUTE);
63 63
 
64
-        if (empty($token)) {
64
+        if (empty($token))
65
+        {
65 66
             throw new \LogicException('Unable to apply CSRF firewall, attribute is missing');
66 67
         }
67 68
 
68
-        if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request))) {
69
+        if ($this->isRequired($request) && !hash_equals($token, $this->fetchToken($request)))
70
+        {
69 71
             return $this->responseFactory->createResponse(412, 'Bad CSRF Token');
70 72
         }
71 73
 
@@ -91,12 +93,14 @@  discard block
 block discarded – undo
91 93
      */
92 94
     protected function fetchToken(Request $request): string
93 95
     {
94
-        if ($request->hasHeader(self::HEADER)) {
96
+        if ($request->hasHeader(self::HEADER))
97
+        {
95 98
             return (string)$request->getHeaderLine(self::HEADER);
96 99
         }
97 100
 
98 101
         $data = $request->getParsedBody();
99
-        if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER])) {
102
+        if (is_array($data) && isset($data[self::PARAMETER]) && is_string($data[self::PARAMETER]))
103
+        {
100 104
             return $data[self::PARAMETER];
101 105
         }
102 106
 
Please login to merge, or discard this patch.
src/AuthHttp/src/Transport/CookieTransport.php 2 patches
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -56,7 +56,7 @@  discard block
 block discarded – undo
56 56
         bool $secure = false,
57 57
         bool $httpOnly = true,
58 58
         ?string $sameSite = null
59
-    ) {
59
+    ){
60 60
         $this->cookie = $cookie;
61 61
         $this->basePath = $basePath;
62 62
         $this->domain = $domain;
@@ -85,7 +85,7 @@  discard block
 block discarded – undo
85 85
     ): Response {
86 86
         /** @var CookieQueue $cookieQueue */
87 87
         $cookieQueue = $request->getAttribute(CookieQueue::ATTRIBUTE);
88
-        if ($cookieQueue === null) {
88
+        if ($cookieQueue === null){
89 89
             return $response->withAddedHeader(
90 90
                 'Set-Cookie',
91 91
                 Cookie::create(
@@ -101,9 +101,9 @@  discard block
 block discarded – undo
101 101
             );
102 102
         }
103 103
 
104
-        if ($tokenID === null) {
104
+        if ($tokenID === null){
105 105
             $cookieQueue->delete($this->cookie);
106
-        } else {
106
+        }else{
107 107
             $cookieQueue->set(
108 108
                 $this->cookie,
109 109
                 $tokenID,
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
      */
135 135
     private function getLifetime(\DateTimeInterface $expiresAt = null): ?int
136 136
     {
137
-        if ($expiresAt === null) {
137
+        if ($expiresAt === null){
138 138
             return null;
139 139
         }
140 140
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -4 removed lines patch added patch discarded remove patch
@@ -85,7 +85,8 @@  discard block
 block discarded – undo
85 85
     ): Response {
86 86
         /** @var CookieQueue $cookieQueue */
87 87
         $cookieQueue = $request->getAttribute(CookieQueue::ATTRIBUTE);
88
-        if ($cookieQueue === null) {
88
+        if ($cookieQueue === null)
89
+        {
89 90
             return $response->withAddedHeader(
90 91
                 'Set-Cookie',
91 92
                 Cookie::create(
@@ -101,9 +102,12 @@  discard block
 block discarded – undo
101 102
             );
102 103
         }
103 104
 
104
-        if ($tokenID === null) {
105
+        if ($tokenID === null)
106
+        {
105 107
             $cookieQueue->delete($this->cookie);
106
-        } else {
108
+        }
109
+        else
110
+        {
107 111
             $cookieQueue->set(
108 112
                 $this->cookie,
109 113
                 $tokenID,
@@ -134,7 +138,8 @@  discard block
 block discarded – undo
134 138
      */
135 139
     private function getLifetime(\DateTimeInterface $expiresAt = null): ?int
136 140
     {
137
-        if ($expiresAt === null) {
141
+        if ($expiresAt === null)
142
+        {
138 143
             return null;
139 144
         }
140 145
 
Please login to merge, or discard this patch.
src/AuthHttp/src/Middleware/AuthMiddleware.php 2 patches
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
         ActorProviderInterface $actorProvider,
55 55
         TokenStorageInterface $tokenStorage,
56 56
         TransportRegistry $transportRegistry
57
-    ) {
57
+    ){
58 58
         $this->scope = $scope;
59 59
         $this->actorProvider = $actorProvider;
60 60
         $this->tokenStorage = $tokenStorage;
@@ -89,14 +89,14 @@  discard block
 block discarded – undo
89 89
      */
90 90
     private function initContext(Request $request, AuthContextInterface $authContext): AuthContextInterface
91 91
     {
92
-        foreach ($this->transportRegistry->getTransports() as $name => $transport) {
92
+        foreach ($this->transportRegistry->getTransports() as $name => $transport){
93 93
             $tokenID = $transport->fetchToken($request);
94
-            if ($tokenID === null) {
94
+            if ($tokenID === null){
95 95
                 continue;
96 96
             }
97 97
 
98 98
             $token = $this->tokenStorage->load($tokenID);
99
-            if ($token === null) {
99
+            if ($token === null){
100 100
                 continue;
101 101
             }
102 102
 
@@ -116,13 +116,13 @@  discard block
 block discarded – undo
116 116
      */
117 117
     private function closeContext(Request $request, Response $response, AuthContextInterface $authContext): Response
118 118
     {
119
-        if ($authContext->getToken() === null) {
119
+        if ($authContext->getToken() === null){
120 120
             return $response;
121 121
         }
122 122
 
123 123
         $transport = $this->transportRegistry->getTransport($authContext->getTransport());
124 124
 
125
-        if ($authContext->isClosed()) {
125
+        if ($authContext->isClosed()){
126 126
             $this->tokenStorage->delete($authContext->getToken());
127 127
 
128 128
             return $transport->removeToken(
Please login to merge, or discard this patch.
Braces   +12 added lines, -6 removed lines patch added patch discarded remove patch
@@ -74,7 +74,8 @@  discard block
 block discarded – undo
74 74
 
75 75
         $response = $this->scope->runScope(
76 76
             [AuthContextInterface::class => $authContext],
77
-            static function () use ($request, $handler, $authContext) {
77
+            static function () use ($request, $handler, $authContext)
78
+            {
78 79
                 return $handler->handle($request->withAttribute(self::ATTRIBUTE, $authContext));
79 80
             }
80 81
         );
@@ -89,14 +90,17 @@  discard block
 block discarded – undo
89 90
      */
90 91
     private function initContext(Request $request, AuthContextInterface $authContext): AuthContextInterface
91 92
     {
92
-        foreach ($this->transportRegistry->getTransports() as $name => $transport) {
93
+        foreach ($this->transportRegistry->getTransports() as $name => $transport)
94
+        {
93 95
             $tokenID = $transport->fetchToken($request);
94
-            if ($tokenID === null) {
96
+            if ($tokenID === null)
97
+            {
95 98
                 continue;
96 99
             }
97 100
 
98 101
             $token = $this->tokenStorage->load($tokenID);
99
-            if ($token === null) {
102
+            if ($token === null)
103
+            {
100 104
                 continue;
101 105
             }
102 106
 
@@ -116,13 +120,15 @@  discard block
 block discarded – undo
116 120
      */
117 121
     private function closeContext(Request $request, Response $response, AuthContextInterface $authContext): Response
118 122
     {
119
-        if ($authContext->getToken() === null) {
123
+        if ($authContext->getToken() === null)
124
+        {
120 125
             return $response;
121 126
         }
122 127
 
123 128
         $transport = $this->transportRegistry->getTransport($authContext->getTransport());
124 129
 
125
-        if ($authContext->isClosed()) {
130
+        if ($authContext->isClosed())
131
+        {
126 132
             $this->tokenStorage->delete($authContext->getToken());
127 133
 
128 134
             return $transport->removeToken(
Please login to merge, or discard this patch.
src/AuthHttp/src/Middleware/Firewall/AbstractFirewall.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,7 @@
 block discarded – undo
33 33
         /** @var AuthContextInterface $context */
34 34
         $authContext = $request->getAttribute(AuthMiddleware::ATTRIBUTE);
35 35
 
36
-        if ($authContext === null || $authContext->getActor() === null) {
36
+        if ($authContext === null || $authContext->getActor() === null){
37 37
             return $this->denyAccess($request, $handler);
38 38
         }
39 39
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -33,7 +33,8 @@
 block discarded – undo
33 33
         /** @var AuthContextInterface $context */
34 34
         $authContext = $request->getAttribute(AuthMiddleware::ATTRIBUTE);
35 35
 
36
-        if ($authContext === null || $authContext->getActor() === null) {
36
+        if ($authContext === null || $authContext->getActor() === null)
37
+        {
37 38
             return $this->denyAccess($request, $handler);
38 39
         }
39 40
 
Please login to merge, or discard this patch.
src/AuthHttp/src/TransportRegistry.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,7 @@
 block discarded – undo
49 49
     {
50 50
         $name = $name ?? $this->default;
51 51
 
52
-        if (!isset($this->transports[$name])) {
52
+        if (!isset($this->transports[$name])){
53 53
             throw new TransportException("Undefined auth transport {$name}");
54 54
         }
55 55
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -49,7 +49,8 @@
 block discarded – undo
49 49
     {
50 50
         $name = $name ?? $this->default;
51 51
 
52
-        if (!isset($this->transports[$name])) {
52
+        if (!isset($this->transports[$name]))
53
+        {
53 54
             throw new TransportException("Undefined auth transport {$name}");
54 55
         }
55 56
 
Please login to merge, or discard this patch.
src/AuthHttp/tests/AuthMiddlewareTest.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,7 @@
 block discarded – undo
75 75
 
76 76
         $http->setHandler(
77 77
             static function (ServerRequestInterface $request, ResponseInterface $response): void {
78
-                if ($request->getAttribute('authContext')->getToken() === null) {
78
+                if ($request->getAttribute('authContext')->getToken() === null){
79 79
                     echo 'no token';
80 80
                 }
81 81
             }
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -75,7 +75,8 @@
 block discarded – undo
75 75
 
76 76
         $http->setHandler(
77 77
             static function (ServerRequestInterface $request, ResponseInterface $response): void {
78
-                if ($request->getAttribute('authContext')->getToken() === null) {
78
+                if ($request->getAttribute('authContext')->getToken() === null)
79
+                {
79 80
                     echo 'no token';
80 81
                 }
81 82
             }
Please login to merge, or discard this patch.
src/AuthHttp/tests/Diactoros/ResponseFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,7 @@
 block discarded – undo
37 37
         $response = new Response('php://memory', $code, []);
38 38
         $response = $response->withStatus($code, $reasonPhrase);
39 39
 
40
-        foreach ($this->config->getBaseHeaders() as $header => $value) {
40
+        foreach ($this->config->getBaseHeaders() as $header => $value){
41 41
             $response = $response->withAddedHeader($header, $value);
42 42
         }
43 43
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -37,7 +37,8 @@
 block discarded – undo
37 37
         $response = new Response('php://memory', $code, []);
38 38
         $response = $response->withStatus($code, $reasonPhrase);
39 39
 
40
-        foreach ($this->config->getBaseHeaders() as $header => $value) {
40
+        foreach ($this->config->getBaseHeaders() as $header => $value)
41
+        {
41 42
             $response = $response->withAddedHeader($header, $value);
42 43
         }
43 44
 
Please login to merge, or discard this patch.
src/AuthHttp/tests/Diactoros/UploadedFileFactory.php 2 patches
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,7 @@
 block discarded – undo
26 26
         string $clientFilename = null,
27 27
         string $clientMediaType = null
28 28
     ): UploadedFileInterface {
29
-        if ($size === null) {
29
+        if ($size === null){
30 30
             $size = $stream->getSize();
31 31
         }
32 32
 
Please login to merge, or discard this patch.
Braces   +2 added lines, -1 removed lines patch added patch discarded remove patch
@@ -26,7 +26,8 @@
 block discarded – undo
26 26
         string $clientFilename = null,
27 27
         string $clientMediaType = null
28 28
     ): UploadedFileInterface {
29
-        if ($size === null) {
29
+        if ($size === null)
30
+        {
30 31
             $size = $stream->getSize();
31 32
         }
32 33
 
Please login to merge, or discard this patch.