mirror of
https://github.com/elyby/php-tempmailbuster.git
synced 2024-11-23 05:32:58 +05:30
Removed redundant feature from AntiTempmailRepo class
This commit is contained in:
parent
3131ece3b3
commit
676d2bee6d
@ -10,24 +10,25 @@ use Exception;
|
||||
class AntiTempmailRepo implements LoaderInterface
|
||||
{
|
||||
/**
|
||||
* @var array with custom paths to find data file
|
||||
* File path array to data repository.
|
||||
*
|
||||
* Default paths are used in following cases:
|
||||
* 1. if this library and data repository are included in project as composer dependencies;
|
||||
* 2. if this library is deployed for development (data repository included as composer dependency to this library).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
private $customPaths;
|
||||
|
||||
/**
|
||||
* @param array $customPaths
|
||||
*/
|
||||
public function __construct(array $customPaths = [])
|
||||
{
|
||||
$this->customPaths = $customPaths;
|
||||
}
|
||||
private $searchPaths = [
|
||||
__DIR__ . '/../../../anti-tempmail-repo/data.json',
|
||||
__DIR__ . '/../../vendor/ely/anti-tempmail-repo/data.json',
|
||||
];
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function load()
|
||||
{
|
||||
$paths = $this->getPaths();
|
||||
$paths = $this->getSearchPaths();
|
||||
$dataPath = null;
|
||||
foreach($paths as $path) {
|
||||
if (file_exists($path)) {
|
||||
@ -49,19 +50,18 @@ class AntiTempmailRepo implements LoaderInterface
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates file path array to data repository.
|
||||
*
|
||||
* Default paths are used in following cases:
|
||||
* 1. if this library and data repository are included in project as composer dependencies;
|
||||
* 2. if this library is deployed for development (data repository included as composer dependency to this library).
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
protected function getPaths()
|
||||
public function getSearchPaths()
|
||||
{
|
||||
return array_merge($this->customPaths, [
|
||||
__DIR__ . '/../../../anti-tempmail-repo/data.json',
|
||||
__DIR__ . '/../../vendor/ely/anti-tempmail-repo/data.json',
|
||||
]);
|
||||
return $this->searchPaths;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array|string $path
|
||||
*/
|
||||
public function setSearchPaths($path)
|
||||
{
|
||||
$this->searchPaths = (array)$path;
|
||||
}
|
||||
}
|
||||
|
@ -22,11 +22,32 @@ class AntiTempmailRepoTest extends \PHPUnit_Framework_TestCase
|
||||
$loader = new AntiTempmailRepoWithInvalidJson();
|
||||
$loader->load();
|
||||
}
|
||||
|
||||
public function testGetSearchPaths()
|
||||
{
|
||||
$loader = new AntiTempmailRepo();
|
||||
$this->assertTrue(is_array($loader->getSearchPaths()));
|
||||
}
|
||||
|
||||
public function testSetSearchPaths()
|
||||
{
|
||||
$path = __DIR__ . '/test.json';
|
||||
|
||||
$loader = new AntiTempmailRepo();
|
||||
$loader->setSearchPaths([$path]);
|
||||
$this->assertTrue(is_array($loader->getSearchPaths()));
|
||||
$this->assertEquals([$path], $loader->getSearchPaths());
|
||||
|
||||
$loader = new AntiTempmailRepo();
|
||||
$loader->setSearchPaths($path);
|
||||
$this->assertTrue(is_array($loader->getSearchPaths()));
|
||||
$this->assertEquals([$path], $loader->getSearchPaths());
|
||||
}
|
||||
}
|
||||
|
||||
class AntiTempmailRepoWithWrongPaths extends AntiTempmailRepo
|
||||
{
|
||||
protected function getPaths()
|
||||
public function getSearchPaths()
|
||||
{
|
||||
return [
|
||||
__DIR__ . '/virtual_reality.json',
|
||||
@ -36,7 +57,7 @@ class AntiTempmailRepoWithWrongPaths extends AntiTempmailRepo
|
||||
|
||||
class AntiTempmailRepoWithInvalidJson extends AntiTempmailRepo
|
||||
{
|
||||
protected function getPaths()
|
||||
public function getSearchPaths()
|
||||
{
|
||||
return [
|
||||
__DIR__ . '/AntiTempmailRepoTest.php',
|
||||
|
Loading…
Reference in New Issue
Block a user