Completed
Pull Request — behat-2.x (#43)
by Timothée
10:30
created

XmlStorage::readXml()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 10
rs 9.4285
cc 3
eloc 6
nc 3
nop 1
1
<?php
2
3
namespace Rezzza\RestApiBehatExtension\Xml;
4
5
use Rezzza\RestApiBehatExtension\Response\ResponseStorage;
6
7
/**
8
 * Store the XML that we could analyze it in XmlContext
9
 */
10
class XmlStorage
11
{
12
    private $responseStorage;
13
14
    public function __construct(ResponseStorage $responseStorage)
15
    {
16
        $this->responseStorage = $responseStorage;
17
    }
18
19
    public function writeRawContent($content)
20
    {
21
        $this->responseStorage->writeRawContent($content);
22
    }
23
24
    /**
25
     * @return Xml
26
     */
27
    public function readXml($throwExceptions)
28
    {
29
        try {
30
            return new Xml($this->responseStorage->read());
31
        } catch(\DOMException $e) {
32
            if ($throwExceptions) {
33
                throw new \RuntimeException($e->getMessage());
34
            }
35
        }
36
    }
37
}
38