Skip to content
Merged
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 .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
.github export-ignore
.gitattributes export-ignore
.gitignore export-ignore
.php_cs export-ignore
.php-cs-fixer.dist.php export-ignore
phpunit.xml.dist export-ignore
37 changes: 30 additions & 7 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,18 +13,18 @@ jobs:
fail-fast: false
matrix:
php-version:
- '7.1'
- '7.2'
- '7.3'
- '7.4'
- '8.0'
- '8.1'
- '8.2'
- '8.3'
- '8.4'
- '8.5'
dependencies: [highest]
include:
- php-version: '8.0'
dependencies: lowest

name: PHP ${{ matrix.php-version }}
name: PHP ${{ matrix.php-version }} ${{ matrix.dependencies }}

steps:
- name: Checkout code
Expand All @@ -36,8 +36,31 @@ jobs:
php-version: ${{ matrix.php-version }}
coverage: none

- name: Install dependencies
run: composer install --prefer-dist --no-progress --no-interaction
- name: Install Composer dependencies (${{ matrix.dependencies }})
uses: ramsey/composer-install@v3
with:
dependency-versions: ${{ matrix.dependencies }}

- name: Run tests
run: composer test

lint:
runs-on: ubuntu-latest

name: PHP Cs Fixer

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: 8.5
coverage: none

- name: Install Composer dependencies
uses: ramsey/composer-install@v3

- name: Run lint
run: composer lint
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/.php_cs.cache
/.php-cs-fixer.cache
/.phpunit.result.cache
/composer.lock
/vendor
27 changes: 27 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

$header = <<<EOF
This file is part of the EmailChecker package.

(c) Matthieu Moquet <[email protected]>

This source file is subject to the MIT license that is bundled
with this source code in the file LICENSE.
EOF;

$finder = PhpCsFixer\Finder::create()
->files()
->in(__DIR__)
->exclude('res')
->exclude('tests/bootstrap.php')
->exclude('vendor')
->name('*.php');

return (new PhpCsFixer\Config())
->setRules([
'@Symfony' => true,
'header_comment' => [
'header' => $header,
]
])
->setFinder($finder);
29 changes: 0 additions & 29 deletions .php_cs

This file was deleted.

17 changes: 7 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
# EmailChecker

[![Build status...](https://img.shields.io/travis/MattKetmo/EmailChecker.svg)](http://travis-ci.org/MattKetmo/EmailChecker)
[![Code quality...](https://img.shields.io/scrutinizer/g/MattKetmo/EmailChecker.svg)](https://scrutinizer-ci.com/g/MattKetmo/EmailChecker/)
[![Downloads](https://img.shields.io/packagist/dt/mattketmo/email-checker.svg)](https://packagist.org/packages/mattketmo/email-checker)
[![Packagist](http://img.shields.io/packagist/v/mattketmo/email-checker.svg)](https://packagist.org/packages/mattketmo/email-checker)
Expand Down Expand Up @@ -57,9 +56,9 @@ $checker->isValid('[email protected]'); // false
You can build your own adapter (to use another database) simply by implementing
the [AdapterInterface](src/EmailChecker/Adapter/AdapterInterface.php).

## Integration with Symfony2
## Integration with Symfony

This library also provides a constraint validation for your Symfony2 project:
This library also provides a constraint validation for your Symfony project:

```php
<?php
Expand All @@ -69,17 +68,15 @@ use Symfony\Component\Validator\Constraints as Assert;

class User
{
/**
* @Assert\NotBlank
* @EmailCheckerAssert\NotThrowawayEmail
*/
protected $email;
#[Assert\NotBlank]
#[EmailCheckerAssert\NotThrowawayEmail]
private string $email;
}
```

## Integration with Laravel 5
## Integration with Laravel

To integrate this library with your Laravel 5.x project add the following
To integrate this library with your Laravel project add the following
line to the `providers` key within your `config/app.php` file:

```php
Expand Down
12 changes: 6 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
}
],
"require": {
"php": "^7.1 || ^8.0"
"php": "^8.0"
},
"require-dev": {
"friendsofphp/php-cs-fixer": "^2.18",
"illuminate/support": "^5.0 || ^6.0 || ^7.0 || ^8.0",
"knplabs/gaufrette": "^0.10",
"phpunit/phpunit": "^7.5 || ^9.5",
"symfony/validator": "^3.0 || ^4.0 || ^5.0"
"friendsofphp/php-cs-fixer": "^3.91",
"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.0"
},
"suggest": {
"symfony/validator": "Add validation constraints",
Expand Down
7 changes: 1 addition & 6 deletions src/EmailChecker/Adapter/AgregatorAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,18 +29,13 @@ public function __construct(array $adapters)
{
foreach ($adapters as $adapter) {
if (!$adapter instanceof AdapterInterface) {
throw new \InvalidArgumentException(
'AgregatorAdapter only accept instances of AdapterInterface'
);
throw new \InvalidArgumentException('AgregatorAdapter only accept instances of AdapterInterface');
}
}

$this->adapters = $adapters;
}

/**
* {@inheritdoc}
*/
public function isThrowawayDomain($domain)
{
foreach ($this->adapters as $adapter) {
Expand Down
3 changes: 0 additions & 3 deletions src/EmailChecker/Adapter/ArrayAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@ public function __construct(array $domains)
$this->domains = $domains;
}

/**
* {@inheritdoc}
*/
public function isThrowawayDomain($domain)
{
return in_array($domain, $this->domains);
Expand Down
3 changes: 0 additions & 3 deletions src/EmailChecker/Adapter/FileAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@ public function __construct($filename)
$this->domains = Utilities::parseLines(file_get_contents($filename));
}

/**
* {@inheritdoc}
*/
public function isThrowawayDomain($domain)
{
return in_array($domain, $this->domains);
Expand Down
6 changes: 0 additions & 6 deletions src/EmailChecker/Adapter/GaufretteAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,11 @@ class GaufretteAdapter implements AdapterInterface
{
protected $domains;

/**
* @param File $file
*/
public function __construct(File $file)
{
$this->domains = Utilities::parseLines($file->getContent());
}

/**
* {@inheritdoc}
*/
public function isThrowawayDomain($domain)
{
return in_array($domain, $this->domains);
Expand Down
3 changes: 2 additions & 1 deletion src/EmailChecker/Constraints/NotThrowawayEmail.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

/**
* @author Matthieu Moquet <[email protected]>
*
* @Annotation
*/
#[\Attribute]
Expand All @@ -26,7 +27,7 @@ public function __construct(
$options = null,
?array $groups = null,
$payload = null,
?string $message = null
?string $message = null,
) {
parent::__construct($options, $groups, $payload);

Expand Down
7 changes: 0 additions & 7 deletions src/EmailChecker/Constraints/NotThrowawayEmailValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

namespace EmailChecker\Constraints;

use EmailChecker\Adapter\BuiltInAdapter;
use EmailChecker\EmailChecker;
use Symfony\Component\Validator\Constraint;
use Symfony\Component\Validator\ConstraintValidator;
Expand All @@ -24,17 +23,11 @@ class NotThrowawayEmailValidator extends ConstraintValidator
{
protected $emailChecker;

/**
* @param EmailChecker $emailChecker
*/
public function __construct(?EmailChecker $emailChecker = null)
{
$this->emailChecker = $emailChecker ?: new EmailChecker();
}

/**
* {@inheritdoc}
*/
public function validate($value, Constraint $constraint)
{
if (null === $value || '' === $value) {
Expand Down
2 changes: 1 addition & 1 deletion src/EmailChecker/Laravel/EmailCheckerServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace EmailChecker\Laravel;

use EmailChecker\EmailChecker;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\ServiceProvider;

/**
* Laravel service provider.
Expand Down
4 changes: 2 additions & 2 deletions src/EmailChecker/Utilities.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@
*/
class Utilities
{
const EMAIL_REGEX_LOCAL = '(?!(?:(?:\\x22?\\x5C[\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2})|(?:[1-9]?[0-9]))){3}))\\]))';
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}))\\]))';

/**
* Extract parts of an email address.
Expand Down