From 1013b819198139060ba62f35624c4d2c7cbfe40f Mon Sep 17 00:00:00 2001
From: David Maus <maus@hab.de>
Date: Mon, 6 Aug 2012 13:14:51 +0200
Subject: [PATCH]  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.
---
 src/php/HAB/Pica/Record/NestedRecord.php | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/src/php/HAB/Pica/Record/NestedRecord.php b/src/php/HAB/Pica/Record/NestedRecord.php
index 57e0ab4..5a8f1a5 100644
--- a/src/php/HAB/Pica/Record/NestedRecord.php
+++ b/src/php/HAB/Pica/Record/NestedRecord.php
@@ -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.
    *
-- 
GitLab