ListRecordsResponse::__construct()   B
last analyzed

Complexity

Conditions 6
Paths 11

Size

Total Lines 30
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 30
rs 8.439
c 0
b 0
f 0
cc 6
eloc 16
nc 11
nop 2
1
<?php namespace Scriptotek\OaiPmh;
2
3
/**
4
 * ListRecords response, containing a list of records or some error
5
 */
6
class ListRecordsResponse extends Response
7
{
8
 
9
    /** @var Record[] Array of records */
10
    public $records;
11
12
    /** @var int Total number of records in the result set */
13
    public $numberOfRecords = null;
14
15
    /** @var int Position of the first record in the response relative to the result set (starts at 0) */
16
    public $cursor = null;
17
18
    /** @var int Token for retrieving more records */
19
    public $resumptionToken = null;
20
21
    /**
22
     * Create a new ListRecords response
23
     *
24
     * @param string $text Raw XML response
25
     * @param Client $client OAI-PMH client reference (optional)
26
     */
27
    public function __construct($text, &$client = null)
28
    {
29
        parent::__construct($text, $client);
30
31
        $this->records = array();
32
33
        $records = $this->response->first('/oai:OAI-PMH/oai:ListRecords');
34
        if (!$records) {
35
            return;
36
        }
37
38
        foreach ($records->xpath('oai:record') as $record) {
39
            $this->records[] = new Record($record);
40
        }
41
42
        $resumptionToken = $records->first('oai:resumptionToken');
43
        if (!$resumptionToken) {
44
            return;
45
        }
46
47
        $this->resumptionToken = $resumptionToken->text();
48
        
49
        // These are optional:
50
        if ($resumptionToken->attr('completeListSize') !== '') {
51
            $this->numberOfRecords = intval($resumptionToken->attr('completeListSize'));
52
        }
53
        if ($resumptionToken->attr('cursor') !== '') {
54
            $this->cursor = intval($resumptionToken->attr('cursor'));
55
        }
56
    }
57
}
58