Conditions | 6 |
Paths | 3 |
Total Lines | 73 |
Code Lines | 53 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | <?php declare(strict_types=1); |
||
126 | public function testV1EncryptedRequestAndResponse() |
||
127 | { |
||
128 | foreach ($this->testCases as $k => $params) { |
||
129 | $serverKey = EncryptionKey::generate(); |
||
130 | $myKey = EncryptionKey::generate(); |
||
131 | $nonce = \random_bytes(24); |
||
132 | $cache = Psr16MemoryCache::instance(); |
||
133 | $cache->set($serverKey->getHashIdentifier(), $serverKey); |
||
134 | |||
135 | $auth = new Authorization($params[0], $params[1], $this->token, new DateTime, $params[2]); |
||
136 | $token = $this->token; |
||
137 | $response = Dispatcher::run( |
||
138 | [ |
||
139 | new RequestParser($cache), |
||
140 | new Authentication, |
||
141 | function ($request, $next) { |
||
142 | $this->assertInstanceOf('\ncryptf\Token', $request->getAttribute('ncryptf-token')); |
||
143 | $this->assertEquals(true, \is_array($request->getAttribute('ncryptf-user'))); |
||
144 | return $next->handle($request); |
||
145 | }, |
||
146 | new ResponseFormatter(new EncryptionKey), |
||
147 | new EchoResponse, |
||
148 | ], |
||
149 | Factory::createServerRequest($params[0], $params[1]) |
||
150 | ->withHeader('Authorization', $auth->getHeader()) |
||
151 | ->withHeader('Content-Type', 'application/vnd.25519+json') |
||
152 | ->withHeader('Accept', 'application/vnd.25519+json') |
||
153 | ->withHeader('X-HashId', $serverKey->getHashIdentifier()) |
||
154 | ->withHeader('X-Nonce', \base64_encode($nonce)) |
||
155 | ->withHeader('X-PubKey', \base64_encode($myKey->getBoxPublicKey())) |
||
156 | ->withBody((function () use ($params, $serverKey, $myKey, $nonce, $token) { |
||
157 | $data = \is_array($params[2]) ? \json_encode($params[2]): $params[2]; |
||
158 | |||
159 | $request = new Request( |
||
160 | $myKey->getBoxSecretKey(), |
||
161 | $token->signature |
||
162 | ); |
||
163 | |||
164 | $encryptedData = $request->encrypt( |
||
165 | $data, |
||
166 | $serverKey->getBoxPublicKey(), |
||
167 | 1, |
||
168 | $nonce |
||
169 | ); |
||
170 | $stream = fopen('php://memory', 'r+'); |
||
171 | fwrite($stream, $data === '' ? '' : \base64_encode($encryptedData)); |
||
172 | rewind($stream); |
||
173 | return new \Zend\Diactoros\Stream($stream); |
||
174 | })()) |
||
175 | ); |
||
176 | |||
177 | $this->assertSame(200, $response->getStatusCode()); |
||
178 | $this->assertSame('application/vnd.ncryptf+json', $response->getHeaderLine('Content-Type')); |
||
179 | if ($params[2] !== '') { |
||
180 | $this->assertTrue($response->hasHeader('x-hashid')); |
||
181 | $this->assertTrue($response->hasHeader('x-signature')); |
||
182 | $this->assertTrue($response->hasHeader('x-sigpubkey')); |
||
183 | $this->assertTrue($response->hasHeader('x-nonce')); |
||
184 | $this->assertTrue($response->hasHeader('x-pubkey')); |
||
185 | $this->assertTrue($response->hasHeader('x-public-key-expiration')); |
||
186 | } |
||
187 | |||
188 | $r = new Response( |
||
189 | $myKey->getBoxSecretKey() |
||
190 | ); |
||
191 | |||
192 | $plaintext = $r->decrypt( |
||
193 | \base64_decode((string)$response->getBody()), |
||
194 | \base64_decode($response->getHeaderLine('x-pubkey')), |
||
195 | \base64_decode($response->getHeaderLine('x-nonce')) |
||
196 | ); |
||
197 | |||
198 | $this->assertEquals(\is_array($params[2]) ? \json_encode($params[2]) : $params[2], $plaintext); |
||
199 | } |
||
221 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths