ListRecordsResponse   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 0
Metric Value
wmc 6
lcom 0
cbo 3
dl 0
loc 52
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B __construct() 0 30 6
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