Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 0187922

Browse files
committed
Ensure data is lowercase
1 parent 230d58d commit 0187922

7 files changed

Lines changed: 36 additions & 18 deletions

File tree

res/throwaway_domains.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
75hosting.net
2222
75hosting.org
2323
9ox.net
24-
MailEater.com
25-
TempEMail.net
24+
maileater.com
25+
tempemail.net
2626
a-bc.net
2727
ag.us.to
2828
ajaxapp.net

src/EmailChecker/Adapter/FileAdapter.php

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111

1212
namespace EmailChecker\Adapter;
1313

14+
use EmailChecker\Utilities;
15+
1416
/**
1517
* Throwaway email adapter build with file.
1618
*
@@ -29,13 +31,7 @@ public function __construct($filename)
2931
throw new \InvalidArgumentException(sprintf('File "%s" not found', $filename));
3032
}
3133

32-
$lines = explode(PHP_EOL, file_get_contents($filename));
33-
$lines = array_map('trim', $lines);
34-
$lines = array_filter($lines, function($line) {
35-
return (0 === strlen($line) || '#' === $line[0]) ? false : $line;
36-
});
37-
38-
$this->domains = $lines;
34+
$this->domains = Utilities::parseLines(file_get_contents($filename));
3935
}
4036

4137
/**

src/EmailChecker/Adapter/GaufretteAdapter.php

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace EmailChecker\Adapter;
1313

1414
use Gaufrette\File;
15+
use EmailChecker\Utilities;
1516

1617
/**
1718
* Adapter for Gaufrette filesystem abstraction layer.
@@ -27,13 +28,7 @@ class GaufretteAdapter implements AdapterInterface
2728
*/
2829
public function __construct(File $file)
2930
{
30-
$lines = explode(PHP_EOL, $file->getContent());
31-
$lines = array_map('trim', $lines);
32-
$lines = array_filter($lines, function($line) {
33-
return (0 === strlen($line) || '#' === $line[0]) ? false : $line;
34-
});
35-
36-
$this->domains = $lines;
31+
$this->domains = Utilities::parseLines($file->getContent());
3732
}
3833

3934
/**

src/EmailChecker/Utilities.php

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,30 @@ static public function parseEmailAddress($email)
3838
throw new InvalidEmailException(sprintf('"%s" is not a valid email', $email));
3939
}
4040

41-
return array($parts['local'], $parts['domain']);
41+
return array_map('strtolower', array($parts['local'], $parts['domain']));
42+
}
43+
44+
/**
45+
* Parse content and extract lines.
46+
*
47+
* @param string $content The content to parse
48+
*
49+
* @return array Array of cleaned string
50+
*/
51+
static public function parseLines($content)
52+
{
53+
// Split by line
54+
$lines = explode(PHP_EOL, $content);
55+
56+
// Trim and convert to lowercase
57+
$lines = array_map('trim', $lines);
58+
$lines = array_map('strtolower', $lines);
59+
60+
// Remove empty lines and comments
61+
$lines = array_filter($lines, function($line) {
62+
return (0 === strlen($line) || '#' === $line[0]) ? false : $line;
63+
});
64+
65+
return $lines;
4266
}
4367
}

tests/EmailChecker/Tests/Adpater/FileAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public static function throwawayDomains()
4545
array('jetable.org'),
4646
array('mailjet.org'),
4747
array('dummy-space.ext'),
48+
array('yopmail.com'),
4849
);
4950
}
5051

tests/EmailChecker/Tests/Adpater/GaufretteAdapterTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ public static function throwawayDomains()
5151
array('jetable.org'),
5252
array('mailjet.org'),
5353
array('dummy-space.ext'),
54+
array('yopmail.com'),
5455
);
5556
}
5657

tests/fixtures/throwaway_domains.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@
22
jetable.org
33
mailjet.org
44
dummy-space.ext
5-
#comment.ext
5+
#comment.ext
6+
Yopmail.com

0 commit comments

Comments
 (0)