Skip to content

Commit 6a3f31f

Browse files
Rely on ArrayAdapter (#115)
1 parent 29be56c commit 6a3f31f

File tree

4 files changed

+16
-47
lines changed

4 files changed

+16
-47
lines changed

src/EmailChecker/Adapter/ArrayAdapter.php

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,17 +16,23 @@
1616
*
1717
* @author Matthieu Moquet <[email protected]>
1818
*/
19-
final class ArrayAdapter implements AdapterInterface
19+
class ArrayAdapter implements AdapterInterface
2020
{
21+
/**
22+
* @var array<string, int>
23+
*/
24+
private array $domainSet;
25+
2126
/**
2227
* @param string[] $domains List of throwaway domains
2328
*/
24-
public function __construct(private array $domains)
29+
public function __construct(array $domains)
2530
{
31+
$this->domainSet = array_flip($domains);
2632
}
2733

2834
public function isThrowawayDomain(string $domain): bool
2935
{
30-
return in_array($domain, $this->domains, true);
36+
return isset($this->domainSet[$domain]);
3137
}
3238
}

src/EmailChecker/Adapter/BuiltInAdapter.php

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -23,27 +23,10 @@
2323
*
2424
* @author Matthieu Moquet <[email protected]>
2525
*/
26-
final class BuiltInAdapter implements AdapterInterface
26+
final class BuiltInAdapter extends ArrayAdapter
2727
{
28-
/**
29-
* @var string[]|null
30-
*/
31-
protected array|null $domains = null;
32-
33-
public function isThrowawayDomain(string $domain): bool
28+
public function __construct()
3429
{
35-
return in_array($domain, $this->getDomains(), true);
36-
}
37-
38-
/**
39-
* @return string[]
40-
*/
41-
private function getDomains(): array
42-
{
43-
if (null === $this->domains) {
44-
$this->domains = (new ThrowawayDomains())->toArray();
45-
}
46-
47-
return $this->domains;
30+
parent::__construct((new ThrowawayDomains())->toArray());
4831
}
4932
}

src/EmailChecker/Adapter/FileAdapter.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,8 @@
1818
*
1919
* @author Matthieu Moquet <[email protected]>
2020
*/
21-
final class FileAdapter implements AdapterInterface
21+
final class FileAdapter extends ArrayAdapter
2222
{
23-
/**
24-
* @var string[]
25-
*/
26-
protected array $domains;
27-
2823
/**
2924
* @param string $filename Filename containing all domains
3025
*/
@@ -35,11 +30,6 @@ public function __construct(string $filename)
3530
throw new \InvalidArgumentException(sprintf('File "%s" not found', $filename));
3631
}
3732

38-
$this->domains = Utilities::parseLines($content);
39-
}
40-
41-
public function isThrowawayDomain(string $domain): bool
42-
{
43-
return in_array($domain, $this->domains, true);
33+
parent::__construct(Utilities::parseLines($content));
4434
}
4535
}

src/EmailChecker/Adapter/GaufretteAdapter.php

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,10 @@
1919
*
2020
* @author Matthieu Moquet <[email protected]>
2121
*/
22-
final class GaufretteAdapter implements AdapterInterface
22+
final class GaufretteAdapter extends ArrayAdapter
2323
{
24-
/**
25-
* @var string[]
26-
*/
27-
private array $domains;
28-
2924
public function __construct(File $file)
3025
{
31-
$this->domains = Utilities::parseLines($file->getContent());
32-
}
33-
34-
public function isThrowawayDomain(string $domain): bool
35-
{
36-
return in_array($domain, $this->domains, true);
26+
parent::__construct(Utilities::parseLines($file->getContent()));
3727
}
3828
}

0 commit comments

Comments
 (0)