Passed
Push — master ( 2291e3...cd7158 )
by Anton
03:34
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/Transport/HeaderTransport.php 2 patches
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function fetchToken(Request $request): ?string
38 38
     {
39
-        if ($request->hasHeader($this->header)) {
39
+        if ($request->hasHeader($this->header)){
40 40
             return $request->getHeaderLine($this->header);
41 41
         }
42 42
 
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
         string $tokenID,
53 53
         \DateTimeInterface $expiresAt = null
54 54
     ): Response {
55
-        if ($request->hasHeader($this->header) && $request->getHeaderLine($this->header) === $tokenID) {
55
+        if ($request->hasHeader($this->header) && $request->getHeaderLine($this->header) === $tokenID){
56 56
             return $response;
57 57
         }
58 58
 
Please login to merge, or discard this patch.
Braces   +4 added lines, -2 removed lines patch added patch discarded remove patch
@@ -36,7 +36,8 @@  discard block
 block discarded – undo
36 36
      */
37 37
     public function fetchToken(Request $request): ?string
38 38
     {
39
-        if ($request->hasHeader($this->header)) {
39
+        if ($request->hasHeader($this->header))
40
+        {
40 41
             return $request->getHeaderLine($this->header);
41 42
         }
42 43
 
@@ -52,7 +53,8 @@  discard block
 block discarded – undo
52 53
         string $tokenID,
53 54
         \DateTimeInterface $expiresAt = null
54 55
     ): Response {
55
-        if ($request->hasHeader($this->header) && $request->getHeaderLine($this->header) === $tokenID) {
56
+        if ($request->hasHeader($this->header) && $request->getHeaderLine($this->header) === $tokenID)
57
+        {
56 58
             return $response;
57 59
         }
58 60
 
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/HeaderTransportTest.php 2 patches
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,9 +43,9 @@  discard block
 block discarded – undo
43 43
 
44 44
         $http->setHandler(
45 45
             static function (ServerRequestInterface $request, ResponseInterface $response): void {
46
-                if ($request->getAttribute('authContext')->getToken() === null) {
46
+                if ($request->getAttribute('authContext')->getToken() === null){
47 47
                     echo 'no token';
48
-                } else {
48
+                }else{
49 49
                     echo $request->getAttribute('authContext')->getToken()->getID();
50 50
                     echo ':';
51 51
                     echo json_encode($request->getAttribute('authContext')->getToken()->getPayload());
@@ -67,9 +67,9 @@  discard block
 block discarded – undo
67 67
 
68 68
         $http->setHandler(
69 69
             static function (ServerRequestInterface $request, ResponseInterface $response): void {
70
-                if ($request->getAttribute('authContext')->getToken() === null) {
70
+                if ($request->getAttribute('authContext')->getToken() === null){
71 71
                     echo 'no token';
72
-                } else {
72
+                }else{
73 73
                     echo $request->getAttribute('authContext')->getToken()->getID();
74 74
                     echo ':';
75 75
                     echo json_encode($request->getAttribute('authContext')->getToken()->getPayload());
Please login to merge, or discard this patch.
Braces   +10 added lines, -4 removed lines patch added patch discarded remove patch
@@ -43,9 +43,12 @@  discard block
 block discarded – undo
43 43
 
44 44
         $http->setHandler(
45 45
             static function (ServerRequestInterface $request, ResponseInterface $response): void {
46
-                if ($request->getAttribute('authContext')->getToken() === null) {
46
+                if ($request->getAttribute('authContext')->getToken() === null)
47
+                {
47 48
                     echo 'no token';
48
-                } else {
49
+                }
50
+                else
51
+                {
49 52
                     echo $request->getAttribute('authContext')->getToken()->getID();
50 53
                     echo ':';
51 54
                     echo json_encode($request->getAttribute('authContext')->getToken()->getPayload());
@@ -67,9 +70,12 @@  discard block
 block discarded – undo
67 70
 
68 71
         $http->setHandler(
69 72
             static function (ServerRequestInterface $request, ResponseInterface $response): void {
70
-                if ($request->getAttribute('authContext')->getToken() === null) {
73
+                if ($request->getAttribute('authContext')->getToken() === null)
74
+                {
71 75
                     echo 'no token';
72
-                } else {
76
+                }
77
+                else
78
+                {
73 79
                     echo $request->getAttribute('authContext')->getToken()->getID();
74 80
                     echo ':';
75 81
                     echo json_encode($request->getAttribute('authContext')->getToken()->getPayload());
Please login to merge, or discard this patch.