Completed
Push — master ( 2b8aa3...9a2a4c )
by David
06:24
created

ResponseSeekableBodyPlugin::handleRequest()   A

Complexity

Conditions 2
Paths 1

Size

Total Lines 10

Duplication

Lines 10
Ratio 100 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 0
Metric Value
dl 10
loc 10
ccs 5
cts 5
cp 1
rs 9.9332
c 0
b 0
f 0
cc 2
nc 1
nop 3
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Http\Client\Common\Plugin;
6
7
use Http\Message\Stream\BufferedStream;
8
use Http\Promise\Promise;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
/**
13
 * Allow body used in response to be always seekable.
14
 *
15
 * @author Joel Wurtz <[email protected]>
16
 */
17 View Code Duplication
final class ResponseSeekableBodyPlugin extends SeekableBodyPlugin
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22 2
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
23
    {
24
        return $next($request)->then(function (ResponseInterface $response) {
25 2
            if ($response->getBody()->isSeekable()) {
26 1
                return $response;
27
            }
28
29 1
            return $response->withBody(new BufferedStream($response->getBody(), $this->useFileBuffer, $this->memoryBufferSize));
30 2
        });
31
    }
32
}
33