diff --git a/composer.json b/composer.json index e7de7f8..6ef0632 100644 --- a/composer.json +++ b/composer.json @@ -17,7 +17,7 @@ "illuminate/support": "^9.0 || ^10.0 || ^11.0 || ^12.0", "knplabs/gaufrette": "^0.11", "phpunit/phpunit": "^9.5", - "symfony/validator": "^5.4 || ^6.4 || ^7.3", + "symfony/validator": "^5.4 || ^6.4 || ^7.3 || ^8.0", "phpstan/phpstan": "^2.1", "phpstan/phpstan-phpunit": "^2.0", "phpstan/phpstan-strict-rules": "^2.0" diff --git a/src/EmailChecker/Adapter/AdapterInterface.php b/src/EmailChecker/Adapter/AdapterInterface.php index 2440ca1..f739458 100644 --- a/src/EmailChecker/Adapter/AdapterInterface.php +++ b/src/EmailChecker/Adapter/AdapterInterface.php @@ -25,5 +25,5 @@ interface AdapterInterface * * @return bool True for a throwaway domain */ - public function isThrowawayDomain($domain); + public function isThrowawayDomain(string $domain): bool; } diff --git a/src/EmailChecker/Adapter/AggregatorAdapter.php b/src/EmailChecker/Adapter/AggregatorAdapter.php index f54372b..f7c86d8 100644 --- a/src/EmailChecker/Adapter/AggregatorAdapter.php +++ b/src/EmailChecker/Adapter/AggregatorAdapter.php @@ -16,24 +16,18 @@ * * @author Matthieu Moquet */ -class AggregatorAdapter implements AdapterInterface +final class AggregatorAdapter implements AdapterInterface { - /** - * @var AdapterInterface[] - */ - protected $adapters; - /** * Build aggregator adapter with a list of adapters (order matters). * * @param AdapterInterface[] $adapters List of AdapterInterface objects */ - public function __construct(array $adapters) + public function __construct(private array $adapters) { - $this->adapters = $adapters; } - public function isThrowawayDomain($domain) + public function isThrowawayDomain(string $domain): bool { foreach ($this->adapters as $adapter) { if ($adapter->isThrowawayDomain($domain)) { diff --git a/src/EmailChecker/Adapter/AgregatorAdapter.php b/src/EmailChecker/Adapter/AgregatorAdapter.php deleted file mode 100644 index aadd2c2..0000000 --- a/src/EmailChecker/Adapter/AgregatorAdapter.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * This source file is subject to the MIT license that is bundled - * with this source code in the file LICENSE. - */ - -namespace EmailChecker\Adapter; - -/** - * Combine data from other adapters. - * - * @author Matthieu Moquet - * - * @deprecated Use \EmailChecker\Adapter\AggregatorAdapter instead. - */ -class AgregatorAdapter extends AggregatorAdapter -{ - public function __construct(array $adapters) - { - parent::__construct($adapters); - - trigger_error(\sprintf( - 'Since mattketmo/email-checker 2.5.0: Class "%s" is deprecated, use "%s" instead.', - self::class, - AggregatorAdapter::class, - ), \E_USER_DEPRECATED); - } -} diff --git a/src/EmailChecker/Adapter/ArrayAdapter.php b/src/EmailChecker/Adapter/ArrayAdapter.php index 487d31c..adb341d 100644 --- a/src/EmailChecker/Adapter/ArrayAdapter.php +++ b/src/EmailChecker/Adapter/ArrayAdapter.php @@ -16,22 +16,16 @@ * * @author Matthieu Moquet */ -class ArrayAdapter implements AdapterInterface +final class ArrayAdapter implements AdapterInterface { - /** - * @var string[] - */ - protected $domains; - /** * @param string[] $domains List of throwaway domains */ - public function __construct(array $domains) + public function __construct(private array $domains) { - $this->domains = $domains; } - public function isThrowawayDomain($domain) + public function isThrowawayDomain(string $domain): bool { return in_array($domain, $this->domains, true); } diff --git a/src/EmailChecker/Adapter/BuiltInAdapter.php b/src/EmailChecker/Adapter/BuiltInAdapter.php index 66a0984..16c10f4 100644 --- a/src/EmailChecker/Adapter/BuiltInAdapter.php +++ b/src/EmailChecker/Adapter/BuiltInAdapter.php @@ -23,14 +23,14 @@ * * @author Matthieu Moquet */ -class BuiltInAdapter implements AdapterInterface +final class BuiltInAdapter implements AdapterInterface { /** * @var string[]|null */ - protected $domains = null; + protected array|null $domains = null; - public function isThrowawayDomain($domain) + public function isThrowawayDomain(string $domain): bool { return in_array($domain, $this->getDomains(), true); } @@ -38,7 +38,7 @@ public function isThrowawayDomain($domain) /** * @return string[] */ - private function getDomains() + private function getDomains(): array { if (null === $this->domains) { $this->domains = (new ThrowawayDomains())->toArray(); diff --git a/src/EmailChecker/Adapter/FileAdapter.php b/src/EmailChecker/Adapter/FileAdapter.php index 922ad9c..1313e6a 100644 --- a/src/EmailChecker/Adapter/FileAdapter.php +++ b/src/EmailChecker/Adapter/FileAdapter.php @@ -18,17 +18,17 @@ * * @author Matthieu Moquet */ -class FileAdapter implements AdapterInterface +final class FileAdapter implements AdapterInterface { /** * @var string[] */ - protected $domains; + protected array $domains; /** * @param string $filename Filename containing all domains */ - public function __construct($filename) + public function __construct(string $filename) { $content = file_get_contents($filename); if (false === $content) { @@ -38,7 +38,7 @@ public function __construct($filename) $this->domains = Utilities::parseLines($content); } - public function isThrowawayDomain($domain) + public function isThrowawayDomain(string $domain): bool { return in_array($domain, $this->domains, true); } diff --git a/src/EmailChecker/Adapter/GaufretteAdapter.php b/src/EmailChecker/Adapter/GaufretteAdapter.php index cc1b330..d2715f6 100644 --- a/src/EmailChecker/Adapter/GaufretteAdapter.php +++ b/src/EmailChecker/Adapter/GaufretteAdapter.php @@ -19,19 +19,19 @@ * * @author Matthieu Moquet */ -class GaufretteAdapter implements AdapterInterface +final class GaufretteAdapter implements AdapterInterface { /** * @var string[] */ - protected $domains; + private array $domains; public function __construct(File $file) { $this->domains = Utilities::parseLines($file->getContent()); } - public function isThrowawayDomain($domain) + public function isThrowawayDomain(string $domain): bool { return in_array($domain, $this->domains, true); } diff --git a/src/EmailChecker/Constraints/NotThrowawayEmail.php b/src/EmailChecker/Constraints/NotThrowawayEmail.php index 4a554e6..03640e5 100644 --- a/src/EmailChecker/Constraints/NotThrowawayEmail.php +++ b/src/EmailChecker/Constraints/NotThrowawayEmail.php @@ -19,7 +19,7 @@ * @Annotation */ #[\Attribute] -class NotThrowawayEmail extends Constraint +final class NotThrowawayEmail extends Constraint { /** * @var string @@ -27,12 +27,11 @@ class NotThrowawayEmail extends Constraint public $message = 'The domain associated with this email is not valid.'; public function __construct( - $options = null, - ?array $groups = null, - $payload = null, ?string $message = null, + ?array $groups = null, + mixed $payload = null, ) { - parent::__construct($options, $groups, $payload); + parent::__construct(null, $groups, $payload); $this->message = $message ?? $this->message; } diff --git a/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php b/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php index 2596b74..3587ddf 100644 --- a/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php +++ b/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php @@ -12,7 +12,6 @@ namespace EmailChecker\Constraints; use EmailChecker\EmailChecker; -use ReturnTypeWillChange; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; use Symfony\Component\Validator\Exception\UnexpectedTypeException; @@ -20,25 +19,16 @@ /** * @author Matthieu Moquet */ -class NotThrowawayEmailValidator extends ConstraintValidator +final class NotThrowawayEmailValidator extends ConstraintValidator { - /** - * @var EmailChecker - */ - protected $emailChecker; + private EmailChecker $emailChecker; public function __construct(?EmailChecker $emailChecker = null) { $this->emailChecker = $emailChecker ?? new EmailChecker(); } - /** - * @param mixed $value - * - * @return void - */ - #[ReturnTypeWillChange] - public function validate($value, Constraint $constraint) + public function validate(mixed $value, Constraint $constraint): void { if (!$constraint instanceof NotThrowawayEmail) { throw new UnexpectedTypeException($constraint, NotThrowawayEmail::class); diff --git a/src/EmailChecker/EmailChecker.php b/src/EmailChecker/EmailChecker.php index 14e2ba3..45bd85b 100644 --- a/src/EmailChecker/EmailChecker.php +++ b/src/EmailChecker/EmailChecker.php @@ -20,15 +20,12 @@ * * @author Matthieu Moquet */ -class EmailChecker +final class EmailChecker { - /** - * @var AdapterInterface - */ - protected $adapter; + private AdapterInterface $adapter; /** - * @param AdapterInterface $adapter Checker adapter + * @param AdapterInterface|null $adapter Checker adapter */ public function __construct(?AdapterInterface $adapter = null) { @@ -42,7 +39,7 @@ public function __construct(?AdapterInterface $adapter = null) * * @return bool true for a throwaway email */ - public function isValid($email) + public function isValid(string $email): bool { if (false === $email = filter_var($email, FILTER_VALIDATE_EMAIL)) { return false; diff --git a/src/EmailChecker/Laravel/EmailCheckerFacade.php b/src/EmailChecker/Laravel/EmailCheckerFacade.php index 06b5803..f6c6d04 100644 --- a/src/EmailChecker/Laravel/EmailCheckerFacade.php +++ b/src/EmailChecker/Laravel/EmailCheckerFacade.php @@ -18,7 +18,7 @@ * * @author Oliver Green */ -class EmailCheckerFacade extends Facade +final class EmailCheckerFacade extends Facade { /** * Get the registered name of the component. diff --git a/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php b/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php index c22bf73..24fa8f6 100644 --- a/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php +++ b/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php @@ -20,14 +20,12 @@ * * @author Oliver Green */ -class EmailCheckerServiceProvider extends ServiceProvider +final class EmailCheckerServiceProvider extends ServiceProvider { /** * Register the factory in the application container. - * - * @return void */ - public function register() + public function register(): void { /* * Register the e-mail checker @@ -44,10 +42,8 @@ public function register() /** * Bootstrap any application services. - * - * @return void */ - public function boot(EmailChecker $checker) + public function boot(EmailChecker $checker): void { /* * Add a custom validator filter. @@ -66,7 +62,7 @@ public function boot(EmailChecker $checker) * * @return array */ - public function provides() + public function provides(): array { return ['email.checker', EmailChecker::class]; } diff --git a/src/EmailChecker/ThrowawayDomains.php b/src/EmailChecker/ThrowawayDomains.php index b7e341a..706ab45 100644 --- a/src/EmailChecker/ThrowawayDomains.php +++ b/src/EmailChecker/ThrowawayDomains.php @@ -18,12 +18,12 @@ * * @implements \IteratorAggregate */ -class ThrowawayDomains implements \IteratorAggregate, \Countable +final class ThrowawayDomains implements \IteratorAggregate, \Countable { /** * @var string[] */ - protected $domains; + private array $domains; public function __construct() { @@ -38,7 +38,7 @@ public function __construct() /** * @return string[] */ - public function toArray() + public function toArray(): array { return $this->domains; } diff --git a/src/EmailChecker/Utilities.php b/src/EmailChecker/Utilities.php index 2eec987..7e50b91 100644 --- a/src/EmailChecker/Utilities.php +++ b/src/EmailChecker/Utilities.php @@ -18,7 +18,7 @@ * * @author Matthieu Moquet */ -class Utilities +final class Utilities { public const EMAIL_REGEX_LOCAL = '(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*'; public const EMAIL_REGEX_DOMAIN = '(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))'; @@ -30,7 +30,7 @@ class Utilities * * @return array{string, string} The parts of the email. First the local part, then the domain */ - public static function parseEmailAddress($email) + public static function parseEmailAddress(string $email): array { $pattern = sprintf('/^(?%s)@(?%s)$/iD', self::EMAIL_REGEX_LOCAL, self::EMAIL_REGEX_DOMAIN); @@ -48,7 +48,7 @@ public static function parseEmailAddress($email) * * @return array Array of cleaned string */ - public static function parseLines($content) + public static function parseLines(string $content): array { // Split by line $lines = explode("\n", $content); diff --git a/tests/EmailChecker/Tests/Adpater/AggregatorAdapterTest.php b/tests/EmailChecker/Tests/Adapter/AggregatorAdapterTest.php similarity index 97% rename from tests/EmailChecker/Tests/Adpater/AggregatorAdapterTest.php rename to tests/EmailChecker/Tests/Adapter/AggregatorAdapterTest.php index 950bdac..d928634 100644 --- a/tests/EmailChecker/Tests/Adpater/AggregatorAdapterTest.php +++ b/tests/EmailChecker/Tests/Adapter/AggregatorAdapterTest.php @@ -9,7 +9,7 @@ * with this source code in the file LICENSE. */ -namespace EmailChecker\Tests\Adpater; +namespace EmailChecker\Tests\Adapter; use EmailChecker\Adapter\AdapterInterface; use EmailChecker\Adapter\AggregatorAdapter; diff --git a/tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php b/tests/EmailChecker/Tests/Adapter/ArrayAdapterTest.php similarity index 97% rename from tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php rename to tests/EmailChecker/Tests/Adapter/ArrayAdapterTest.php index 6f3a867..ae658aa 100644 --- a/tests/EmailChecker/Tests/Adpater/ArrayAdapterTest.php +++ b/tests/EmailChecker/Tests/Adapter/ArrayAdapterTest.php @@ -9,7 +9,7 @@ * with this source code in the file LICENSE. */ -namespace EmailChecker\Tests\Adpater; +namespace EmailChecker\Tests\Adapter; use EmailChecker\Adapter\ArrayAdapter; use EmailChecker\Tests\TestCase; diff --git a/tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php b/tests/EmailChecker/Tests/Adapter/BuiltInAdapterTest.php similarity index 98% rename from tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php rename to tests/EmailChecker/Tests/Adapter/BuiltInAdapterTest.php index e91e977..00e6aa7 100644 --- a/tests/EmailChecker/Tests/Adpater/BuiltInAdapterTest.php +++ b/tests/EmailChecker/Tests/Adapter/BuiltInAdapterTest.php @@ -9,7 +9,7 @@ * with this source code in the file LICENSE. */ -namespace EmailChecker\Tests\Adpater; +namespace EmailChecker\Tests\Adapter; use EmailChecker\Adapter\BuiltInAdapter; use EmailChecker\Tests\TestCase; diff --git a/tests/EmailChecker/Tests/Adpater/FileAdapterTest.php b/tests/EmailChecker/Tests/Adapter/FileAdapterTest.php similarity index 97% rename from tests/EmailChecker/Tests/Adpater/FileAdapterTest.php rename to tests/EmailChecker/Tests/Adapter/FileAdapterTest.php index c2edc75..bcdafb3 100644 --- a/tests/EmailChecker/Tests/Adpater/FileAdapterTest.php +++ b/tests/EmailChecker/Tests/Adapter/FileAdapterTest.php @@ -9,7 +9,7 @@ * with this source code in the file LICENSE. */ -namespace EmailChecker\Tests\Adpater; +namespace EmailChecker\Tests\Adapter; use EmailChecker\Adapter\FileAdapter; use EmailChecker\Tests\TestCase; diff --git a/tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php b/tests/EmailChecker/Tests/Adapter/GaufretteAdapterTest.php similarity index 97% rename from tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php rename to tests/EmailChecker/Tests/Adapter/GaufretteAdapterTest.php index 40800f8..7b3c436 100644 --- a/tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php +++ b/tests/EmailChecker/Tests/Adapter/GaufretteAdapterTest.php @@ -9,7 +9,7 @@ * with this source code in the file LICENSE. */ -namespace EmailChecker\Tests\Adpater; +namespace EmailChecker\Tests\Adapter; use EmailChecker\Adapter\GaufretteAdapter; use EmailChecker\Tests\TestCase; diff --git a/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php b/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php index ad9f962..a2a91c9 100644 --- a/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php +++ b/tests/EmailChecker/Tests/Constraint/NotThrowawayEmailValidatorTest.php @@ -80,9 +80,7 @@ public function getValidEmails(): iterable */ public function testInvalidEmails(string $email): void { - $constraint = new NotThrowawayEmail([ - 'message' => 'myMessage', - ]); + $constraint = new NotThrowawayEmail(message: 'myMessage'); $this->context->expects(self::once()) ->method('addViolation')