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

XmlStorage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 28
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 2
Bugs 0 Features 1
Metric Value
wmc 5
c 2
b 0
f 1
lcom 1
cbo 2
dl 0
loc 28
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A writeRawContent() 0 4 1
A readXml() 0 10 3
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