mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-01-22 12:07:32 +00:00
wip
This commit is contained in:
parent
caa3767246
commit
ba5a972715
|
@ -1,15 +1,17 @@
|
|||
<?php
|
||||
|
||||
use Opdavies\GmailFilterBuilder\Filter;
|
||||
use Opdavies\GmailFilterBuilder\Model\Filter;
|
||||
|
||||
require_once __DIR__ . '/vendor/autoload.php';
|
||||
require_once __DIR__ . '/../vendor/autoload.php';
|
||||
|
||||
return [
|
||||
Filter::create()
|
||||
->from('foo@example.com')
|
||||
->labelAndArchive('Example'),
|
||||
->from('papercall.io')
|
||||
->subject('New Submission For Drupal Camp Bristol 2019')
|
||||
->labelAndArchive('DrupalCamp Bristol'),
|
||||
|
||||
Filter::create()
|
||||
->from('bar@example.com')
|
||||
->important(),
|
||||
($filter = Filter::create())
|
||||
->from('papercall.io')
|
||||
->negate($filter->subject('New Submission For Drupal Camp Bristol 2019'))
|
||||
->labelAndArchive('Deletable/Other notifications'),
|
||||
];
|
||||
|
|
|
@ -275,4 +275,22 @@ class Filter
|
|||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
||||
public function negate(Filter $filter): self
|
||||
{
|
||||
$filter->properties = collect($filter->toArray())
|
||||
->mapWithKeys(function ($conditions, $key) {
|
||||
return [$key => collect($conditions)->map(function ($condition) {
|
||||
return $this->negateCondition($condition);
|
||||
})];
|
||||
})
|
||||
->toArray();
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
private function negateCondition(string $condition): string
|
||||
{
|
||||
return "-($condition)";
|
||||
}
|
||||
}
|
||||
|
|
|
@ -337,4 +337,20 @@ class FilterTest extends TestCase
|
|||
->toArray()
|
||||
);
|
||||
}
|
||||
|
||||
/** @test */
|
||||
public function conditions_can_be_negated()
|
||||
{
|
||||
$this->filter
|
||||
->from('example.com')
|
||||
->negate($this->filter->subject('test'));
|
||||
|
||||
$this->assertEquals(
|
||||
[
|
||||
'from' => 'example.com',
|
||||
'subject' => '-(test)',
|
||||
],
|
||||
$this->filter->toArray()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue