Psr18ClientTrait   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 1
Metric Value
eloc 13
c 3
b 1
f 1
dl 0
loc 26
ccs 8
cts 8
cp 1
rs 10
wmc 2

1 Method

Rating   Name   Duplication   Size   Complexity  
A sendRequest() 0 17 2
1
<?php
2
3
/*
4
 * This file is part of the Koded package.
5
 *
6
 * (c) Mihail Binev <[email protected]>
7
 *
8
 * Please view the LICENSE distributed with this source code
9
 * for the full copyright and license information.
10
 *
11
 */
12
13
namespace Koded\Http\Client;
14
15
use Koded\Http\Interfaces\HttpStatus;
16
use Psr\Http\Message\{RequestInterface, ResponseInterface};
17
18
trait Psr18ClientTrait
19
{
20
    /**
21
     * Sends a PSR-7 request and returns a PSR-7 response.
22
     *
23
     * @param RequestInterface $request
24
     * @return ResponseInterface
25
     * @throws \Psr\Http\Client\ClientExceptionInterface If an error happens while processing the request.
26
     */
27
    public function sendRequest(RequestInterface $request): ResponseInterface
28
    {
29
        /** @var ResponseInterface $response */
30
        $response = $this
31
            ->withMethod($request->getMethod())
0 ignored issues
show
Bug introduced by
It seems like withMethod() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

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

31
            ->/** @scrutinizer ignore-call */ withMethod($request->getMethod())
Loading history...
32 10
            ->withUri($request->getUri())
33
            ->withHeaders($request->getHeaders())
34
            ->withBody($request->getBody())
35
            ->read();
36 10
37 10
        if ($response->getStatusCode() >= HttpStatus::BAD_REQUEST) {
38 10
            throw new Psr18Exception(
39 10
                $response->getBody()->getContents(),
40 10
                $response->getStatusCode(),
41
                $request);
42 10
        }
43 6
        return $response;
44
    }
45
}
46