Passed
Push — master ( 14d404...4bd91f )
by C.
02:09
created

Processor   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 4
dl 0
loc 27
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A processResponse() 0 17 4
1
<?php
2
3
/*
4
 * This file is part of PHP CS Fixer.
5
 *
6
 * (c) Fabien Potencier <[email protected]>
7
 *     Dariusz Rumiński <[email protected]>
8
 *
9
 * This source file is subject to the MIT license that is bundled
10
 * with this source code in the file LICENSE.
11
 */
12
13
namespace Etrias\PaazlConnector\Processor;
14
15
use Etrias\PaazlConnector\ExceptionMap;
16
use Etrias\PaazlConnector\Exceptions\PaazlException;
17
use Etrias\PaazlConnector\SoapClient;
18
use WsdlToPhp\PackageBase\AbstractStructBase;
19
20
trait Processor
21
{
22
    /**
23
     * @param $response
24
     * @param SoapClient $soapClient
25
     *
26
     * @throws PaazlException
27
     *
28
     * @return mixed
29
     */
30
    public function processResponse($response, SoapClient $soapClient)
31
    {
32
        if ($response === false) {
33
            $errors = $soapClient->getLastError();
34
            throw end($errors);
35
        }
36
37
        if ($response->getError()) {
38
            $exceptionName = ExceptionMap::getException($response->getError()->getCode());
39
            throw new $exceptionName();
40
        }
41
42
        if (!($response instanceof AbstractStructBase)) {
43
            throw new PaazlException('Response is not a AbstructStructBase class');
44
        }
45
46
        return $response;
47
    }
48
}
49