Removing static dependencies

This commit is contained in:
bkrukowski 2016-10-26 20:13:11 +02:00
parent 5dd7f4d0fb
commit 9fe99a091c
4 changed files with 13 additions and 12 deletions

View File

@ -27,7 +27,8 @@ use bkrukowski\TransparentEmail\Emails\EmailInterface;
use bkrukowski\TransparentEmail\Emails\InvalidEmailException; use bkrukowski\TransparentEmail\Emails\InvalidEmailException;
try { try {
$cleaner = TransparentEmailFactory::createDefault(); $factory = new TransparentEmailFactory();
$cleaner = $factory->createDefault();
$inputEmail = new Email('John.Doe+alias@gmail.com'); $inputEmail = new Email('John.Doe+alias@gmail.com');
/** @var EmailInterface $transformedEmail */ /** @var EmailInterface $transformedEmail */
$transformedEmail = $cleaner->getPrimaryEmail($inputEmail); $transformedEmail = $cleaner->getPrimaryEmail($inputEmail);

View File

@ -13,23 +13,23 @@ use bkrukowski\TransparentEmail\Services\YahooCom;
class TransparentEmailFactory class TransparentEmailFactory
{ {
public static function createDefault() : TransparentEmailInterface public function createDefault() : TransparentEmailInterface
{ {
return new TransparentEmail(self::createServiceCollector()); return new TransparentEmail($this->createServiceCollector());
} }
private static function createServiceCollector() : ServiceCollectorInterface private function createServiceCollector() : ServiceCollectorInterface
{ {
$collector = new ServiceCollector(); $collector = new ServiceCollector();
foreach (self::getAllServicesClasses() as $servicesClass) { foreach ($this->getAllServicesClasses() as $servicesClass) {
$collector->addService(new $servicesClass()); $collector->addService(new $servicesClass());
} }
return $collector; return $collector;
} }
private static function getAllServicesClasses() : array private function getAllServicesClasses() : array
{ {
return [ return [
GmailCom::class, GmailCom::class,

View File

@ -18,7 +18,7 @@ class TransparentEmailFactoryTest extends \PHPUnit_Framework_TestCase
*/ */
public function testExpectedEmail(EmailInterface $inputEmail, string $expectedEmail) public function testExpectedEmail(EmailInterface $inputEmail, string $expectedEmail)
{ {
$outputEmail = TransparentEmailFactory::createDefault()->getPrimaryEmail($inputEmail); $outputEmail = (new TransparentEmailFactory())->createDefault()->getPrimaryEmail($inputEmail);
$this->assertSame($expectedEmail, (string) $outputEmail); $this->assertSame($expectedEmail, (string) $outputEmail);
} }

View File

@ -42,12 +42,12 @@ class TransparentEmailTest extends \PHPUnit_Framework_TestCase
'john.doe+alias@gmail.com', 'john.doe+alias@gmail.com',
'john.doe+alias@gmail.com' 'john.doe+alias@gmail.com'
], ],
[TransparentEmailFactory::createDefault(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'], [(new TransparentEmailFactory())->createDefault(), 'john.doe+alias@gmail.com', 'johndoe@gmail.com'],
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'john.doe@example.com'], [new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'john.doe@example.com'],
[new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'John.Doe@example.com', true], [new TransparentEmail($emptyServiceCollector), 'John.Doe@example.com', 'John.Doe@example.com', true],
[TransparentEmailFactory::createDefault(), 'John.Doe@gmail.com', 'johndoe@gmail.com', true], [(new TransparentEmailFactory())->createDefault(), 'John.Doe@gmail.com', 'johndoe@gmail.com', true],
[TransparentEmailFactory::createDefault(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'], [(new TransparentEmailFactory())->createDefault(), 'Jane.Doe+receipts@hotmail.com', 'jane.doe@hotmail.com'],
[TransparentEmailFactory::createDefault(), 'Jane.Doe-receipts@yahoo.com', 'jane.doe@yahoo.com'], [(new TransparentEmailFactory())->createDefault(), 'Jane.Doe-receipts@yahoo.com', 'jane.doe@yahoo.com'],
]; ];
} }
@ -59,7 +59,7 @@ class TransparentEmailTest extends \PHPUnit_Framework_TestCase
*/ */
public function testDefault(EmailInterface $inputEmail, string $expectedEmail) public function testDefault(EmailInterface $inputEmail, string $expectedEmail)
{ {
$this->assertEquals($expectedEmail, (TransparentEmailFactory::createDefault())->getPrimaryEmail($inputEmail)); $this->assertEquals($expectedEmail, ((new TransparentEmailFactory())->createDefault())->getPrimaryEmail($inputEmail));
} }
public function providerDefault() : array public function providerDefault() : array