SearchRetrieveResponse   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 60
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 4
dl 0
loc 60
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 19 5
A next() 0 13 4
1
<?php namespace Scriptotek\Sru;
2
3
/**
4
 * SearchRetrieve response, containing a list of records or some error
5
 */
6
class SearchRetrieveResponse extends Response implements ResponseInterface
7
{
8
    /** @var Record[] Array of records */
9
    public $records = array();
10
11
    /** @var int Total number of records in the result set */
12
    public $numberOfRecords = 0;
13
14
    /** @var int Position of next record in the result set, or null if no such record exist */
15
    public $nextRecordPosition = null;
16
17
    /** @var string The CQL query used to generate the response */
18
    public $query = '';
19
20
    /**
21
     * Create a new searchRetrieve response
22
     *
23
     * @param string $text Raw XML response
24
     * @param Client $client SRU client reference (optional)
25
     * @param string $url Request URL
26
     */
27
    public function __construct($text = null, &$client = null, $url = null)
28
    {
29
        parent::__construct($text, $client, $url);
30
31
        if (is_null($this->response)) {
32
            return;
33
        }
34
35
        $this->numberOfRecords = (int) $this->response->text('/srw:searchRetrieveResponse/srw:numberOfRecords');
36
        $this->nextRecordPosition = (int) $this->response->text('/srw:searchRetrieveResponse/srw:nextRecordPosition') ?: null;
37
38
        // The server may echo the request back to the client along with the response
39
        $this->query = $this->response->text('/srw:searchRetrieveResponse/srw:echoedSearchRetrieveRequest/srw:query') ?: null;
40
41
        $this->records = array();
42
        foreach ($this->response->xpath('/srw:searchRetrieveResponse/srw:records/srw:record') as $record) {
43
            $this->records[] = new Record($record);
44
        }
45
    }
46
47
    /**
48
     * Request next batch of records in the result set, or return null if we're at the end of the set
49
     *
50
     * @return Response
51
     */
52
    public function next()
53
    {
54
        if (is_null($this->client)) {
55
            throw new \Exception('No client reference passed to response');
56
        }
57
        if (is_null($this->query)) {
58
            throw new \Exception('No query available');
59
        }
60
        if (is_null($this->nextRecordPosition)) {
61
            return null;
62
        }
63
        return $this->client->search($this->query, $this->nextRecordPosition, count($this->records));
0 ignored issues
show
Deprecated Code introduced by
The method Scriptotek\Sru\Client::search() has been deprecated.

This method has been deprecated.

Loading history...
64
    }
65
}
66