From b39b0151bbef84d7e4adbe772359bdfcbc60b6d6 Mon Sep 17 00:00:00 2001 From: oscarotero Date: Wed, 2 Dec 2015 19:18:07 +0100 Subject: [PATCH] added strict mode on rowcollection->filter() --- src/RowCollection.php | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/src/RowCollection.php b/src/RowCollection.php index 6be2e8f..0619df3 100644 --- a/src/RowCollection.php +++ b/src/RowCollection.php @@ -321,27 +321,23 @@ public function add($rows) /** * Filter the rows by a value. * - * @param string $name The value name - * @param mixed $value The value to filter - * @param bool $first Set true to return only the first row found + * @param string $name The value name + * @param mixed $value The value to filter + * @param bool $strict Strict mode * - * @return null|RowInterface The rows found or null if no value is found and $first parameter is true + * @return RowInterface The rows found */ - public function filter($name, $value, $first = false) + public function filter($name, $value, $strict = true) { $rows = []; foreach ($this->rows as $row) { - if (($row->$name === $value) || (is_array($value) && in_array($row->$name, $value, true))) { - if ($first === true) { - return $row; - } - + if (($row->$name === $value) || (!$strict && $row->$name == $value) || (is_array($value) && in_array($row->$name, $value, $strict))) { $rows[] = $row; } } - return $first ? null : $this->entity->createCollection($rows); + return $this->entity->createCollection($rows); } /**