Commit 1013b819 authored by David Maus's avatar David Maus
Browse files

New function: Return true if nested records contains a record

* php/HAB/Pica/Record/NestedRecord.php (containsRecord): New
function. Return true if nested records contains a record.
(addRecord): Use new function.
parent 6cf941a0
......@@ -142,7 +142,7 @@ abstract class NestedRecord extends Record {
* @return void
*/
protected function addRecord (\HAB\Pica\Record\Record $record) {
if (in_array($record, $this->_records, true)) {
if ($this->containsRecord($record)) {
throw new \InvalidArgumentException("{$this} already contains {$record}");
}
$this->_records []= $record;
......@@ -163,6 +163,16 @@ abstract class NestedRecord extends Record {
unset($this->_records[$index]);
}
/**
* Return true if this record contains the requested record.
*
* @param \HAB\Pica\Record\Record Record to check
* @return boolean
*/
protected function containsRecord (\HAB\Pica\Record\Record $record) {
return in_array($record, $this->_records, true);
}
/**
* Finalize the clone() operation.
*
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment