mirror of
https://github.com/opdavies/gmail-filter-builder.git
synced 2025-02-02 00:47:32 +00:00
parent
72ed0d6f24
commit
a4c913ab38
|
@ -15,7 +15,7 @@ class Filter
|
|||
/**
|
||||
* @return static
|
||||
*/
|
||||
public static function create()
|
||||
public static function create(): self
|
||||
{
|
||||
return new static();
|
||||
}
|
||||
|
@ -25,7 +25,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function has($value)
|
||||
public function has(string $value): self
|
||||
{
|
||||
$this->properties['hasTheWord'] = $value;
|
||||
|
||||
|
@ -37,7 +37,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function hasNot($value)
|
||||
public function hasNot(string $value): self
|
||||
{
|
||||
$this->properties['doesNotHaveTheWord'] = $value;
|
||||
|
||||
|
@ -49,7 +49,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function from($values)
|
||||
public function from($values): self
|
||||
{
|
||||
if (!empty($values)) {
|
||||
$this->properties['from'] = collect($values)->map(function ($value) {
|
||||
|
@ -65,7 +65,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function to($values)
|
||||
public function to($values): self
|
||||
{
|
||||
if (!empty($values)) {
|
||||
$this->properties['to'] = collect($values)->map(function ($value) {
|
||||
|
@ -81,7 +81,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function subject($values)
|
||||
public function subject($values): self
|
||||
{
|
||||
$this->properties['subject'] = collect($values)->map(function ($value) {
|
||||
return json_encode($value);
|
||||
|
@ -93,7 +93,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function hasAttachment()
|
||||
public function hasAttachment(): self
|
||||
{
|
||||
$this->properties['hasAttachment'] = 'true';
|
||||
|
||||
|
@ -107,7 +107,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function fromList($value)
|
||||
public function fromList($value): self
|
||||
{
|
||||
$value = collect($value)->implode(self::SEPARATOR);
|
||||
$this->has("list:{$value}");
|
||||
|
@ -118,7 +118,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function excludeChats()
|
||||
public function excludeChats(): self
|
||||
{
|
||||
$this->properties['excludeChats'] = 'true';
|
||||
|
||||
|
@ -130,7 +130,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function label($label)
|
||||
public function label(string $label): self
|
||||
{
|
||||
$this->properties['label'] = $label;
|
||||
|
||||
|
@ -140,7 +140,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function archive()
|
||||
public function archive(): self
|
||||
{
|
||||
$this->properties['shouldArchive'] = 'true';
|
||||
|
||||
|
@ -152,7 +152,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function labelAndArchive($label)
|
||||
public function labelAndArchive(string $label): self
|
||||
{
|
||||
$this->label($label)->archive();
|
||||
|
||||
|
@ -162,7 +162,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function spam()
|
||||
public function spam(): self
|
||||
{
|
||||
$this->properties['shouldSpam'] = 'true';
|
||||
$this->properties['shouldNeverSpam'] = 'false';
|
||||
|
@ -173,7 +173,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function neverSpam()
|
||||
public function neverSpam(): self
|
||||
{
|
||||
$this->properties['shouldSpam'] = 'false';
|
||||
$this->properties['shouldNeverSpam'] = 'true';
|
||||
|
@ -184,7 +184,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function trash()
|
||||
public function trash(): self
|
||||
{
|
||||
$this->properties['shouldTrash'] = 'true';
|
||||
|
||||
|
@ -194,7 +194,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function read()
|
||||
public function read(): self
|
||||
{
|
||||
$this->properties['markAsRead'] = 'true';
|
||||
|
||||
|
@ -204,7 +204,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function star()
|
||||
public function star(): self
|
||||
{
|
||||
$this->properties['shouldStar'] = 'true';
|
||||
|
||||
|
@ -216,7 +216,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function forward($to)
|
||||
public function forward(string $to): self
|
||||
{
|
||||
$this->properties['forwardTo'] = $to;
|
||||
|
||||
|
@ -226,7 +226,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function important()
|
||||
public function important(): self
|
||||
{
|
||||
$this->properties['shouldAlwaysMarkAsImportant'] = 'true';
|
||||
|
||||
|
@ -236,7 +236,7 @@ class Filter
|
|||
/**
|
||||
* @return $this
|
||||
*/
|
||||
public function notImportant()
|
||||
public function notImportant(): self
|
||||
{
|
||||
$this->properties['shouldNeverMarkAsImportant'] = 'true';
|
||||
|
||||
|
@ -248,7 +248,7 @@ class Filter
|
|||
*
|
||||
* @return $this
|
||||
*/
|
||||
public function categorise($category)
|
||||
public function categorise(string $category): self
|
||||
{
|
||||
$this->properties['smartLabelToApply'] = $category;
|
||||
|
||||
|
@ -261,7 +261,7 @@ class Filter
|
|||
* @return array
|
||||
* @deprecated toArray()
|
||||
*/
|
||||
public function getProperties()
|
||||
public function getProperties(): array
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
@ -271,7 +271,7 @@ class Filter
|
|||
*
|
||||
* @return array
|
||||
*/
|
||||
public function toArray()
|
||||
public function toArray(): array
|
||||
{
|
||||
return $this->properties;
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ class Builder
|
|||
$this->build();
|
||||
}
|
||||
|
||||
public function __toString()
|
||||
public function __toString(): string
|
||||
{
|
||||
return $this->build();
|
||||
}
|
||||
|
@ -49,7 +49,7 @@ class Builder
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
public function getXml()
|
||||
public function getXml(): string
|
||||
{
|
||||
return $this->xml;
|
||||
}
|
||||
|
@ -59,7 +59,7 @@ class Builder
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
private function build()
|
||||
private function build(): void
|
||||
{
|
||||
$prefix = "<?xml version='1.0' encoding='UTF-8'?>" . PHP_EOL . "<feed xmlns='http://www.w3.org/2005/Atom' xmlns:apps='http://schemas.google.com/apps/2006'>";
|
||||
$suffix = '</feed>';
|
||||
|
@ -82,11 +82,13 @@ class Builder
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildEntry(Filter $filter)
|
||||
private function buildEntry(Filter $filter): string
|
||||
{
|
||||
$entry = collect($filter->getProperties())->map(function ($value, $key) {
|
||||
return $this->buildProperty($value, $key);
|
||||
})->implode(PHP_EOL);
|
||||
$entry = collect($filter->toArray())
|
||||
->map(function ($value, $key): string {
|
||||
return $this->buildProperty($value, $key);
|
||||
})
|
||||
->implode(PHP_EOL);
|
||||
|
||||
return collect(['<entry>', $entry, '</entry>'])->implode(PHP_EOL);
|
||||
}
|
||||
|
@ -99,7 +101,7 @@ class Builder
|
|||
*
|
||||
* @return string
|
||||
*/
|
||||
private function buildProperty($value, $key)
|
||||
private function buildProperty($value, $key): string
|
||||
{
|
||||
if (collect(['from', 'to'])->contains($key)) {
|
||||
$value = $this->implode($value);
|
||||
|
@ -114,7 +116,7 @@ class Builder
|
|||
/**
|
||||
* Implode values with the appropriate prefix, suffix and separator.
|
||||
*/
|
||||
private function implode($value, $separator = '|')
|
||||
private function implode($value, $separator = '|'): string
|
||||
{
|
||||
if (is_string($value)) {
|
||||
return $value;
|
||||
|
|
|
@ -14,7 +14,7 @@ class Partials
|
|||
*
|
||||
* @return array The loaded filters.
|
||||
*/
|
||||
public static function load($directoryName = 'filters')
|
||||
public static function load($directoryName = 'filters'): array
|
||||
{
|
||||
$files = static::getFilePattern($directoryName);
|
||||
|
||||
|
@ -23,7 +23,7 @@ class Partials
|
|||
return include $filename;
|
||||
})
|
||||
->flatten(1)
|
||||
->all();
|
||||
->toArray();
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -36,7 +36,7 @@ class Partials
|
|||
*
|
||||
* @return string The full path.
|
||||
*/
|
||||
protected static function getFilePattern($directoryName)
|
||||
protected static function getFilePattern($directoryName): string
|
||||
{
|
||||
return getcwd() . DIRECTORY_SEPARATOR . $directoryName . DIRECTORY_SEPARATOR . '*.php';
|
||||
}
|
||||
|
|
|
@ -18,9 +18,9 @@ class PartialsTest extends TestCase
|
|||
|
||||
$this->assertCount(3, $filters);
|
||||
|
||||
$this->assertSame('foo@example.com', $filters[0]->getProperties()['from'][0]);
|
||||
$this->assertSame('bar@example.com', $filters[1]->getProperties()['from'][0]);
|
||||
$this->assertSame('baz@example.com', $filters[2]->getProperties()['from'][0]);
|
||||
$this->assertSame('foo@example.com', $filters[0]->toArray()['from'][0]);
|
||||
$this->assertSame('bar@example.com', $filters[1]->toArray()['from'][0]);
|
||||
$this->assertSame('baz@example.com', $filters[2]->toArray()['from'][0]);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -29,7 +29,7 @@ class FakePartials extends Partials
|
|||
/**
|
||||
* {@inheritdoc}
|
||||
*/
|
||||
protected static function getFilePattern($directoryName)
|
||||
protected static function getFilePattern($directoryName): string
|
||||
{
|
||||
return __DIR__ . '/../../stubs/filters/*.php';
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue