Compare commits

...

16 Commits

Author SHA1 Message Date
Eduardo Gulias Davis 1ac0be80b3 bump dependencies and lock 2022-12-29 22:07:24 +01:00
Eduardo Gulias Davis c38e9600fb Merge branch 'derrabus-bump/vendors' into 3.x 2022-12-29 22:01:54 +01:00
Eduardo Gulias Davis 777864f79e Merge branch 'bump/vendors' of https://github.com/derrabus/EmailValidator into derrabus-bump/vendors 2022-12-29 22:01:11 +01:00
Eduardo Gulias Davis ecbcdcef05 Merge branch '3.x' of github.com:egulias/EmailValidator into 3.x 2022-12-29 21:59:01 +01:00
Alexander M. Turek b28de87213 Allow doctrine/lexer 2 (#340) 2022-12-29 21:52:48 +01:00
Alexander M. Turek 6d6a87e5d9 Bump all locked dependencies
- Removing openlss/lib-array2xml (1.0.0)
  - Removing phpspec/prophecy (v1.15.0)
  - Removing webmozart/path-util (2.3.0)
  - Upgrading composer/pcre (3.0.0 => 3.1.0)
  - Locking fidry/cpu-core-counter (0.4.1)
  - Upgrading guzzlehttp/guzzle (7.4.5 => 7.5.0)
  - Upgrading guzzlehttp/promises (1.5.1 => 1.5.2)
  - Upgrading guzzlehttp/psr7 (2.4.0 => 2.4.3)
  - Upgrading netresearch/jsonmapper (v4.0.0 => v4.1.0)
  - Upgrading nikic/php-parser (v4.13.2 => v4.15.2)
  - Upgrading php-coveralls/php-coveralls (v2.5.2 => v2.5.3)
  - Upgrading phpdocumentor/type-resolver (1.6.1 => 1.6.2)
  - Upgrading phpunit/php-code-coverage (9.2.15 => 9.2.23)
  - Upgrading phpunit/phpunit (9.5.20 => 9.5.27)
  - Upgrading sebastian/comparator (4.0.6 => 4.0.8)
  - Upgrading sebastian/exporter (4.0.4 => 4.0.5)
  - Upgrading sebastian/type (3.0.0 => 3.2.0)
  - Locking spatie/array-to-xml (2.17.1)
  - Upgrading symfony/config (v5.4.9 => v5.4.11)
  - Upgrading symfony/console (v5.4.9 => v5.4.16)
  - Upgrading symfony/deprecation-contracts (v2.5.1 => v2.5.2)
  - Upgrading symfony/filesystem (v5.4.9 => v5.4.13)
  - Upgrading symfony/polyfill-ctype (v1.25.0 => v1.27.0)
  - Upgrading symfony/polyfill-intl-grapheme (v1.25.0 => v1.27.0)
  - Upgrading symfony/polyfill-intl-idn (v1.26.0 => v1.27.0)
  - Upgrading symfony/polyfill-intl-normalizer (v1.26.0 => v1.27.0)
  - Upgrading symfony/polyfill-mbstring (v1.26.0 => v1.27.0)
  - Upgrading symfony/polyfill-php72 (v1.26.0 => v1.27.0)
  - Upgrading symfony/polyfill-php73 (v1.25.0 => v1.27.0)
  - Upgrading symfony/polyfill-php80 (v1.25.0 => v1.27.0)
  - Upgrading symfony/polyfill-php81 (v1.25.0 => v1.27.0)
  - Upgrading symfony/service-contracts (v2.5.1 => v2.5.2)
  - Upgrading symfony/stopwatch (v5.4.5 => v5.4.13)
  - Upgrading symfony/string (v5.4.9 => v5.4.15)
  - Upgrading symfony/yaml (v5.4.3 => v5.4.16)
  - Upgrading vimeo/psalm (4.23.0 => 5.4.0)
  - Upgrading webmozart/assert (1.10.0 => 1.11.0)
2022-12-28 13:45:16 +01:00
Alexis Lefebvre 0170967656 CHANGELOG: Fix typo “Breacking” (#333) 2022-09-03 11:54:08 +02:00
Eduardo Gulias Davis 4c72190f32 Update LICENSE 2022-08-14 20:36:33 +02:00
Mathias Reker ⚡️ 413b263617 Nullable type declaration for default null value (#328)
Adds ? before type declarations for parameters with a default null value
2022-07-13 16:53:11 +02:00
Mathias Reker ⚡️ 18b9e5b572 Visibility required (#329)
Visibility MUST be declared on all properties and methods; abstract and final MUST be declared before the visibility; static MUST be declared after the visibility.
2022-07-13 16:52:42 +02:00
Mathias Reker ⚡️ 1ca313dfcd Single blank line at eof (#330)
A PHP file without end tag must always end with a single empty line feed.
2022-07-13 16:51:51 +02:00
Mathias Reker ⚡️ cf5908bb1a No superfluous elseif (#331)
Replaces superfluous elseif with if.
2022-07-13 16:51:22 +02:00
Mathias Reker ⚡️ b241b54919 No unused imports (#332)
Unused use statements must be removed.
2022-07-13 16:50:27 +02:00
dependabot[bot] 74d2f16d9d Bump guzzlehttp/guzzle from 7.4.3 to 7.4.5 (#326)
Bumps [guzzlehttp/guzzle](https://github.com/guzzle/guzzle) from 7.4.3 to 7.4.5.
- [Release notes](https://github.com/guzzle/guzzle/releases)
- [Changelog](https://github.com/guzzle/guzzle/blob/master/CHANGELOG.md)
- [Commits](https://github.com/guzzle/guzzle/compare/7.4.3...7.4.5)

---
updated-dependencies:
- dependency-name: guzzlehttp/guzzle
  dependency-type: indirect
...

Signed-off-by: dependabot[bot] <support@github.com>

Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
2022-06-24 20:51:04 +02:00
Nicolas Grekas f88dcf4b14 Don't use utf8_en/decode() functions, they're deprecated on PHP 8.2 (#325) 2022-06-18 22:57:19 +02:00
Eduardo Gulias Davis e3c1f426e5 Update dependencies 2022-05-28 17:34:06 +02:00
10 changed files with 265 additions and 403 deletions
+1 -1
View File
@@ -3,7 +3,7 @@ imports:
build:
environment:
php: '7.4'
php: '7.3'
tests:
override:
-
+9
View File
@@ -2,6 +2,10 @@ language: php
matrix:
include:
- php: 7.3
env:
- psalm=yes
dist: bionic
- php: 7.4
dist: bionic
env:
@@ -11,6 +15,11 @@ matrix:
- psalm=yes
dist: bionic
#ppc64le support code
- php: 7.3
arch: ppc64le
env:
- psalm=yes
dist: bionic
- php: 7.4
arch: ppc64le
env:
Generated
+232 -286
View File
File diff suppressed because it is too large Load Diff
+1
View File
@@ -1,5 +1,6 @@
<?xml version="1.0"?>
<psalm
totallyTyped="false"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config ./vendor/vimeo/psalm/config.xsd"
+1 -1
View File
@@ -151,7 +151,7 @@ class EmailLexer extends AbstractLexer
/**
* The next token in the input.
*
* @var array{position: int, type: int|null|string, value: int|string}|null
* @var array|null
*/
public $lookahead;
+1 -1
View File
@@ -50,7 +50,7 @@ class DomainLiteral extends PartParser
}
if ($this->lexer->isNextTokenAny(
array(EmailLexer::S_HTAB, EmailLexer::S_SP, EmailLexer::CRLF)
array(EmailLexer::S_HTAB, EmailLexer::S_SP, $this->lexer->token['type'] === EmailLexer::CRLF)
)) {
$this->warnings[CFWSWithFWS::CODE] = new CFWSWithFWS();
$this->parseFWS();
+16 -23
View File
@@ -2,7 +2,6 @@
namespace Egulias\EmailValidator\Validation;
use Egulias\EmailValidator\Validation\DNSGetRecordWrapper;
use Egulias\EmailValidator\EmailLexer;
use Egulias\EmailValidator\Result\InvalidEmail;
use Egulias\EmailValidator\Result\Reason\DomainAcceptsNoMail;
@@ -56,22 +55,11 @@ class DNSCheckValidation implements EmailValidation
*/
private $mxRecords = [];
/**
* @var DNSGetRecordWrapper
*/
private $dnsGetRecord;
public function __construct(DNSGetRecordWrapper $dnsGetRecord = null)
public function __construct()
{
if (!function_exists('idn_to_ascii')) {
throw new \LogicException(sprintf('The %s class requires the Intl extension.', __CLASS__));
}
if ($dnsGetRecord == null) {
$dnsGetRecord = new DNSGetRecordWrapper();
}
$this->dnsGetRecord = $dnsGetRecord;
}
public function isValid(string $email, EmailLexer $emailLexer) : bool
@@ -133,17 +121,27 @@ class DNSCheckValidation implements EmailValidation
*/
private function validateDnsRecords($host) : bool
{
$dnsRecordsResult = $this->dnsGetRecord->getRecords($host, static::DNS_RECORD_TYPES_TO_CHECK);
// A workaround to fix https://bugs.php.net/bug.php?id=73149
/** @psalm-suppress InvalidArgument */
set_error_handler(
static function (int $errorLevel, string $errorMessage): ?bool {
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
}
);
if ($dnsRecordsResult->withError()) {
try {
// Get all MX, A and AAAA DNS records for host
$dnsRecords = dns_get_record($host, static::DNS_RECORD_TYPES_TO_CHECK);
} catch (\RuntimeException $exception) {
$this->error = new InvalidEmail(new UnableToGetDNSRecord(), '');
return false;
} finally {
restore_error_handler();
}
$dnsRecords = $dnsRecordsResult->getRecords();
// No MX, A or AAAA DNS records
if ($dnsRecords === []) {
if ($dnsRecords === [] || $dnsRecords === false) {
$this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
return false;
}
@@ -170,11 +168,6 @@ class DNSCheckValidation implements EmailValidation
*/
private function validateMxRecord($dnsRecord) : bool
{
if (!isset($dnsRecord['type'])) {
$this->error = new InvalidEmail(new ReasonNoDNSRecord(), '');
return false;
}
if ($dnsRecord['type'] !== 'MX') {
return true;
}
-28
View File
@@ -1,28 +0,0 @@
<?php
namespace Egulias\EmailValidator\Validation;
class DNSGetRecordWrapper
{
/**
* @param string $host
* @param int $type
*/
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): ?bool {
throw new \RuntimeException("Unable to get DNS record for the host: $errorMessage");
}
);
try {
// Get all MX, A and AAAA DNS records for host
return new DNSRecords(dns_get_record($host, $type));
} catch (\RuntimeException $exception) {
return new DNSRecords([], true);
} finally {
restore_error_handler();
}
}
}
-35
View File
@@ -1,35 +0,0 @@
<?php
namespace Egulias\EmailValidator\Validation;
class DNSRecords
{
/**
* @var array $records
*/
private $records = [];
/**
* @var bool $error
*/
private $error = false;
public function __construct(array $records, bool $error = false)
{
$this->records = $records;
$this->error = $error;
}
public function getRecords() : array
{
return $this->records;
}
public function withError() : bool
{
return $this->error;
}
}
@@ -9,8 +9,6 @@ use Egulias\EmailValidator\Result\Reason\LocalOrReservedDomain;
use Egulias\EmailValidator\Result\Reason\NoDNSRecord;
use Egulias\EmailValidator\Result\Reason\UnableToGetDNSRecord;
use Egulias\EmailValidator\Validation\DNSCheckValidation;
use Egulias\EmailValidator\Validation\DNSGetRecordWrapper;
use Egulias\EmailValidator\Validation\DNSRecords;
use Egulias\EmailValidator\Warning\NoDNSMXRecord;
use PHPUnit\Framework\TestCase;
@@ -118,35 +116,13 @@ class DNSCheckValidationTest extends TestCase
error_reporting(\E_ALL);
// UnableToGetDNSRecord raises on network errors (e.g. timeout) that we cant emulate in tests (for sure),
// but we can simulate with the wrapper helper
$wrapper = new class extends DNSGetRecordWrapper {
public function getRecords(string $host, int $type) : DNSRecords
{
return new DNSRecords([], true);
}
// but we can try to get timeout error by trying to fetch all DNS records
$validation = new class extends DNSCheckValidation {
protected const DNS_RECORD_TYPES_TO_CHECK = \DNS_ALL;
};
$validation = new DNSCheckValidation($wrapper);
$expectedError = new InvalidEmail(new UnableToGetDNSRecord(), '');
$validation->isValid('example@invalid.example.com', new EmailLexer());
$this->assertEquals($expectedError, $validation->getError());
}
public function testMissingTypeKey()
{
$wrapper = new class extends DNSGetRecordWrapper {
public function getRecords(string $host, int $type): DNSRecords
{
return new DNSRecords(['host' => 'test']);
}
};
$validation = new DNSCheckValidation($wrapper);
$expectedError = new InvalidEmail(new NoDNSRecord(), '');
$validation->isValid('example@invalid.example.com', new EmailLexer());
$this->assertEquals($expectedError, $validation->getError());
}
}
}