diff --git a/.gitattributes b/.gitattributes index ccdf623..b4fcd6b 100644 --- a/.gitattributes +++ b/.gitattributes @@ -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 diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 2c96ae2..b285223 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -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 @@ -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 diff --git a/.gitignore b/.gitignore index 449b6a2..3c04f0e 100644 --- a/.gitignore +++ b/.gitignore @@ -1,4 +1,4 @@ -/.php_cs.cache +/.php-cs-fixer.cache /.phpunit.result.cache /composer.lock /vendor diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..1caa7ef --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,27 @@ + + +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); diff --git a/.php_cs b/.php_cs deleted file mode 100644 index 8034855..0000000 --- a/.php_cs +++ /dev/null @@ -1,29 +0,0 @@ - - -This source file is subject to the MIT license that is bundled -with this source code in the file LICENSE. -EOF; - -Symfony\CS\Fixer\Contrib\HeaderCommentFixer::setHeader($header); - -return Symfony\CS\Config\Config::create() - ->level(Symfony\CS\FixerInterface::SYMFONY_LEVEL) - ->fixers(array( - 'header_comment', - 'ordered_use', - 'short_array_syntax', - )) - ->setUsingCache(true) - ->setUsingLinter(false) - ->finder( - Symfony\CS\Finder\DefaultFinder::create() - ->in([__DIR__]) - ->exclude('res') - ->exclude('tests/bootstrap.php') - ) -; diff --git a/README.md b/README.md index b5d801f..542216d 100644 --- a/README.md +++ b/README.md @@ -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) @@ -57,9 +56,9 @@ $checker->isValid('foo@baz.net'); // 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 adapters = $adapters; } - /** - * {@inheritdoc} - */ public function isThrowawayDomain($domain) { foreach ($this->adapters as $adapter) { diff --git a/src/EmailChecker/Adapter/ArrayAdapter.php b/src/EmailChecker/Adapter/ArrayAdapter.php index cd9b075..4de61fd 100644 --- a/src/EmailChecker/Adapter/ArrayAdapter.php +++ b/src/EmailChecker/Adapter/ArrayAdapter.php @@ -28,9 +28,6 @@ public function __construct(array $domains) $this->domains = $domains; } - /** - * {@inheritdoc} - */ public function isThrowawayDomain($domain) { return in_array($domain, $this->domains); diff --git a/src/EmailChecker/Adapter/FileAdapter.php b/src/EmailChecker/Adapter/FileAdapter.php index a552755..eae9c0c 100644 --- a/src/EmailChecker/Adapter/FileAdapter.php +++ b/src/EmailChecker/Adapter/FileAdapter.php @@ -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); diff --git a/src/EmailChecker/Adapter/GaufretteAdapter.php b/src/EmailChecker/Adapter/GaufretteAdapter.php index 86d85c7..3625b2d 100644 --- a/src/EmailChecker/Adapter/GaufretteAdapter.php +++ b/src/EmailChecker/Adapter/GaufretteAdapter.php @@ -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); diff --git a/src/EmailChecker/Constraints/NotThrowawayEmail.php b/src/EmailChecker/Constraints/NotThrowawayEmail.php index 0037b89..d74c1d1 100644 --- a/src/EmailChecker/Constraints/NotThrowawayEmail.php +++ b/src/EmailChecker/Constraints/NotThrowawayEmail.php @@ -15,6 +15,7 @@ /** * @author Matthieu Moquet + * * @Annotation */ #[\Attribute] @@ -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); diff --git a/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php b/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php index 1ea9f38..a41d741 100644 --- a/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php +++ b/src/EmailChecker/Constraints/NotThrowawayEmailValidator.php @@ -11,7 +11,6 @@ namespace EmailChecker\Constraints; -use EmailChecker\Adapter\BuiltInAdapter; use EmailChecker\EmailChecker; use Symfony\Component\Validator\Constraint; use Symfony\Component\Validator\ConstraintValidator; @@ -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) { diff --git a/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php b/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php index 41f65fc..c0732be 100644 --- a/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php +++ b/src/EmailChecker/Laravel/EmailCheckerServiceProvider.php @@ -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. diff --git a/src/EmailChecker/Utilities.php b/src/EmailChecker/Utilities.php index 340d798..e73c52d 100644 --- a/src/EmailChecker/Utilities.php +++ b/src/EmailChecker/Utilities.php @@ -20,8 +20,8 @@ */ class Utilities { - 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)))*'; - 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}))\\]))'; + 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.