Conditions | 9 |
Paths | 5 |
Total Lines | 51 |
Code Lines | 34 |
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); |
||
59 | public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface |
||
60 | { |
||
61 | if ($this->checkRequest($request)) { |
||
62 | $response = $handler->handle($request); |
||
63 | $version = $request->getAttribute('ncryptf-version'); |
||
64 | $publicKey = $request->getAttribute('ncryptf-request-public-key'); |
||
65 | $token = $request->getAttribute('ncryptf-token'); |
||
66 | |||
67 | if ($version === null || $publicKey === null) { |
||
68 | return $response->withStatus(400, 'Unable to encrypt request.'); |
||
69 | } |
||
70 | |||
71 | if (!($response instanceof MessageInterface)) { |
||
72 | throw new Exception('Response does not implement MessageInterface.'); |
||
73 | } |
||
74 | |||
75 | $stream = $response->getBody(); |
||
76 | $class = $this->key; |
||
77 | $key = $class::generate(); |
||
78 | |||
79 | $this->cache->set($key->getHashIdentifier(), $key); |
||
80 | |||
81 | $r = new Request( |
||
82 | $key->getBoxSecretKey(), |
||
83 | $token === null ? $key->getSignSecretKey() : $token->signature |
||
84 | ); |
||
85 | |||
86 | $content = $r->encrypt( |
||
87 | (string)$stream, |
||
88 | $publicKey, |
||
89 | $version, |
||
90 | $version === 2 ? null : \random_bytes(SODIUM_CRYPTO_BOX_NONCEBYTES) |
||
91 | ); |
||
92 | |||
93 | if ($version === 1) { |
||
94 | $response = $response->withHeader('x-sigpubkey', \base64_encode($token === null ? $key->getSignPublicKey() : $token->getSignaturePublicKey())) |
||
95 | ->withHeader('x-signature', \base64_encode($r->sign((string)$stream))) |
||
96 | ->withHeader('x-public-key-expiration', $key->getPublicKeyExpiration()) |
||
97 | ->withHeader('x-nonce', \base64_encode($r->getNonce())) |
||
98 | ->withHeader('x-pubkey', \base64_encode($key->getBoxPublicKey())); |
||
99 | } |
||
100 | |||
101 | $stream->rewind(); |
||
102 | $stream->write(\base64_encode($content)); |
||
103 | return $response->withBody($stream) |
||
104 | ->withHeader('Content-Type', 'application/vnd.ncryptf+json') |
||
105 | ->withHeader('x-hashid', \base64_encode($key->getHashIdentifier())); |
||
106 | } |
||
107 | |||
108 | return $handler->handle($request) |
||
109 | ->withHeader('Content-Type', 'application/vnd.ncryptf+json'); |
||
110 | } |
||
128 |
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