Skip to content

Commit 9f9aae0

Browse files
Finalise, type and restrict visibility
1 parent d202e52 commit 9f9aae0

20 files changed

+46
-111
lines changed

src/EmailChecker/Adapter/AdapterInterface.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,5 +25,5 @@ interface AdapterInterface
2525
*
2626
* @return bool True for a throwaway domain
2727
*/
28-
public function isThrowawayDomain($domain);
28+
public function isThrowawayDomain(string $domain): bool;
2929
}

src/EmailChecker/Adapter/AggregatorAdapter.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,18 @@
1616
*
1717
* @author Matthieu Moquet <matthieu@moquet.net>
1818
*/
19-
class AggregatorAdapter implements AdapterInterface
19+
final class AggregatorAdapter implements AdapterInterface
2020
{
21-
/**
22-
* @var AdapterInterface[]
23-
*/
24-
protected $adapters;
25-
2621
/**
2722
* Build aggregator adapter with a list of adapters (order matters).
2823
*
2924
* @param AdapterInterface[] $adapters List of AdapterInterface objects
3025
*/
31-
public function __construct(array $adapters)
26+
public function __construct(private array $adapters)
3227
{
33-
$this->adapters = $adapters;
3428
}
3529

36-
public function isThrowawayDomain($domain)
30+
public function isThrowawayDomain(string $domain): bool
3731
{
3832
foreach ($this->adapters as $adapter) {
3933
if ($adapter->isThrowawayDomain($domain)) {

src/EmailChecker/Adapter/AgregatorAdapter.php

Lines changed: 0 additions & 33 deletions
This file was deleted.

src/EmailChecker/Adapter/ArrayAdapter.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,22 +16,16 @@
1616
*
1717
* @author Matthieu Moquet <matthieu@moquet.net>
1818
*/
19-
class ArrayAdapter implements AdapterInterface
19+
final class ArrayAdapter implements AdapterInterface
2020
{
21-
/**
22-
* @var string[]
23-
*/
24-
protected $domains;
25-
2621
/**
2722
* @param string[] $domains List of throwaway domains
2823
*/
29-
public function __construct(array $domains)
24+
public function __construct(private array $domains)
3025
{
31-
$this->domains = $domains;
3226
}
3327

34-
public function isThrowawayDomain($domain)
28+
public function isThrowawayDomain(string $domain): bool
3529
{
3630
return in_array($domain, $this->domains, true);
3731
}

src/EmailChecker/Adapter/BuiltInAdapter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,22 +23,22 @@
2323
*
2424
* @author Matthieu Moquet <matthieu@moquet.net>
2525
*/
26-
class BuiltInAdapter implements AdapterInterface
26+
final class BuiltInAdapter implements AdapterInterface
2727
{
2828
/**
2929
* @var string[]|null
3030
*/
31-
protected $domains = null;
31+
protected array|null $domains = null;
3232

33-
public function isThrowawayDomain($domain)
33+
public function isThrowawayDomain(string $domain): bool
3434
{
3535
return in_array($domain, $this->getDomains(), true);
3636
}
3737

3838
/**
3939
* @return string[]
4040
*/
41-
private function getDomains()
41+
private function getDomains(): array
4242
{
4343
if (null === $this->domains) {
4444
$this->domains = (new ThrowawayDomains())->toArray();

src/EmailChecker/Adapter/FileAdapter.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,17 @@
1818
*
1919
* @author Matthieu Moquet <matthieu@moquet.net>
2020
*/
21-
class FileAdapter implements AdapterInterface
21+
final class FileAdapter implements AdapterInterface
2222
{
2323
/**
2424
* @var string[]
2525
*/
26-
protected $domains;
26+
protected array $domains;
2727

2828
/**
2929
* @param string $filename Filename containing all domains
3030
*/
31-
public function __construct($filename)
31+
public function __construct(string $filename)
3232
{
3333
$content = file_get_contents($filename);
3434
if (false === $content) {
@@ -38,7 +38,7 @@ public function __construct($filename)
3838
$this->domains = Utilities::parseLines($content);
3939
}
4040

41-
public function isThrowawayDomain($domain)
41+
public function isThrowawayDomain(string $domain): bool
4242
{
4343
return in_array($domain, $this->domains, true);
4444
}

src/EmailChecker/Adapter/GaufretteAdapter.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,19 @@
1919
*
2020
* @author Matthieu Moquet <matthieu@moquet.net>
2121
*/
22-
class GaufretteAdapter implements AdapterInterface
22+
final class GaufretteAdapter implements AdapterInterface
2323
{
2424
/**
2525
* @var string[]
2626
*/
27-
protected $domains;
27+
private array $domains;
2828

2929
public function __construct(File $file)
3030
{
3131
$this->domains = Utilities::parseLines($file->getContent());
3232
}
3333

34-
public function isThrowawayDomain($domain)
34+
public function isThrowawayDomain(string $domain): bool
3535
{
3636
return in_array($domain, $this->domains, true);
3737
}

src/EmailChecker/Constraints/NotThrowawayEmail.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,20 +19,19 @@
1919
* @Annotation
2020
*/
2121
#[\Attribute]
22-
class NotThrowawayEmail extends Constraint
22+
final class NotThrowawayEmail extends Constraint
2323
{
2424
/**
2525
* @var string
2626
*/
2727
public $message = 'The domain associated with this email is not valid.';
2828

2929
public function __construct(
30-
$options = null,
31-
?array $groups = null,
32-
$payload = null,
3330
?string $message = null,
31+
?array $groups = null,
32+
mixed $payload = null,
3433
) {
35-
parent::__construct($options, $groups, $payload);
34+
parent::__construct(null, $groups, $payload);
3635

3736
$this->message = $message ?? $this->message;
3837
}

src/EmailChecker/Constraints/NotThrowawayEmailValidator.php

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,23 @@
1212
namespace EmailChecker\Constraints;
1313

1414
use EmailChecker\EmailChecker;
15-
use ReturnTypeWillChange;
1615
use Symfony\Component\Validator\Constraint;
1716
use Symfony\Component\Validator\ConstraintValidator;
1817
use Symfony\Component\Validator\Exception\UnexpectedTypeException;
1918

2019
/**
2120
* @author Matthieu Moquet <matthieu@moquet.net>
2221
*/
23-
class NotThrowawayEmailValidator extends ConstraintValidator
22+
final class NotThrowawayEmailValidator extends ConstraintValidator
2423
{
25-
/**
26-
* @var EmailChecker
27-
*/
28-
protected $emailChecker;
24+
private EmailChecker $emailChecker;
2925

3026
public function __construct(?EmailChecker $emailChecker = null)
3127
{
3228
$this->emailChecker = $emailChecker ?? new EmailChecker();
3329
}
3430

35-
/**
36-
* @param mixed $value
37-
*
38-
* @return void
39-
*/
40-
#[ReturnTypeWillChange]
41-
public function validate($value, Constraint $constraint)
31+
public function validate(mixed $value, Constraint $constraint): void
4232
{
4333
if (!$constraint instanceof NotThrowawayEmail) {
4434
throw new UnexpectedTypeException($constraint, NotThrowawayEmail::class);

src/EmailChecker/EmailChecker.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,12 @@
2020
*
2121
* @author Matthieu Moquet <matthieu@moquet.net>
2222
*/
23-
class EmailChecker
23+
final class EmailChecker
2424
{
25-
/**
26-
* @var AdapterInterface
27-
*/
28-
protected $adapter;
25+
private AdapterInterface $adapter;
2926

3027
/**
31-
* @param AdapterInterface $adapter Checker adapter
28+
* @param AdapterInterface|null $adapter Checker adapter
3229
*/
3330
public function __construct(?AdapterInterface $adapter = null)
3431
{
@@ -42,7 +39,7 @@ public function __construct(?AdapterInterface $adapter = null)
4239
*
4340
* @return bool true for a throwaway email
4441
*/
45-
public function isValid($email)
42+
public function isValid(string $email): bool
4643
{
4744
if (false === $email = filter_var($email, FILTER_VALIDATE_EMAIL)) {
4845
return false;

0 commit comments

Comments
 (0)