This commit is contained in:
2025-05-12 14:25:25 +02:00
parent ab2db755ef
commit 9e378ca2b7
2719 changed files with 46505 additions and 60181 deletions

View File

@@ -1,32 +0,0 @@
# EmailValidator Changelog
## New Features
* Access to local part and domain part from EmailParser
* Validations outside of the scope of the RFC will be considered "extra" validations, thus opening the door for adding new; will live in their own folder "extra" (as requested in #248, #195, #183).
## Breaking changes
* PHP version upgraded to match Symfony's (as of 12/2020).
* DNSCheckValidation now fails for missing MX records. While the RFC argues that the existence of only A records to be valid, starting in v3 they will be considered invalid.
* Emails domain part are now intenteded to be RFC 1035 compliant, rendering previous valid emails (e.g example@examp&) invalid.
## PHP versions upgrade policy
PHP version upgrade requirement will happen via MINOR (3.x) version upgrades of the library, following the adoption level by major frameworks.
## Changes
* #235
* #215
* #130
* #258
* #188
* #181
* #217
* #214
* #249
* #236
* #257
* #210
## Thanks
To contributors, be it with PRs, reporting issues or supporting otherwise.

View File

@@ -61,7 +61,7 @@ class EmailLexer extends AbstractLexer
/**
* US-ASCII visible characters not valid for atext (@link http://tools.ietf.org/html/rfc5322#section-3.2.3)
*
* @var array
* @var array<string, int>
*/
protected $charValue = [
'{' => self::S_OPENCURLYBRACES,
@@ -177,7 +177,6 @@ class EmailLexer extends AbstractLexer
* @throws \UnexpectedValueException
* @return boolean
*
* @psalm-suppress InvalidScalarArgument
*/
public function find($type): bool
{

View File

@@ -8,11 +8,12 @@ use Egulias\EmailValidator\Result\ValidEmail;
use Egulias\EmailValidator\Warning\CFWSNearAt;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Result\Reason\ExpectingATEXT;
use Egulias\EmailValidator\Warning\Warning;
class LocalComment implements CommentStrategy
{
/**
* @var array
* @var array<int, Warning>
*/
private $warnings = [];

View File

@@ -307,6 +307,7 @@ class DomainPart extends PartParser
{
if (preg_match('/[^\x00-\x7F]/', $label)) {
idn_to_ascii($label, IDNA_DEFAULT, INTL_IDNA_VARIANT_UTS46, $idnaInfo);
/** @psalm-var array{errors: int, ...} $idnaInfo */
return (bool) ($idnaInfo['errors'] & IDNA_ERROR_LABEL_TOO_LONG);
}
return strlen($label) > self::LABEL_MAX_LENGTH;

View File

@@ -34,6 +34,7 @@ class LocalPart extends PartParser
public function parse(): Result
{
$this->lexer->clearRecorded();
$this->lexer->startRecording();
while (!$this->lexer->current->isA(EmailLexer::S_AT) && !$this->lexer->current->isA(EmailLexer::S_EMPTY)) {

View File

@@ -11,6 +11,6 @@ class NoDNSRecord implements Reason
public function description() : string
{
return 'No MX or A DSN record was found for this email';
return 'No MX or A DNS record was found for this email';
}
}

View File

@@ -6,22 +6,26 @@ interface Result
{
/**
* Is validation result valid?
*
*/
public function isValid() : bool;
public function isValid(): bool;
/**
* Is validation result invalid?
* Usually the inverse of isValid()
*
*/
public function isInvalid() : bool;
public function isInvalid(): bool;
/**
* Short description of the result, human readable.
*
*/
public function description() : string;
public function description(): string;
/**
* Code for user land to act upon.
*
*/
public function code() : int;
public function code(): int;
}

View File

@@ -7,13 +7,12 @@ class DNSGetRecordWrapper
/**
* @param string $host
* @param int $type
*
*
* @return DNSRecords
*/
public function getRecords(string $host, int $type): DNSRecords
{
// A workaround to fix https://bugs.php.net/bug.php?id=73149
/** @psalm-suppress InvalidArgument */
set_error_handler(
static function (int $errorLevel, string $errorMessage): never {
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");

View File

@@ -5,7 +5,7 @@ namespace Egulias\EmailValidator\Validation;
class DNSRecords
{
/**
* @param array $records
* @param list<array<array-key, mixed>> $records
* @param bool $error
*/
public function __construct(private readonly array $records, private readonly bool $error = false)
@@ -13,7 +13,7 @@ class DNSRecords
}
/**
* @return array
* @return list<array<array-key, mixed>>
*/
public function getRecords(): array
{

View File

@@ -22,9 +22,6 @@ class SpoofCheckValidation implements EmailValidation
}
}
/**
* @psalm-suppress InvalidArgument
*/
public function isValid(string $email, EmailLexer $emailLexer) : bool
{
$checker = new Spoofchecker();

View File

@@ -2,16 +2,26 @@
namespace Egulias\EmailValidator\Warning;
use UnitEnum;
class QuotedPart extends Warning
{
public const CODE = 36;
/**
* @param scalar|null $prevToken
* @param scalar|null $postToken
* @param UnitEnum|string|int|null $prevToken
* @param UnitEnum|string|int|null $postToken
*/
public function __construct($prevToken, $postToken)
{
if ($prevToken instanceof UnitEnum) {
$prevToken = $prevToken->name;
}
if ($postToken instanceof UnitEnum) {
$postToken = $postToken->name;
}
$this->message = "Deprecated Quoted String found between $prevToken and $postToken";
}
}

View File

@@ -7,8 +7,8 @@ class QuotedString extends Warning
public const CODE = 11;
/**
* @param scalar $prevToken
* @param scalar $postToken
* @param string|int $prevToken
* @param string|int $postToken
*/
public function __construct($prevToken, $postToken)
{