Passed
Push — master ( 34eaf6...149dd5 )
by Charles
02:52
created

EchoResponse   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 15
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 6
dl 0
loc 15
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A process() 0 7 1
1
<?php declare(strict_types=1);
2
3
namespace ncryptf\Tests\mock;
4
5
use Exception;
6
7
use Middlewares\Utils\Factory;
8
9
use Psr\Http\Message\StreamInterface;
10
use Psr\Http\Message\MessageInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
use Psr\Http\Server\MiddlewareInterface;
14
use Fig\Http\Message\StatusCodeInterface;
0 ignored issues
show
Bug introduced by
The type Fig\Http\Message\StatusCodeInterface was not found. Maybe you did not declare it correctly or list all dependencies?

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:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
15
use Psr\Http\Message\ServerRequestInterface;
16
use Psr\Http\Server\RequestHandlerInterface;
17
18
/**
19
 * A simple response middleware that echo's the request back to the user
20
 */
21
final class EchoResponse implements MiddlewareInterface
22
{
23
    /**
24
     * Echoes the request back out to the response
25
     * @param ServerRequestInterface $request
26
     * @param RequestHandlerInterface $handler
27
     * @return ResponseInterface
28
     */
29
    public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
30
    {
31
        $stream = fopen('php://memory', 'r+');
32
        fwrite($stream, $request->getAttribute('ncryptf-decrypted-body'));
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of fwrite() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

32
        fwrite(/** @scrutinizer ignore-type */ $stream, $request->getAttribute('ncryptf-decrypted-body'));
Loading history...
33
        rewind($stream);
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $handle of rewind() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
        rewind(/** @scrutinizer ignore-type */ $stream);
Loading history...
34
        return Factory::createResponse()
35
            ->withBody(new \Zend\Diactoros\Stream($stream));
0 ignored issues
show
Bug introduced by
It seems like $stream can also be of type false; however, parameter $stream of Zend\Diactoros\Stream::__construct() does only seem to accept resource|string, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

35
            ->withBody(new \Zend\Diactoros\Stream(/** @scrutinizer ignore-type */ $stream));
Loading history...
36
    }
37
}
38