Passed
Push — ref ( 45b89b )
by Asmir
02:50
created

Fault::getBody()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
rs 10
cc 1
nc 1
nop 0
1
<?php
2
3
namespace GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages;
4
5
use GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\FaultCode;
6
use GoetasWebservices\SoapServices\Metadata\Exception\Fault12Exception;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...eption\Fault12Exception was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
7
use GoetasWebservices\SoapServices\SoapServer\Exception\ClientException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...ception\ClientException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
8
use GoetasWebservices\SoapServices\SoapServer\Exception\FaultException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...xception\FaultException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use GoetasWebservices\SoapServices\SoapServer\Exception\MustUnderstandException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...MustUnderstandException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use GoetasWebservices\SoapServices\SoapServer\Exception\ServerException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...ception\ServerException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use GoetasWebservices\SoapServices\SoapServer\Exception\SoapServerException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...ion\SoapServerException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use GoetasWebservices\SoapServices\SoapServer\Exception\VersionMismatchException;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...ersionMismatchException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
13
use Psr\Http\Message\RequestInterface;
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * Class representing Body
18
 */
19
class Fault
20
{
21
22
    /**
23
     * @var \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\FaultBody $body
24
     */
25
    private $body = null;
26
27
    /**
28
     * Gets as body
29
     *
30
     * @return \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\FaultBody
31
     */
32
    public function getBody()
33
    {
34
        return $this->body;
35
    }
36
37
    /**
38
     * Sets a new body
39
     *
40
     * @param \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\FaultBody $body
41
     * @return self
42
     */
43
    public function setBody(\GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Messages\FaultBody $body)
44
    {
45
        $this->body = $body;
46
        return $this;
47
    }
48
49
    public static function fromException(\Throwable $e, bool $debug = false): self
50
    {
51
        $faultEnvelope = new self();
52
        $faultBody = new FaultBody();
53
        $faultEnvelope->setBody($faultBody);
54
55
        $fault = new \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope12\Parts\Fault();
56
        if (!$e instanceof FaultException) {
57
            $e = new ServerException($e->getMessage(), $e->getCode(), $e);
58
        }
59
60
        $faultCode = new FaultCode();
61
62
        if ($e instanceof VersionMismatchException) {
63
            $faultCode->setValue('SOAP:VersionMismatch');
64
        }elseif ($e instanceof MustUnderstandException) {
65
            $faultCode->setValue('SOAP:MustUnderstand');
66
        }elseif ($e instanceof ClientException) {
67
            $faultCode->setValue('SOAP:Sender');
68
        } else {
69
            $faultCode->setValue('SOAP:Receiver');
70
        }
71
72
        if ($e->getCode() !== 0) {
73
            $subFaultCode = new FaultCode();
74
            $subFaultCode->setValue($e->getCode());
75
76
            $faultCode->setSubcode($subFaultCode);
77
        }
78
79
        $fault->setCode($faultCode);
80
        if ($debug) {
81
            $fault->setReason(array_merge([$e->getMessage()], explode("\n", (string)$e)));
82
        } else {
83
            $fault->setReason(explode("\n", $e->getMessage()));
84
        }
85
86
        // @todo implement detail wrapping
87
        $fault->setDetail($e->getDetail());
0 ignored issues
show
Bug introduced by
The method getDetail() does not exist on Throwable. ( Ignorable by Annotation )

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

87
        $fault->setDetail($e->/** @scrutinizer ignore-call */ getDetail());

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
88
89
90
        $faultBody->setFault($fault);
91
        return $faultEnvelope;
92
    }
93
94
    /**
95
     * @param ResponseInterface $response
96
     * @param RequestInterface $request
97
     * @param \Exception $e
98
     * @return \GoetasWebservices\SoapServices\Metadata\Exception\FaultException
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...xception\FaultException was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
99
     */
100
    public function createException(ResponseInterface $response, RequestInterface $request, \Exception $e = null)
101
    {
102
        return new Fault12Exception($this->getBody()->getFault(), $response, $request, $e);
103
    }
104
}
105
106