XmlResponse::__construct()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 12
rs 9.8666
c 0
b 0
f 0
cc 2
nc 2
nop 6
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Furious\Psr7\Response;
6
7
use Furious\Psr7\Response;
8
use SimpleXMLElement;
9
10
class XmlResponse extends Response
11
{
12
    public function __construct($xml, int $statusCode = 200, array $headers = [], $body = null, string $version = '1.1', string $reason = null)
13
    {
14
        if ($xml instanceof SimpleXMLElement) {
15
            $body = $xml->asXML();
16
        } else {
17
            $body = (string) $xml;
18
        }
19
20
        parent::__construct($statusCode, $headers + [
21
            'Content-Type' => 'application/xml'
22
        ], $body, $version, $reason);
23
    }
24
}