Add a filter() helper method

Add a namespaced `filter()` method that can be imported via `use
function` and use it as an alternative for `new Filter` or
`Filter::create()`.

This provides a cleaner, easier to read syntax - particularly if you
have a lot of filters in the same file.
This commit is contained in:
Oliver Davies 2020-07-09 20:15:30 +01:00
parent 31cfaf8f6f
commit 330d6f9393
3 changed files with 30 additions and 0 deletions

View file

@ -23,6 +23,7 @@
"symfony/var-dumper": "^3.4"
},
"autoload": {
"files": ["src/Helpers.php"],
"psr-4": {
"Opdavies\\GmailFilterBuilder\\": "src/"
}

12
src/Helpers.php Normal file
View file

@ -0,0 +1,12 @@
<?php
declare(strict_types=1);
namespace Opdavies\GmailFilterBuilder;
use Opdavies\GmailFilterBuilder\Model\Filter;
function filter(): Filter
{
return new Filter();
}

View file

@ -0,0 +1,17 @@
<?php
declare(strict_types=1);
use PHPUnit\Framework\TestCase;
use Opdavies\GmailFilterBuilder\Model\Filter as FilterClass;
use function Opdavies\GmailFilterBuilder\filter;
final class HelpersTest extends TestCase
{
/** @test */
public function it_returns_a_filter_object(): void
{
$this->assertEquals(new FilterClass(), filter());
}
}