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 \DateTime 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 | */ |
||
88 | public function __construct(ClientInterface $client, $verb, array $params = array(), $resumptionToken = null) |
||
101 | |||
102 | /** |
||
103 | * Get the total number of requests made during this run |
||
104 | * |
||
105 | * @return int The number of HTTP requests made |
||
106 | */ |
||
107 | public function getNumRequests() |
||
111 | |||
112 | /** |
||
113 | * Get the total number of records processed during this run |
||
114 | * |
||
115 | * @return int The number of records processed |
||
116 | */ |
||
117 | public function getNumRetrieved() |
||
121 | |||
122 | |||
123 | /** |
||
124 | * Get the resumption token if it is specified |
||
125 | * |
||
126 | * @return null|string |
||
127 | */ |
||
128 | public function getResumptionToken() |
||
132 | |||
133 | /** |
||
134 | * @return \DateTime|null |
||
135 | */ |
||
136 | public function getExpirationDate() |
||
140 | |||
141 | /** |
||
142 | * Get the total number of records in the collection if available |
||
143 | * |
||
144 | * This only returns a value if the OAI-PMH server provides this information |
||
145 | * in the response, which not all servers do (it is optional in the OAI-PMH spec) |
||
146 | * |
||
147 | * Also, the number of records may change during the requests, so it should |
||
148 | * be treated as an estimate |
||
149 | * |
||
150 | * @return int|null |
||
151 | * @deprecated Use `countTotalRecords()` |
||
152 | */ |
||
153 | public function getTotalRecordsInCollection() |
||
157 | |||
158 | /** |
||
159 | * Get the total number of records in the collection if available |
||
160 | * |
||
161 | * This only returns a value if the OAI-PMH server provides this information |
||
162 | * in the response, which not all servers do (it is optional in the OAI-PMH spec) |
||
163 | * |
||
164 | * Also, the number of records may change during the requests, so it should |
||
165 | * be treated as an estimate |
||
166 | * |
||
167 | * @return int|null |
||
168 | */ |
||
169 | public function getTotalRecordCount() |
||
177 | |||
178 | /** |
||
179 | * Get the next item |
||
180 | * |
||
181 | * Return an item from the currently-retrieved batch, get next batch and |
||
182 | * return first record from it, or return false if no more records |
||
183 | * |
||
184 | * @return \SimpleXMLElement|bool |
||
185 | */ |
||
186 | public function nextItem() |
||
205 | |||
206 | /** |
||
207 | * Do a request to get the next batch of items |
||
208 | * |
||
209 | * @return int The number of items in the batch after the retrieve |
||
210 | */ |
||
211 | private function retrieveBatch() |
||
256 | |||
257 | /** |
||
258 | * Get Item Node Name |
||
259 | * |
||
260 | * Map the item node name based on the verb |
||
261 | * |
||
262 | * @return string|boolean The element name for the mapping, or false if unmapped |
||
263 | */ |
||
264 | private function getItemNodeName() |
||
275 | |||
276 | // ---------------------------------------------------------------- |
||
277 | // Leaky abstraction methods |
||
278 | |||
279 | /** |
||
280 | * Get the current batch of records retrieved |
||
281 | * |
||
282 | * @return array|\SimpleXMLElement[] |
||
283 | */ |
||
284 | public function getBatch() |
||
288 | |||
289 | /** |
||
290 | * Reset the request state |
||
291 | */ |
||
292 | public function reset() |
||
304 | |||
305 | // ---------------------------------------------------------------- |
||
306 | // Iterator methods |
||
307 | |||
308 | public function current() |
||
314 | |||
315 | public function next() |
||
319 | |||
320 | public function key() |
||
328 | |||
329 | public function valid() |
||
333 | |||
334 | public function rewind() |
||
338 | } |
||
339 |
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.