From 1578cc81a371eed02cdbe55a4be6c1cfcb596fb5 Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Mon, 1 Apr 2019 23:23:52 +0100 Subject: [PATCH] Split and store the conditions for a filter --- src/Model/Filter.php | 19 +++++++++++++++++++ tests/Unit/Model/FilterTest.php | 10 ++++++++++ 2 files changed, 29 insertions(+) diff --git a/src/Model/Filter.php b/src/Model/Filter.php index 86a2640..2d13862 100644 --- a/src/Model/Filter.php +++ b/src/Model/Filter.php @@ -2,6 +2,8 @@ namespace Opdavies\GmailFilterBuilder\Model; +use Tightenco\Collect\Support\Collection; + class Filter { /** @@ -9,6 +11,14 @@ class Filter */ private $properties = []; + /** @var Collection */ + private $conditions; + + public function __construct() + { + $this->conditions = new Collection(); + } + /** * @return static */ @@ -26,6 +36,10 @@ class Filter { $this->properties['hasTheWord'] = $value; + $this->conditions = $this->conditions->merge( + new Collection(preg_split('/\s+/', $value)) + ); + return $this; } @@ -271,4 +285,9 @@ class Filter { return $this->properties; } + + public function getConditions(): Collection + { + return $this->conditions; + } } diff --git a/tests/Unit/Model/FilterTest.php b/tests/Unit/Model/FilterTest.php index 8de48fc..44f8752 100644 --- a/tests/Unit/Model/FilterTest.php +++ b/tests/Unit/Model/FilterTest.php @@ -320,4 +320,14 @@ class FilterTest extends TestCase ->toArray() ); } + + /** @test */ + public function conditions_can_be_split_and_stored() + { + $filter = Filter::create() + ->has('to:me@example.com subject:Something') + ->archive(); + + $this->assertCount(2, $filter->getConditions()); + } }