| Conditions | 6 |
| Paths | 2 |
| Total Lines | 62 |
| Code Lines | 42 |
| 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); |
||
| 61 | public function testV2EncryptedRequestAndResponse() |
||
| 62 | { |
||
| 63 | foreach ($this->testCases as $k => $params) { |
||
| 64 | $serverKey = EncryptionKey::generate(); |
||
| 65 | $myKey = EncryptionKey::generate(); |
||
| 66 | $cache = Psr16MemoryCache::instance(); |
||
| 67 | $cache->set($serverKey->getHashIdentifier(), $serverKey); |
||
| 68 | |||
| 69 | $auth = new Authorization($params[0], $params[1], $this->token, new DateTime, $params[2]); |
||
| 70 | $token = $this->token; |
||
| 71 | |||
| 72 | $response = Dispatcher::run( |
||
| 73 | [ |
||
| 74 | new RequestParser($cache), |
||
| 75 | new Authentication, |
||
| 76 | function ($request, $next) use ($params) { |
||
| 77 | $this->assertInstanceOf('\ncryptf\Token', $request->getAttribute('ncryptf-token')); |
||
| 78 | $this->assertEquals(true, \is_array($request->getAttribute('ncryptf-user'))); |
||
| 79 | return $next->handle($request); |
||
| 80 | }, |
||
| 81 | new ResponseFormatter(new EncryptionKey), |
||
| 82 | new EchoResponse, |
||
| 83 | ], |
||
| 84 | Factory::createServerRequest($params[0], $params[1]) |
||
| 85 | ->withHeader('Authorization', $auth->getHeader()) |
||
| 86 | ->withHeader('Content-Type', 'application/vnd.ncryptf+json') |
||
| 87 | ->withHeader('Accept', 'application/vnd.ncryptf+json') |
||
| 88 | ->withHeader('X-HashId', $serverKey->getHashIdentifier()) |
||
| 89 | ->withHeader('X-PubKey', \base64_encode($myKey->getBoxPublicKey())) |
||
| 90 | ->withBody((function () use ($params, $serverKey, $myKey, $token) { |
||
| 91 | $data = \is_array($params[2]) ? \json_encode($params[2]): $params[2]; |
||
| 92 | |||
| 93 | if (!empty($params[2])) { |
||
| 94 | $request = new Request( |
||
| 95 | $myKey->getBoxSecretKey(), |
||
| 96 | $token->signature |
||
| 97 | ); |
||
| 98 | |||
| 99 | $encryptedData = $request->encrypt( |
||
| 100 | $data, |
||
| 101 | $serverKey->getBoxPublicKey() |
||
| 102 | ); |
||
| 103 | } |
||
| 104 | $stream = fopen('php://memory', 'r+'); |
||
| 105 | fwrite($stream, empty($params[2]) ? '' : \base64_encode($encryptedData)); |
||
| 106 | rewind($stream); |
||
| 107 | return new \Zend\Diactoros\Stream($stream); |
||
| 108 | })()) |
||
| 109 | ); |
||
| 110 | |||
| 111 | $this->assertSame('application/vnd.ncryptf+json', $response->getHeaderLine('Content-Type')); |
||
| 112 | $this->assertTrue($response->hasHeader('x-hashid')); |
||
| 113 | |||
| 114 | $r = new Response( |
||
| 115 | $myKey->getBoxSecretKey() |
||
| 116 | ); |
||
| 117 | |||
| 118 | $plaintext = $r->decrypt( |
||
| 119 | \base64_decode((string)$response->getBody()) |
||
| 120 | ); |
||
| 121 | |||
| 122 | $this->assertEquals(\is_array($params[2]) ? \json_encode($params[2]) : $params[2], $plaintext); |
||
| 123 | } |
||
| 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