Skip to content

Commit

Permalink
Merge pull request #18 from daveearley/php7.4
Browse files Browse the repository at this point in the history
Update to PHP 7.4
  • Loading branch information
daveearley authored Jun 1, 2020
2 parents 9cc91d4 + 2a7911a commit 6383ec9
Show file tree
Hide file tree
Showing 34 changed files with 72,845 additions and 71,961 deletions.
15 changes: 0 additions & 15 deletions .travis.yml

This file was deleted.

13 changes: 11 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
FROM php:7.1-fpm
FROM php:7.4-fpm

RUN curl https://getcomposer.org/installer > composer-setup.php \
&& php composer-setup.php \
&& mv composer.phar /usr/local/bin/composer \
&& rm composer-setup.php

# Install git
RUN apt-get update \
&& apt-get -y install git \
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*

RUN curl https://getcomposer.org/installer > composer-setup.php && php composer-setup.php && mv composer.phar /usr/local/bin/composer && rm composer-setup.php
WORKDIR /web
ADD . /web

Expand Down
15 changes: 1 addition & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -118,11 +118,10 @@ The expected output will be:
```

## Running in Docker
You can easily validate over HTTP using docker. To get docker working run
```bash
docker-compose up -d
```
in the repository root. You can then validate an email by navigating to http://localhost:8880?email=email.to.validate@example.com. The result will be JSON string as per above.
You can then validate an email by navigating to http://localhost:8880?email=email.to.validate@example.com. The result will be JSON string as per above.

## Adding a custom data source

Expand All @@ -139,33 +138,21 @@ namespace EmailValidation;

class CustomEmailDataProvider implements EmailDataProviderInterface
{
/**
* {@inheritdoc}
*/
public function getEmailProviders(): array
{
return ['custom.com'];
}

/**
* {@inheritdoc}
*/
public function getTopLevelDomains(): array
{
return ['custom'];
}

/**
* {@inheritdoc}
*/
public function getDisposableEmailProviders(): array
{
return ['custom.com', 'another.com'];
}

/**
* {@inheritdoc}
*/
public function getRoleEmailPrefixes(): array
{
return ['custom'];
Expand Down
19 changes: 14 additions & 5 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,32 @@
"disposable email check"
],
"require": {
"php": "^7.0"
"php": "^7.4",
"ext-json": "*"
},
"require-dev": {
"mockery/mockery": "^0.9.9",
"phpunit/phpunit": "^6.2"
"mockery/mockery": "dev-master",
"phpunit/phpunit": "^9.0"
},
"license": "MIT",
"autoload": {
"psr-4": {
"EmailValidation\\": "src/",
"EmailValidation\\Tests\\": "src/tests"
"EmailValidation\\Tests\\": "tests"
}
},
"authors": [
{
"name": "Dave Earley",
"email": "dave@earley.email"
}
]
],
"scripts": {
"update-data-files": [
"(cd scripts && ./update-disposable-email-providers.php)",
"(cd scripts && ./update-top-level-domains.php)"
],
"post-install-cmd": "@update-data-files",
"post-update-cmd": "@update-data-files"
}
}
2 changes: 1 addition & 1 deletion phpunit.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
colors="true"
beStrictAboutTodoAnnotatedTests="true"
verbose="true">
<testsuite>
<testsuite name="Email Validation Test Suite">
<directory suffix="Test.php">tests</directory>
</testsuite>

Expand Down
57 changes: 17 additions & 40 deletions src/EmailAddress.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,17 @@

class EmailAddress
{
const EMAIL_NAME_PART = 0;
const EMAIL_HOST_PART = 1;
public const EMAIL_NAME_PART = 0;
public const EMAIL_HOST_PART = 1;

/** @var string */
private $emailAddress;
private string $emailAddress;

/**
* @param string $emailAddress
*/
public function __construct(string $emailAddress)
{
$this->emailAddress = $emailAddress;
}

/**
* @return mixed
*/
public function getNamePart()
public function getNamePart(): ?string
{
if ($this->isValidEmailAddressFormat()) {
return $this->getEmailPart(self::EMAIL_NAME_PART);
Expand All @@ -32,10 +25,17 @@ public function getNamePart()
return null;
}

/**
* @return mixed
*/
public function getHostPart()
public function isValidEmailAddressFormat(): bool
{
return filter_var($this->emailAddress, FILTER_VALIDATE_EMAIL) !== false;
}

private function getEmailPart(int $partNumber): string
{
return (explode('@', $this->emailAddress))[$partNumber];
}

public function getHostPart(): ?string
{
if ($this->isValidEmailAddressFormat()) {
return $this->getEmailPart(self::EMAIL_HOST_PART);
Expand All @@ -44,10 +44,7 @@ public function getHostPart()
return null;
}

/**
* @return string|null
*/
public function getTopLevelDomainPart()
public function getTopLevelDomainPart(): ?string
{
if ($this->isValidEmailAddressFormat()) {
return explode('.', $this->getEmailPart(self::EMAIL_HOST_PART))[1];
Expand All @@ -56,28 +53,8 @@ public function getTopLevelDomainPart()
return null;
}

/**
* @return bool
*/
public function isValidEmailAddressFormat(): bool
{
return filter_var($this->emailAddress, FILTER_VALIDATE_EMAIL) !== false;
}

/**
* @return string
*/
public function asString(): string
{
return (string)$this->emailAddress;
}

/**
* @param int $partNumber
* @return mixed
*/
private function getEmailPart(int $partNumber)
{
return (explode('@', $this->emailAddress))[$partNumber];
return $this->emailAddress;
}
}
20 changes: 4 additions & 16 deletions src/EmailDataProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,38 +6,26 @@

class EmailDataProvider implements EmailDataProviderInterface
{
const EMAIL_PROVIDERS = __DIR__ . '/data/email-providers.php';
const TOP_LEVEL_DOMAINS = __DIR__ . '/data/top-level-domains.php';
const DISPOSABLE_EMAIL_PROVIDERS = __DIR__ . '/data/disposable-email-providers.php';
const ROLE_BASED_EMAIL_PREFIXES = __DIR__ . '/data/role-based-email-prefixes.php';
private const EMAIL_PROVIDERS = __DIR__ . '/data/email-providers.php';
private const TOP_LEVEL_DOMAINS = __DIR__ . '/data/top-level-domains.php';
private const DISPOSABLE_EMAIL_PROVIDERS = __DIR__ . '/data/disposable-email-providers.php';
private const ROLE_BASED_EMAIL_PREFIXES = __DIR__ . '/data/role-based-email-prefixes.php';

/**
* {@inheritdoc}
*/
public function getEmailProviders(): array
{
return include self::EMAIL_PROVIDERS;
}

/**
* {@inheritdoc}
*/
public function getTopLevelDomains(): array
{
return include self::TOP_LEVEL_DOMAINS;
}

/**
* {@inheritdoc}
*/
public function getDisposableEmailProviders(): array
{
return include self::DISPOSABLE_EMAIL_PROVIDERS;
}

/**
* {@inheritdoc}
*/
public function getRoleEmailPrefixes(): array
{
return include self::ROLE_BASED_EMAIL_PREFIXES;
Expand Down
12 changes: 0 additions & 12 deletions src/EmailDataProviderInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,11 @@

interface EmailDataProviderInterface
{
/**
* @return array
*/
public function getEmailProviders(): array;

/**
* @return array
*/
public function getTopLevelDomains(): array;

/**
* @return array
*/
public function getDisposableEmailProviders(): array;

/**
* @return array
*/
public function getRoleEmailPrefixes(): array;
}
Loading

0 comments on commit 6383ec9

Please sign in to comment.