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

73
        $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...
74
75
        $faultBody->setFault($fault);
76
77
        return $faultEnvelope;
78
    }
79
80
    public function createException(ResponseInterface $response, RequestInterface $request, ?\Throwable $e = null): Fault11Exception
81
    {
82
        return new Fault11Exception($this->getBody()->getFault(), $response, $request, $e);
83
    }
84
}
85