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

RequestSeekableBodyPlugin   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 14
Duplicated Lines 100 %

Coupling/Cohesion

Components 1
Dependencies 4

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 2
lcom 1
cbo 4
dl 14
loc 14
ccs 4
cts 4
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A handleRequest() 8 8 2

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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
11
/**
12
 * Allow body used in request to be always seekable.
13
 *
14
 * @author Joel Wurtz <[email protected]>
15
 */
16 View Code Duplication
final class RequestSeekableBodyPlugin 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...
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21 2
    public function handleRequest(RequestInterface $request, callable $next, callable $first): Promise
22
    {
23 2
        if (!$request->getBody()->isSeekable()) {
24 1
            $request = $request->withBody(new BufferedStream($request->getBody(), $this->useFileBuffer, $this->memoryBufferSize));
25
        }
26
27 2
        return $next($request);
28
    }
29
}
30