Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/EmailChecker/Adapter/AdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ interface AdapterInterface
*
* @return bool True for a throwaway domain
*/
public function isThrowawayDomain($domain);
public function isThrowawayDomain(string $domain): bool;
}
12 changes: 3 additions & 9 deletions src/EmailChecker/Adapter/AggregatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,18 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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)) {
Expand Down
33 changes: 0 additions & 33 deletions src/EmailChecker/Adapter/AgregatorAdapter.php

This file was deleted.

12 changes: 3 additions & 9 deletions src/EmailChecker/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,16 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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);
}
Expand Down
8 changes: 4 additions & 4 deletions src/EmailChecker/Adapter/BuiltInAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,22 +23,22 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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);
}

/**
* @return string[]
*/
private function getDomains()
private function getDomains(): array
{
if (null === $this->domains) {
$this->domains = (new ThrowawayDomains())->toArray();
Expand Down
8 changes: 4 additions & 4 deletions src/EmailChecker/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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) {
Expand All @@ -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);
}
Expand Down
6 changes: 3 additions & 3 deletions src/EmailChecker/Adapter/GaufretteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,19 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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);
}
Expand Down
9 changes: 4 additions & 5 deletions src/EmailChecker/Constraints/NotThrowawayEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,20 +19,19 @@
* @Annotation
*/
#[\Attribute]
class NotThrowawayEmail extends Constraint
final class NotThrowawayEmail extends Constraint
{
/**
* @var string
*/
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;
}
Expand Down
16 changes: 3 additions & 13 deletions src/EmailChecker/Constraints/NotThrowawayEmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,23 @@
namespace EmailChecker\Constraints;

use EmailChecker\EmailChecker;
use ReturnTypeWillChange;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
use Symfony\Component\Validator\Exception\UnexpectedTypeException;

/**
* @author Matthieu Moquet <[email protected]>
*/
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);
Expand Down
11 changes: 4 additions & 7 deletions src/EmailChecker/EmailChecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,12 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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)
{
Expand All @@ -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;
Expand Down
2 changes: 1 addition & 1 deletion src/EmailChecker/Laravel/EmailCheckerFacade.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Oliver Green <[email protected]>
*/
class EmailCheckerFacade extends Facade
final class EmailCheckerFacade extends Facade
{
/**
* Get the registered name of the component.
Expand Down
12 changes: 4 additions & 8 deletions src/EmailChecker/Laravel/EmailCheckerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,12 @@
*
* @author Oliver Green <[email protected]>
*/
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
Expand All @@ -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.
Expand All @@ -66,7 +62,7 @@ public function boot(EmailChecker $checker)
*
* @return array<string>
*/
public function provides()
public function provides(): array
{
return ['email.checker', EmailChecker::class];
}
Expand Down
6 changes: 3 additions & 3 deletions src/EmailChecker/ThrowawayDomains.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
*
* @implements \IteratorAggregate<string>
*/
class ThrowawayDomains implements \IteratorAggregate, \Countable
final class ThrowawayDomains implements \IteratorAggregate, \Countable
{
/**
* @var string[]
*/
protected $domains;
private array $domains;

public function __construct()
{
Expand All @@ -38,7 +38,7 @@ public function __construct()
/**
* @return string[]
*/
public function toArray()
public function toArray(): array
{
return $this->domains;
}
Expand Down
6 changes: 3 additions & 3 deletions src/EmailChecker/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
*
* @author Matthieu Moquet <[email protected]>
*/
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}))\\]))';
Expand All @@ -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('/^(?<local>%s)@(?<domain>%s)$/iD', self::EMAIL_REGEX_LOCAL, self::EMAIL_REGEX_DOMAIN);

Expand All @@ -48,7 +48,7 @@ public static function parseEmailAddress($email)
*
* @return array<string> Array of cleaned string
*/
public static function parseLines($content)
public static function parseLines(string $content): array
{
// Split by line
$lines = explode("\n", $content);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Loading