Completed
Pull Request — v1 (#422)
by
unknown
03:19
created

SoapResponseHandler   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 1 Features 0
Metric Value
wmc 2
c 3
b 1
f 0
lcom 0
cbo 1
dl 0
loc 35
ccs 17
cts 17
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A handle() 0 8 1
A toXml() 0 16 1
1
<?php
2
/**
3
 * Whoops - php errors for cool kids
4
 * @author Filipe Dobreira <http://github.com/filp>
5
 */
6
7
namespace Whoops\Handler;
8
9
/**
10
 * Catches an exception and converts it to an Soap XML
11
 * response.
12
 *
13
 * @author Markus Staab <http://github.com/staabm>
14
 */
15
class SoapResponseHandler extends Handler
16
{
17
    /**
18
     * @return int
19
     */
20 1
    public function handle()
21
    {
22 1
        $exception = $this->getException();
23
24 1
        echo $this->toXml($exception);
25
26 1
        return Handler::QUIT;
27
    }
28
29
    /**
30
     * Converts a Throwable or Exception object into a SoapFault XML
31
     * @param mixed $exception
32
     */
33 1
    private function toXml($exception)
34
    {
35 1
        $xml = '';
36 1
        $xml .= '<?xml version="1.0" encoding="UTF-8"?>';
37 1
        $xml .= '<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">';
38 1
        $xml .= '  <SOAP-ENV:Body>';
39 1
        $xml .= '    <SOAP-ENV:Fault>';
40 1
        $xml .= '      <faultcode>'. htmlspecialchars($exception->getCode()) .'</faultcode>';
41 1
        $xml .= '      <faultstring>'. htmlspecialchars($exception->getMessage()) .'</faultstring>';
42 1
        $xml .= '      <detail><trace>'. htmlspecialchars($exception->getTraceAsString()) .'</trace></detail>';
43 1
        $xml .= '    </SOAP-ENV:Fault>';
44 1
        $xml .= '  </SOAP-ENV:Body>';
45 1
        $xml .= '</SOAP-ENV:Envelope>';
46
47 1
        return $xml;
48
    }
49
}
50