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

Fault::createException()   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 3
1
<?php
2
3
namespace GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages;
4
5
use GoetasWebservices\SoapServices\Metadata\Exception\Fault11Exception;
0 ignored issues
show
Bug introduced by
The type GoetasWebservices\SoapSe...eption\Fault11Exception 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...
6
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...
7
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...
8
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...
9
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...
10
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...
11
use Psr\Http\Message\RequestInterface;
12
use Psr\Http\Message\ResponseInterface;
13
14
/**
15
 * Class representing Body
16
 */
17
class Fault
18
{
19
20
    /**
21
     * @var \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\FaultBody $body
22
     */
23
    private $body = null;
24
25
    /**
26
     * Gets as body
27
     *
28
     * @return \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\FaultBody
29
     */
30
    public function getBody()
31
    {
32
        return $this->body;
33
    }
34
35
    /**
36
     * Sets a new body
37
     *
38
     * @param \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\FaultBody $body
39
     * @return self
40
     */
41
    public function setBody(\GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Messages\FaultBody $body)
42
    {
43
        $this->body = $body;
44
        return $this;
45
    }
46
47
    public static function fromException(\Throwable $e, bool $debug = false): self
48
    {
49
        $faultEnvelope = new self();
50
        $faultBody = new FaultBody();
51
        $faultEnvelope->setBody($faultBody);
52
53
        $fault = new \GoetasWebservices\SoapServices\Metadata\Envelope\SoapEnvelope\Parts\Fault();
54
        if (!$e instanceof FaultException) {
55
            $e = new ServerException($e->getMessage(), $e->getCode(), $e);
56
        }
57
58
        if ($e instanceof ClientException) {
59
            $fault->setCode('SOAP:Client');
60
        }elseif ($e instanceof VersionMismatchException) {
61
            $fault->setCode('SOAP:VersionMismatch');
62
        }elseif ($e instanceof MustUnderstandException) {
63
            $fault->setCode('SOAP:MustUnderstand');
64
        } else {
65
            $fault->setCode('SOAP:Server');
66
        }
67
68
        if ($debug) {
69
            $fault->setString(implode("\n", array_merge([$e->getMessage()], explode("\n", (string)$e))));
70
        } else {
71
            $fault->setString($e->getMessage());
72
        }
73
74
        // @todo implement detail wrapping
75
        $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

75
        $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...
76
77
        $faultBody->setFault($fault);
78
        return $faultEnvelope;
79
    }
80
81
    /**
82
     * @param ResponseInterface $response
83
     * @param RequestInterface $request
84
     * @param \Exception $e
85
     * @return \GoetasWebservices\SoapServices\Metadata\Exception\Fault11Exception
86
     */
87
    public function createException(ResponseInterface $response, RequestInterface $request, \Exception $e = null)
88
    {
89
        return new Fault11Exception($this->getBody()->getFault(), $response, $request, $e);
90
    }
91
}
92
93