Test Failed
Push — master ( 40a540...b96576 )
by Mariano
01:45
created

ArrayToProxyResponseConverter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 8
dl 0
loc 20
rs 10
c 0
b 0
f 0
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A convertResponse() 0 13 2
A convert() 0 3 1
1
<?php
2
/**
3
 * This file is part of Phiremock.
4
 *
5
 * Phiremock is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Lesser General Public License as published by
7
 * the Free Software Foundation, either version 3 of the License, or
8
 * (at your option) any later version.
9
 *
10
 * Phiremock is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with Phiremock.  If not, see <http://www.gnu.org/licenses/>.
17
 */
18
19
namespace Mcustiel\Phiremock\Common\Utils\V1;
20
21
use Mcustiel\Phiremock\Common\Utils\ArrayToProxyResponseConverter as ArrayToProxyResponseConverterInterface;
22
use Mcustiel\Phiremock\Domain\Http\Uri;
23
use Mcustiel\Phiremock\Domain\Options\Delay;
24
use Mcustiel\Phiremock\Domain\Options\ScenarioState;
25
use Mcustiel\Phiremock\Domain\ProxyResponse;
26
use Mcustiel\Phiremock\Domain\Response;
27
28
class ArrayToProxyResponseConverter extends ArrayToResponseConverter implements ArrayToProxyResponseConverterInterface
29
{
30
    public function convert(array $responseArray): ProxyResponse
31
    {
32
        return parent::convert($responseArray);
0 ignored issues
show
Bug Best Practice introduced by
The expression return parent::convert($responseArray) returns the type Mcustiel\Phiremock\Domain\Response which includes types incompatible with the type-hinted return Mcustiel\Phiremock\Domain\ProxyResponse.
Loading history...
33
    }
34
35
    protected function convertResponse(
36
        array $responseArray,
37
        ?Delay $delay,
38
        ?ScenarioState $newScenarioState
39
    ): Response {
40
        if (empty($responseArray['proxyTo'])) {
41
            throw new \InvalidArgumentException('Trying to create a proxied response with an empty uri');
42
        }
43
44
        return new ProxyResponse(
45
            new Uri($responseArray['proxyTo']),
46
            $delay,
47
            $newScenarioState
48
        );
49
    }
50
}
51