1 | <?php |
||
29 | class RecordIterator implements \Iterator, RecordIteratorInterface |
||
30 | { |
||
31 | /** |
||
32 | * @var Client |
||
33 | */ |
||
34 | private $oaipmhClient; |
||
35 | |||
36 | /** |
||
37 | * @var string The verb to use |
||
38 | */ |
||
39 | private $verb; |
||
40 | |||
41 | /** |
||
42 | * @var array OAI-PMH parameters passed as part of the request |
||
43 | */ |
||
44 | private $params; |
||
45 | |||
46 | /** |
||
47 | * @var int The number of total entities (if available) |
||
48 | */ |
||
49 | private $totalRecordsInCollection; |
||
50 | |||
51 | /** |
||
52 | * @var \DateTimeInterface RecordSet expiration date (if specified) |
||
53 | */ |
||
54 | private $expireDate; |
||
55 | |||
56 | /** |
||
57 | * @var string The resumption token |
||
58 | */ |
||
59 | private $resumptionToken; |
||
60 | |||
61 | /** |
||
62 | * @var array Array of records |
||
63 | */ |
||
64 | private $batch; |
||
65 | |||
66 | /** |
||
67 | * @var int Total number of records processed |
||
68 | */ |
||
69 | private $numProcessed = 0; |
||
70 | |||
71 | /** |
||
72 | * @var boolean Total number of requests made |
||
73 | */ |
||
74 | private $numRequests = 0; |
||
75 | |||
76 | /** |
||
77 | * @var \SimpleXMLElement|null Used for tracking the iterator |
||
78 | */ |
||
79 | private $currItem; |
||
80 | |||
81 | /** |
||
82 | * Constructor |
||
83 | * |
||
84 | * @param ClientInterface $client The client to use |
||
85 | * @param string $verb The verb to use when retrieving results from the client |
||
86 | * @param array $params Optional parameters passed to OAI-PMH |
||
87 | * @param string|null $resumptionToken Resumption token, if one exists |
||
88 | */ |
||
89 | public function __construct(ClientInterface $client, $verb, array $params = array(), $resumptionToken = null) |
||
102 | |||
103 | /** |
||
104 | * @return ClientInterface |
||
105 | */ |
||
106 | public function getClient() |
||
110 | |||
111 | /** |
||
112 | * Get the total number of requests made during this run |
||
113 | * |
||
114 | * @return int The number of HTTP requests made |
||
115 | */ |
||
116 | public function getNumRequests() |
||
120 | |||
121 | /** |
||
122 | * Get the total number of records processed during this run |
||
123 | * |
||
124 | * @return int The number of records processed |
||
125 | */ |
||
126 | public function getNumRetrieved() |
||
130 | |||
131 | |||
132 | /** |
||
133 | * Get the resumption token if it is specified |
||
134 | * |
||
135 | * @return null|string |
||
136 | */ |
||
137 | public function getResumptionToken() |
||
141 | |||
142 | /** |
||
143 | * @return \DateTimeInterface|null |
||
144 | */ |
||
145 | public function getExpirationDate() |
||
149 | |||
150 | /** |
||
151 | * Get the total number of records in the collection if available |
||
152 | * |
||
153 | * This only returns a value if the OAI-PMH server provides this information |
||
154 | * in the response, which not all servers do (it is optional in the OAI-PMH spec) |
||
155 | * |
||
156 | * Also, the number of records may change during the requests, so it should |
||
157 | * be treated as an estimate |
||
158 | * |
||
159 | * @return int|null |
||
160 | * @deprecated Use `countTotalRecords()` |
||
161 | */ |
||
162 | public function getTotalRecordsInCollection() |
||
166 | |||
167 | /** |
||
168 | * Get the total number of records in the collection if available |
||
169 | * |
||
170 | * This only returns a value if the OAI-PMH server provides this information |
||
171 | * in the response, which not all servers do (it is optional in the OAI-PMH spec) |
||
172 | * |
||
173 | * Also, the number of records may change during the requests, so it should |
||
174 | * be treated as an estimate |
||
175 | * |
||
176 | * @return int|null |
||
177 | */ |
||
178 | public function getTotalRecordCount() |
||
186 | |||
187 | /** |
||
188 | * Get the next item |
||
189 | * |
||
190 | * Return an item from the currently-retrieved batch, get next batch and |
||
191 | * return first record from it, or return false if no more records |
||
192 | * |
||
193 | * @return \SimpleXMLElement|bool |
||
194 | */ |
||
195 | public function nextItem() |
||
218 | |||
219 | /** |
||
220 | * Do a request to get the next batch of items |
||
221 | * |
||
222 | * @return int The number of items in the batch after the retrieve |
||
223 | */ |
||
224 | private function retrieveBatch() |
||
269 | |||
270 | /** |
||
271 | * Get Item Node Name |
||
272 | * |
||
273 | * Map the item node name based on the verb |
||
274 | * |
||
275 | * @return string|boolean The element name for the mapping, or false if unmapped |
||
276 | */ |
||
277 | private function getItemNodeName() |
||
288 | |||
289 | // ---------------------------------------------------------------- |
||
290 | // Leaky abstraction methods |
||
291 | |||
292 | /** |
||
293 | * Get the current batch of records retrieved |
||
294 | * |
||
295 | * @return array|\SimpleXMLElement[] |
||
296 | */ |
||
297 | public function getBatch() |
||
301 | |||
302 | /** |
||
303 | * Reset the request state |
||
304 | */ |
||
305 | public function reset() |
||
317 | |||
318 | // ---------------------------------------------------------------- |
||
319 | // Iterator methods |
||
320 | |||
321 | public function current() |
||
327 | |||
328 | public function next() |
||
332 | |||
333 | public function key() |
||
341 | |||
342 | public function valid() |
||
346 | |||
347 | public function rewind() |
||
351 | } |
||
352 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.
Either this assignment is in error or an instanceof check should be added for that assignment.