Skip to content

Commit

Permalink
Merge pull request #5 from rezozero/upgrade_deps
Browse files Browse the repository at this point in the history
feat: Upgraded to PHP 7.4 min, use strict_types, upgraded dev dependencies, removed useless phpdocs
  • Loading branch information
ambroisemaupate authored Dec 2, 2024
2 parents c6cfa3e + c30f5a9 commit 96b407f
Show file tree
Hide file tree
Showing 23 changed files with 219 additions and 67 deletions.
43 changes: 43 additions & 0 deletions .github/workflows/run-test.yml
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 18 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

$finder = (new PhpCsFixer\Finder())
->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)
;
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

11 changes: 11 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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))

<!-- generated by git-cliff -->
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -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
Expand Down
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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.

Expand Down
112 changes: 112 additions & 0 deletions cliff.toml
Original file line number Diff line number Diff line change
@@ -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") }}](<REPO>/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="") }}](<REPO>/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="") }}](<REPO>/commit/{{ commit.id }}))
{% endif -%}
{% endfor -%}
{% endfor %}\n
"""
# remove the leading and trailing whitespace from the template
trim = true
# changelog footer
footer = """
<!-- generated by git-cliff -->
"""
# postprocessors
postprocessors = [
{ pattern = '<REPO>', 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}](<REPO>/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
10 changes: 5 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand All @@ -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"
}
}
15 changes: 0 additions & 15 deletions phpcs.xml.dist

This file was deleted.

3 changes: 2 additions & 1 deletion phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,6 @@ parameters:
level: max
paths:
- src
ignoreErrors:
- identifier: missingType.iterableValue
reportUnmatchedIgnoredErrors: false
checkMissingIterableValueType: false
13 changes: 3 additions & 10 deletions src/EmailCanonizer.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace RZ\CanonicalEmail;
Expand All @@ -7,14 +8,9 @@

class EmailCanonizer implements CanonizeStrategy
{
/**
* @var array
*/
private $strategies = [];
private array $strategies = [];

/**
* EmailCanonizer constructor.
*
* @param array $strategies
*/
public function __construct(array $strategies)
Expand All @@ -24,10 +20,7 @@ public function __construct(array $strategies)

public function supportsEmailAddress(string $emailAddress): bool
{
if (filter_var($emailAddress, FILTER_VALIDATE_EMAIL)) {
return true;
}
return false;
return false !== filter_var($emailAddress, FILTER_VALIDATE_EMAIL);
}

public function getCanonicalEmailAddress(string $emailAddress): string
Expand Down
5 changes: 3 additions & 2 deletions src/Exception/EmailNotSupported.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace RZ\CanonicalEmail\Exception;
Expand All @@ -12,7 +13,7 @@ class EmailNotSupported extends \InvalidArgumentException
* @param int $code
* @param Throwable|null $previous
*/
final public function __construct($message = "", $code = 0, Throwable $previous = null)
final public function __construct(string $message = "", int $code = 0, ?Throwable $previous = null)
{
parent::__construct($message, $code, $previous);
}
Expand All @@ -23,7 +24,7 @@ final public function __construct($message = "", $code = 0, Throwable $previous
*
* @return static
*/
public static function fromEmailAddressAndStrategy(string $emailAddress, string $strategyClass)
public static function fromEmailAddressAndStrategy(string $emailAddress, string $strategyClass): EmailNotSupported
{
return new static(sprintf('Email %s is not supported by %s strategy.', $emailAddress, $strategyClass));
}
Expand Down
1 change: 1 addition & 0 deletions src/Strategy/CanonizeStrategy.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace RZ\CanonicalEmail\Strategy;
Expand Down
12 changes: 4 additions & 8 deletions src/Strategy/GSuiteStrategy.php
Original file line number Diff line number Diff line change
@@ -1,23 +1,19 @@
<?php

declare(strict_types=1);

namespace RZ\CanonicalEmail\Strategy;

use Assert\Assert;
use Assert\AssertionFailedException;
use RZ\CanonicalEmail\Exception\EmailNotSupported;

/**
* Class GSuiteStrategy
*
* @package RZ\CanonicalEmail\Strategy
* @see https://support.google.com/mail/answer/10313?hl=fr
*/
class GSuiteStrategy implements CanonizeStrategy
{
/**
* @var array
*/
private static $googleMxHosts = [
private static array $googleMxHosts = [
'aspmx.l.google.com',
'aspmx2.googlemail.com',
'aspmx3.googlemail.com',
Expand Down Expand Up @@ -60,7 +56,7 @@ private function areMailExchangesFromGoogle(string $emailAddress): bool
$domain = $emailAddress[1];
if (getmxrr($domain, $mxHosts) === true) {
Assert::that($mxHosts)->minCount(1);
Assert::thatAll($mxHosts)->inArray(static::$googleMxHosts);
Assert::thatAll($mxHosts)->inArray(self::$googleMxHosts);
return true;
}
return false;
Expand Down
Loading

0 comments on commit 96b407f

Please sign in to comment.