Completed
Push — master ( 15e9d9...1109c2 )
by Anton
03:03
created

WithCustomHost::send()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 4
nc 1
nop 1
1
<?php
2
3
namespace Covery\Client\Transport;
4
5
use Covery\Client\TransportInterface;
6
use Psr\Http\Message\RequestInterface;
7
8
/**
9
 * Class WithCustomHost
10
 *
11
 * Special transport implementation, that allows replacement
12
 * of Covery hostname
13
 *
14
 * @package Covery\Client\Transport
15
 */
16
class WithCustomHost implements TransportInterface
17
{
18
    /**
19
     * @var string
20
     */
21
    private $host;
22
    /**
23
     * @var string
24
     */
25
    private $scheme;
26
27
    /**
28
     * @var TransportInterface
29
     */
30
    private $transport;
31
32
    /**
33
     * WithCustomUrl constructor.
34
     *
35
     * @param TransportInterface $transport
36
     * @param string $host
37
     * @param string $scheme
38
     */
39
    public function __construct(TransportInterface $transport, $host, $scheme = 'https')
40
    {
41 View Code Duplication
        if (!is_string($host)) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
42
            throw new \InvalidArgumentException('Host must be string');
43
        } elseif (empty($host)) {
44
            throw new \InvalidArgumentException('Host must be not empty');
45
        }
46
47
        if (!is_string($scheme)) {
48
            throw new \InvalidArgumentException('Scheme must be string');
49
        }
50
51
        $this->transport = $transport;
52
        $this->host = $host;
53
        $this->scheme = $scheme;
54
    }
55
56
    /**
57
     * @inheritDoc
58
     */
59
    public function send(RequestInterface $request)
60
    {
61
        $request = $request->withUri(
62
            $request->getUri()->withHost($this->host)->withScheme($this->scheme)
63
        );
64
65
        return $this->transport->send($request);
66
    }
67
}
68