From f843d0e0099d9f171331ea05c8d38e416142ea3a Mon Sep 17 00:00:00 2001 From: Ambroise Maupate Date: Mon, 2 Dec 2024 21:25:00 +0100 Subject: [PATCH 1/2] feat: Upgraded to PHP 7.4 min, use strict_types, upgraded dev dependencies, removed useless phpdocs --- .github/workflows/run-test.yml | 43 ++++++++++++++++++++++++ .gitignore | 1 + .php-cs-fixer.dist.php | 18 ++++++++++ .travis.yml | 14 -------- LICENSE | 2 +- Makefile | 6 ++-- composer.json | 10 +++--- phpcs.xml.dist | 15 --------- phpstan.neon | 3 +- src/EmailCanonizer.php | 13 ++----- src/Exception/EmailNotSupported.php | 5 +-- src/Strategy/CanonizeStrategy.php | 1 + src/Strategy/GSuiteStrategy.php | 12 +++---- src/Strategy/GmailStrategy.php | 7 ++-- src/Strategy/LowercaseDomainStrategy.php | 3 +- src/Strategy/OutlookStrategy.php | 2 ++ tests/EmailCanonizerTest.php | 1 + tests/Strategy/GSuiteStrategyTest.php | 1 + tests/Strategy/GmailStrategyTest.php | 1 + tests/Strategy/OutlookStrategyTest.php | 1 + 20 files changed, 94 insertions(+), 65 deletions(-) create mode 100644 .github/workflows/run-test.yml create mode 100644 .php-cs-fixer.dist.php delete mode 100644 .travis.yml delete mode 100644 phpcs.xml.dist diff --git a/.github/workflows/run-test.yml b/.github/workflows/run-test.yml new file mode 100644 index 0000000..28c24ec --- /dev/null +++ b/.github/workflows/run-test.yml @@ -0,0 +1,43 @@ +name: Static analysis and code style + +on: + push: + branches: + - master + tags: ['**'] + pull_request: + types: + - opened + - reopened + - synchronize + - ready_for_review + +jobs: + static-analysis-tests: + runs-on: ubuntu-latest + strategy: + matrix: + php-version: ['7.4', '8.0', '8.1', '8.2', '8.3', '8.4'] + steps: + - uses: shivammathur/setup-php@v2 + with: + php-version: ${{ matrix.php-version }} + - uses: actions/checkout@v3 + - name: Cache Composer packages + id: composer-cache + uses: actions/cache@v3 + with: + path: vendor + key: ${{ runner.os }}-php-${{ matrix.php-version }}-${{ hashFiles('**/composer.lock') }} + restore-keys: | + ${{ runner.os }}-php-${{ matrix.php-version }}- + - name: Install Dependencies + run: composer install --no-scripts --no-ansi --no-interaction --no-progress + - name: Run PHP CS fixer + env: + PHP_CS_FIXER_IGNORE_ENV: 1 + run: vendor/bin/php-cs-fixer check --ansi -vvv + - name: Run PHP Unit tests + run: vendor/bin/phpunit --bootstrap vendor/autoload.php tests/ + - name: Run PHPStan + run: vendor/bin/phpstan analyse --no-progress -c phpstan.neon diff --git a/.gitignore b/.gitignore index 3ab8938..25ae6ab 100644 --- a/.gitignore +++ b/.gitignore @@ -6,3 +6,4 @@ composer.phar # You may choose to ignore a library lock file http://getcomposer.org/doc/02-libraries.md#lock-file composer.lock /.phpcs-cache +/.php-cs-fixer.cache diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..a20c048 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,18 @@ +in(__DIR__) + ->exclude([ + 'vendor', + ]) +; + +return (new PhpCsFixer\Config()) + ->setRules([ + 'blank_line_after_opening_tag' => true, + 'declare_strict_types' => true, + ]) + ->setParallelConfig(PhpCsFixer\Runner\Parallel\ParallelConfigFactory::detect()) + ->setRiskyAllowed(true) + ->setFinder($finder) +; diff --git a/.travis.yml b/.travis.yml deleted file mode 100644 index 0c895c5..0000000 --- a/.travis.yml +++ /dev/null @@ -1,14 +0,0 @@ -language: php -sudo: required -php: - - 7.2 - - 7.3 - - 7.4 - - 8.0 -install: - - curl -s http://getcomposer.org/installer | php - - php composer.phar install --dev --no-interaction -script: - - php -d memory_limit=-1 vendor/bin/phpunit --bootstrap vendor/autoload.php tests/ - - php -d memory_limit=-1 vendor/bin/phpcbf -p - - php -d memory_limit=-1 vendor/bin/phpstan analyse -c phpstan.neon diff --git a/LICENSE b/LICENSE index 53c4945..b0a3ac7 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2019 Rezo Zero +Copyright (c) 2024 Rezo Zero Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/Makefile b/Makefile index 2e59a1b..f765c66 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ test : - ./vendor/bin/phpunit --bootstrap vendor/autoload.php tests/ - ./vendor/bin/phpcbf -p - ./vendor/bin/phpstan analyse -c phpstan.neon + vendor/bin/phpunit --bootstrap vendor/autoload.php tests/ + PHP_CS_FIXER_IGNORE_ENV=1 vendor/bin/php-cs-fixer fix --ansi -vvv + vendor/bin/phpstan analyse -c phpstan.neon diff --git a/composer.json b/composer.json index fd028bb..094fff4 100644 --- a/composer.json +++ b/composer.json @@ -3,8 +3,8 @@ "description": "Simple PHP library to canonize emails address from gmail.com or other providers that allow several forms of email.", "type": "library", "require": { - "php": ">=7.2", - "beberlei/assert": "^3.2" + "php": ">=7.4", + "beberlei/assert": "^3.3" }, "license": "MIT", "authors": [ @@ -19,8 +19,8 @@ } }, "require-dev": { - "phpunit/phpunit": "^8", - "squizlabs/php_codesniffer": "^3.5", - "phpstan/phpstan": "^0.12.32" + "phpunit/phpunit": "^9", + "phpstan/phpstan": "^1.12.12", + "friendsofphp/php-cs-fixer": "^3.64" } } diff --git a/phpcs.xml.dist b/phpcs.xml.dist deleted file mode 100644 index 496c54d..0000000 --- a/phpcs.xml.dist +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - src/ - diff --git a/phpstan.neon b/phpstan.neon index a4c25fe..7245324 100644 --- a/phpstan.neon +++ b/phpstan.neon @@ -2,5 +2,6 @@ parameters: level: max paths: - src + ignoreErrors: + - identifier: missingType.iterableValue reportUnmatchedIgnoredErrors: false - checkMissingIterableValueType: false diff --git a/src/EmailCanonizer.php b/src/EmailCanonizer.php index 92ebf0d..101c688 100644 --- a/src/EmailCanonizer.php +++ b/src/EmailCanonizer.php @@ -1,4 +1,5 @@ minCount(1); - Assert::thatAll($mxHosts)->inArray(static::$googleMxHosts); + Assert::thatAll($mxHosts)->inArray(self::$googleMxHosts); return true; } return false; diff --git a/src/Strategy/GmailStrategy.php b/src/Strategy/GmailStrategy.php index 7c7ffca..c5e7942 100644 --- a/src/Strategy/GmailStrategy.php +++ b/src/Strategy/GmailStrategy.php @@ -1,15 +1,12 @@ Date: Mon, 2 Dec 2024 21:28:56 +0100 Subject: [PATCH 2/2] chore: Added changelog, github status badge --- CHANGELOG.md | 11 +++++ README.md | 4 +- cliff.toml | 112 +++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 125 insertions(+), 2 deletions(-) create mode 100644 CHANGELOG.md create mode 100644 cliff.toml diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..8ddb405 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,11 @@ +# Changelog + +All notable changes to canonical-email will be documented in this file. + +## [1.1.0](https://github.com/rezozero/canonical-email/compare/1.0.2...1.1.0) - 2024-12-02 + +### Features + +- Upgraded to PHP 7.4 min, use strict_types, upgraded dev dependencies, removed useless phpdocs - ([f843d0e](https://github.com/rezozero/canonical-email/commit/f843d0e0099d9f171331ea05c8d38e416142ea3a)) + + diff --git a/README.md b/README.md index 4bf632f..f1441d4 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ # canonical-email Simple PHP library to canonize email addresses from gmail.com, outlook.com or other providers that allow several forms of email. -[![Build Status](https://travis-ci.org/rezozero/canonical-email.svg?branch=master)](https://travis-ci.org/rezozero/canonical-email) +[![Static analysis and code style](https://github.com/rezozero/canonical-email/actions/workflows/run-test.yml/badge.svg)](https://github.com/rezozero/canonical-email/actions/workflows/run-test.yml) **Be careful: do not store canonical email as primary email for login or sending emails!** Your users may not be able to login again to your site if they used a specific email syntax which differs from canonical. Only store canonical emails in order to test against duplicates and prevent new users from creating multiple accounts with same email using variants. @@ -10,7 +10,7 @@ Always store `email` and `canonical_email` in your databases. ## Strategies -- `LowercaseDomainStrategy`: for every emails, domain is case insensitive, so it should be lowercased. +- `LowercaseDomainStrategy`: for every email, domain is case-insensitive, so it should be lowercased. - `GmailStrategy`: for `@gmail.com` addresses or whatever domain which MX servers are from Google GSuite (if `$checkMxRecords` is `true`). This will remove any dots, and any character after `+` sign. Then all email parts will be lowercased. When MX are checked, your app will use PHP `getmxrr` function. - `OutlookStrategy`: for `@outlook.com` addresses. This will remove any character after `+` sign. diff --git a/cliff.toml b/cliff.toml new file mode 100644 index 0000000..9a6dc44 --- /dev/null +++ b/cliff.toml @@ -0,0 +1,112 @@ +# git-cliff ~ default configuration file +# https://git-cliff.org/docs/configuration +# +# Lines starting with "#" are comments. +# Configuration options are organized into tables and keys. +# See documentation for more information on available options. + +[changelog] +# changelog header +header = """ +# Changelog\n +All notable changes to canonical-email will be documented in this file.\n +""" +# template for the changelog body +# https://keats.github.io/tera/docs/#introduction +body = """ +{% if version %}\ + {% if previous.version %}\ + ## [{{ version | trim_start_matches(pat="v") }}](/compare/{{ previous.version }}...{{ version }}) - {{ timestamp | date(format="%Y-%m-%d") }} + {% else %}\ + ## [{{ version | trim_start_matches(pat="v") }}] - {{ timestamp | date(format="%Y-%m-%d") }} + {% endif %}\ +{% else %}\ + ## [unreleased] +{% endif %}\ + +{% set_global breaking_descriptions = [] %}\ +{% for commit in commits | filter(attribute="breaking", value=true) | unique(attribute="message") %}\ + {% if commit.breaking_description %}\ + {% set_global breaking_descriptions = breaking_descriptions | concat(with=commit.breaking_description) %}\ + {% else %}\ + {% set_global breaking_descriptions = breaking_descriptions | concat(with=commit.message) %}\ + {% endif %}\ +{% endfor %}\ +{% if breaking_descriptions | length > 0 %} + ### ⚠ Breaking changes + {% for description in breaking_descriptions %} + - {{ description | upper_first }}\ + {% endfor %} +{% endif %}\ + +{% for group, commits in commits | group_by(attribute="group") %} + ### {{ group | striptags | trim | upper_first }} + {% for commit in commits + | filter(attribute="scope") + | unique(attribute="message") + | sort(attribute="scope") %} + - **({{commit.scope}})**{% if commit.breaking %} [**breaking**]{% endif %} \ + {{ commit.message }} - ([{{ commit.id | truncate(length=7, end="") }}](/commit/{{ commit.id }})) + {%- endfor -%} + {% raw %}\n{% endraw %}\ + {%- for commit in commits | unique(attribute="message") %} + {%- if commit.scope -%} + {% else -%} + - {% if commit.breaking %} [**breaking**]{% endif %}\ + {{ commit.message }} - ([{{ commit.id | truncate(length=7, end="") }}](/commit/{{ commit.id }})) + {% endif -%} + {% endfor -%} +{% endfor %}\n +""" +# remove the leading and trailing whitespace from the template +trim = true +# changelog footer +footer = """ + +""" +# postprocessors +postprocessors = [ + { pattern = '', replace = "https://github.com/rezozero/canonical-email" }, +] +[git] +# parse the commits based on https://www.conventionalcommits.org +conventional_commits = true +# filter out the commits that are not conventional +filter_unconventional = true +# process each line of a commit as an individual commit +split_commits = false +# regex for preprocessing the commit messages +commit_preprocessors = [ + { pattern = '\((\w+\s)?#([0-9]+)\)', replace = "([#${2}](/issues/${2}))"}, # replace issue numbers +] +# regex for parsing and grouping commits +commit_parsers = [ + { message = "^feat(ure)?", group = "Features" }, + { message = "^fix(es)?", group = "Bug Fixes" }, + { message = "^docs?", group = "Documentation" }, + { message = "^perf", group = "Performance" }, + { message = "^refactor", group = "Refactor" }, + { message = "^style", group = "Styling" }, + { message = "^tests?", group = "Testing" }, + { message = "^chore", skip = true }, + { message = "^ci", group = "CI/CD" }, + { body = ".*security", group = "Security" }, + { message = "^revert", group = "Revert" }, +] +# protect breaking changes from being skipped due to matching a skipping commit_parser +protect_breaking_commits = false +# filter out the commits that are not matched by commit parsers +filter_commits = true +# regex for matching git tags +tag_pattern = "v?[0-9].*" + +# regex for skipping tags +skip_tags = "v0.1.0-beta.1" +# regex for ignoring tags +ignore_tags = "" +# sort the tags topologically +topo_order = true +# sort the commits inside sections by oldest/newest order +sort_commits = "newest" +# limit the number of commits included in the changelog. +# limit_commits = 42