Response   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 58
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 29 2
A asXml() 0 4 1
1
<?php namespace Scriptotek\OaiPmh;
2
3
use Danmichaelo\QuiteSimpleXMLElement\QuiteSimpleXMLElement;
4
5
/**
6
 * Generic OAI-PMH response
7
 */
8
class Response
9
{
10
11
    /** @var string Raw XML response */
12
    protected $rawResponse;
13
14
    /** @var QuiteSimpleXMLElement XML response */
15
    protected $response;
16
17
    /** @var Client Reference to OAI-PMH client object */
18
    protected $client;
19
20
    /**
21
     * Create a new response
22
     *
23
     * @param string $text Raw XML response
24
     * @param Client $client OAI-PMH client reference (optional)
25
     */
26
    public function __construct($text, &$client = null)
27
    {
28
        $this->rawResponse = $text;
29
30
        // Throws Danmichaelo\QuiteSimpleXMLElement\InvalidXMLException on invalid xml
31
        $this->response = new QuiteSimpleXMLElement($text);
32
33
        $this->client = $client;
34
35
        $this->response->registerXPathNamespaces(array(
36
            'oai' => 'http://www.openarchives.org/OAI/2.0/',
37
        ));
38
39
        /* Possible error codes:
40
            badArgument
41
            badResumptionToken
42
            badVerb
43
            cannotDisseminateFormat
44
            idDoesNotExist
45
            noRecordsMatch
46
            noMetaDataFormats
47
            noSetHierarchy
48
           http://www.openarchives.org/OAI/openarchivesprotocol.html#ErrorConditions
49
        */
50
        $err = $this->response->first('/oai:OAI-PMH/oai:error');
51
        if ($err) {
52
            throw new BadRequestError($err->attr('code') . ' : ' . $err->text());
53
        }
54
    }
55
56
    /**
57
     * Get the raw xml response
58
     *
59
     * @return string
60
     */
61
    public function asXml()
62
    {
63
        return $this->rawResponse;
64
    }
65
}
66