Skip to content

Commit 6383ec9

Browse files
authored
Merge pull request #18 from daveearley/php7.4
Update to PHP 7.4
2 parents 9cc91d4 + 2a7911a commit 6383ec9

34 files changed

+72845
-71961
lines changed

.travis.yml

-15
This file was deleted.

Dockerfile

+11-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
FROM php:7.1-fpm
1+
FROM php:7.4-fpm
2+
3+
RUN curl https://getcomposer.org/installer > composer-setup.php \
4+
&& php composer-setup.php \
5+
&& mv composer.phar /usr/local/bin/composer \
6+
&& rm composer-setup.php
7+
8+
# Install git
9+
RUN apt-get update \
10+
&& apt-get -y install git \
11+
&& apt-get clean; rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/* /usr/share/doc/*
212

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

README.md

+1-14
Original file line numberDiff line numberDiff line change
@@ -118,11 +118,10 @@ The expected output will be:
118118
```
119119

120120
## Running in Docker
121-
You can easily validate over HTTP using docker. To get docker working run
122121
```bash
123122
docker-compose up -d
124123
```
125-
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.
124+
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.
126125

127126
## Adding a custom data source
128127

@@ -139,33 +138,21 @@ namespace EmailValidation;
139138

140139
class CustomEmailDataProvider implements EmailDataProviderInterface
141140
{
142-
/**
143-
* {@inheritdoc}
144-
*/
145141
public function getEmailProviders(): array
146142
{
147143
return ['custom.com'];
148144
}
149145

150-
/**
151-
* {@inheritdoc}
152-
*/
153146
public function getTopLevelDomains(): array
154147
{
155148
return ['custom'];
156149
}
157150

158-
/**
159-
* {@inheritdoc}
160-
*/
161151
public function getDisposableEmailProviders(): array
162152
{
163153
return ['custom.com', 'another.com'];
164154
}
165155

166-
/**
167-
* {@inheritdoc}
168-
*/
169156
public function getRoleEmailPrefixes(): array
170157
{
171158
return ['custom'];

composer.json

+14-5
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,32 @@
1010
"disposable email check"
1111
],
1212
"require": {
13-
"php": "^7.0"
13+
"php": "^7.4",
14+
"ext-json": "*"
1415
},
1516
"require-dev": {
16-
"mockery/mockery": "^0.9.9",
17-
"phpunit/phpunit": "^6.2"
17+
"mockery/mockery": "dev-master",
18+
"phpunit/phpunit": "^9.0"
1819
},
1920
"license": "MIT",
2021
"autoload": {
2122
"psr-4": {
2223
"EmailValidation\\": "src/",
23-
"EmailValidation\\Tests\\": "src/tests"
24+
"EmailValidation\\Tests\\": "tests"
2425
}
2526
},
2627
"authors": [
2728
{
2829
"name": "Dave Earley",
2930
"email": "dave@earley.email"
3031
}
31-
]
32+
],
33+
"scripts": {
34+
"update-data-files": [
35+
"(cd scripts && ./update-disposable-email-providers.php)",
36+
"(cd scripts && ./update-top-level-domains.php)"
37+
],
38+
"post-install-cmd": "@update-data-files",
39+
"post-update-cmd": "@update-data-files"
40+
}
3241
}

phpunit.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
colors="true"
99
beStrictAboutTodoAnnotatedTests="true"
1010
verbose="true">
11-
<testsuite>
11+
<testsuite name="Email Validation Test Suite">
1212
<directory suffix="Test.php">tests</directory>
1313
</testsuite>
1414

src/EmailAddress.php

+17-40
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,17 @@
66

77
class EmailAddress
88
{
9-
const EMAIL_NAME_PART = 0;
10-
const EMAIL_HOST_PART = 1;
9+
public const EMAIL_NAME_PART = 0;
10+
public const EMAIL_HOST_PART = 1;
1111

12-
/** @var string */
13-
private $emailAddress;
12+
private string $emailAddress;
1413

15-
/**
16-
* @param string $emailAddress
17-
*/
1814
public function __construct(string $emailAddress)
1915
{
2016
$this->emailAddress = $emailAddress;
2117
}
2218

23-
/**
24-
* @return mixed
25-
*/
26-
public function getNamePart()
19+
public function getNamePart(): ?string
2720
{
2821
if ($this->isValidEmailAddressFormat()) {
2922
return $this->getEmailPart(self::EMAIL_NAME_PART);
@@ -32,10 +25,17 @@ public function getNamePart()
3225
return null;
3326
}
3427

35-
/**
36-
* @return mixed
37-
*/
38-
public function getHostPart()
28+
public function isValidEmailAddressFormat(): bool
29+
{
30+
return filter_var($this->emailAddress, FILTER_VALIDATE_EMAIL) !== false;
31+
}
32+
33+
private function getEmailPart(int $partNumber): string
34+
{
35+
return (explode('@', $this->emailAddress))[$partNumber];
36+
}
37+
38+
public function getHostPart(): ?string
3939
{
4040
if ($this->isValidEmailAddressFormat()) {
4141
return $this->getEmailPart(self::EMAIL_HOST_PART);
@@ -44,10 +44,7 @@ public function getHostPart()
4444
return null;
4545
}
4646

47-
/**
48-
* @return string|null
49-
*/
50-
public function getTopLevelDomainPart()
47+
public function getTopLevelDomainPart(): ?string
5148
{
5249
if ($this->isValidEmailAddressFormat()) {
5350
return explode('.', $this->getEmailPart(self::EMAIL_HOST_PART))[1];
@@ -56,28 +53,8 @@ public function getTopLevelDomainPart()
5653
return null;
5754
}
5855

59-
/**
60-
* @return bool
61-
*/
62-
public function isValidEmailAddressFormat(): bool
63-
{
64-
return filter_var($this->emailAddress, FILTER_VALIDATE_EMAIL) !== false;
65-
}
66-
67-
/**
68-
* @return string
69-
*/
7056
public function asString(): string
7157
{
72-
return (string)$this->emailAddress;
73-
}
74-
75-
/**
76-
* @param int $partNumber
77-
* @return mixed
78-
*/
79-
private function getEmailPart(int $partNumber)
80-
{
81-
return (explode('@', $this->emailAddress))[$partNumber];
58+
return $this->emailAddress;
8259
}
8360
}

src/EmailDataProvider.php

+4-16
Original file line numberDiff line numberDiff line change
@@ -6,38 +6,26 @@
66

77
class EmailDataProvider implements EmailDataProviderInterface
88
{
9-
const EMAIL_PROVIDERS = __DIR__ . '/data/email-providers.php';
10-
const TOP_LEVEL_DOMAINS = __DIR__ . '/data/top-level-domains.php';
11-
const DISPOSABLE_EMAIL_PROVIDERS = __DIR__ . '/data/disposable-email-providers.php';
12-
const ROLE_BASED_EMAIL_PREFIXES = __DIR__ . '/data/role-based-email-prefixes.php';
9+
private const EMAIL_PROVIDERS = __DIR__ . '/data/email-providers.php';
10+
private const TOP_LEVEL_DOMAINS = __DIR__ . '/data/top-level-domains.php';
11+
private const DISPOSABLE_EMAIL_PROVIDERS = __DIR__ . '/data/disposable-email-providers.php';
12+
private const ROLE_BASED_EMAIL_PREFIXES = __DIR__ . '/data/role-based-email-prefixes.php';
1313

14-
/**
15-
* {@inheritdoc}
16-
*/
1714
public function getEmailProviders(): array
1815
{
1916
return include self::EMAIL_PROVIDERS;
2017
}
2118

22-
/**
23-
* {@inheritdoc}
24-
*/
2519
public function getTopLevelDomains(): array
2620
{
2721
return include self::TOP_LEVEL_DOMAINS;
2822
}
2923

30-
/**
31-
* {@inheritdoc}
32-
*/
3324
public function getDisposableEmailProviders(): array
3425
{
3526
return include self::DISPOSABLE_EMAIL_PROVIDERS;
3627
}
3728

38-
/**
39-
* {@inheritdoc}
40-
*/
4129
public function getRoleEmailPrefixes(): array
4230
{
4331
return include self::ROLE_BASED_EMAIL_PREFIXES;

src/EmailDataProviderInterface.php

-12
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,11 @@
44

55
interface EmailDataProviderInterface
66
{
7-
/**
8-
* @return array
9-
*/
107
public function getEmailProviders(): array;
118

12-
/**
13-
* @return array
14-
*/
159
public function getTopLevelDomains(): array;
1610

17-
/**
18-
* @return array
19-
*/
2011
public function getDisposableEmailProviders(): array;
2112

22-
/**
23-
* @return array
24-
*/
2513
public function getRoleEmailPrefixes(): array;
2614
}

0 commit comments

Comments
 (0)