mirror of
https://github.com/elyby/php-tempmailbuster.git
synced 2024-11-24 07:49:45 +05:30
Implemented Storage interface
This commit is contained in:
parent
9939ee72b2
commit
b2b8a0438f
@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace Ely\TempMailBuster;
|
||||
|
||||
class Storage
|
||||
class Storage implements StorageInterface
|
||||
{
|
||||
/**
|
||||
* @var array of strings, which contains masks for temp mail services
|
||||
@ -17,7 +17,7 @@ class Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* @return array with current items
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function getItems()
|
||||
{
|
||||
@ -25,20 +25,18 @@ class Storage
|
||||
}
|
||||
|
||||
/**
|
||||
* @param array $items override current items with passed values
|
||||
* @return static
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function setItems(array $items)
|
||||
public function setItems($items)
|
||||
{
|
||||
$this->items = $items;
|
||||
$this->items = (array)$items;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param string|array $items item or items, that will be merged to items
|
||||
* @return static
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function append($items)
|
||||
public function appendItems($items)
|
||||
{
|
||||
$items = (array)$items;
|
||||
$this->items = array_merge($this->items, $items);
|
||||
|
22
src/StorageInterface.php
Normal file
22
src/StorageInterface.php
Normal file
@ -0,0 +1,22 @@
|
||||
<?php
|
||||
namespace Ely\TempMailBuster;
|
||||
|
||||
interface StorageInterface
|
||||
{
|
||||
/**
|
||||
* @return array with current items
|
||||
*/
|
||||
public function getItems();
|
||||
|
||||
/**
|
||||
* @param array $items replace current items with passed values
|
||||
* @return static
|
||||
*/
|
||||
public function setItems($items);
|
||||
|
||||
/**
|
||||
* @param string|array $items item or items, that will be merged to exists array of strings
|
||||
* @return static
|
||||
*/
|
||||
public function appendItems($items);
|
||||
}
|
@ -4,11 +4,11 @@ namespace Ely\TempMailBuster;
|
||||
class TempMailBuster
|
||||
{
|
||||
/**
|
||||
* @var Storage
|
||||
* @var StorageInterface
|
||||
*/
|
||||
private $primaryStorage;
|
||||
/**
|
||||
* @var Storage|null
|
||||
* @var StorageInterface|null
|
||||
*/
|
||||
private $secondaryStorage;
|
||||
/**
|
||||
@ -17,9 +17,10 @@ class TempMailBuster
|
||||
private $isWhitelistMode = false;
|
||||
|
||||
/**
|
||||
* @param Storage $storage
|
||||
* @param StorageInterface $primaryStorage
|
||||
* @param StorageInterface|null $secondaryStorage
|
||||
*/
|
||||
public function __construct(Storage $primaryStorage, Storage $secondaryStorage = null)
|
||||
public function __construct(StorageInterface $primaryStorage, StorageInterface $secondaryStorage = null)
|
||||
{
|
||||
$this->primaryStorage = $primaryStorage;
|
||||
$this->secondaryStorage = $secondaryStorage;
|
||||
@ -62,7 +63,7 @@ class TempMailBuster
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Storage
|
||||
* @return StorageInterface
|
||||
*/
|
||||
public function getPrimaryStorage()
|
||||
{
|
||||
@ -70,17 +71,17 @@ class TempMailBuster
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Storage $primaryStorage
|
||||
* @param StorageInterface $primaryStorage
|
||||
* @return static
|
||||
*/
|
||||
public function setPrimaryStorage(Storage $primaryStorage)
|
||||
public function setPrimaryStorage(StorageInterface $primaryStorage)
|
||||
{
|
||||
$this->primaryStorage = $primaryStorage;
|
||||
return $this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Storage|null
|
||||
* @return StorageInterface|null
|
||||
*/
|
||||
public function getSecondaryStorage()
|
||||
{
|
||||
@ -88,10 +89,10 @@ class TempMailBuster
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Storage|null $secondaryStorage
|
||||
* @param StorageInterface|null $secondaryStorage
|
||||
* @return static
|
||||
*/
|
||||
public function setSecondaryStorage(Storage $secondaryStorage = null)
|
||||
public function setSecondaryStorage(StorageInterface $secondaryStorage = null)
|
||||
{
|
||||
$this->secondaryStorage = $secondaryStorage;
|
||||
return $this;
|
||||
|
@ -9,21 +9,21 @@ class StorageTest extends \PHPUnit_Framework_TestCase
|
||||
$this->assertEquals(['item'], $storage->getItems());
|
||||
}
|
||||
|
||||
public function testAppend()
|
||||
{
|
||||
$storage = new Storage(['item1']);
|
||||
$this->assertEquals($storage, $storage->append(['item2']));
|
||||
$this->assertEquals(['item1', 'item2'], $storage->getItems());
|
||||
|
||||
$storage = new Storage(['item1']);
|
||||
$this->assertEquals($storage, $storage->append('item2'));
|
||||
$this->assertEquals(['item1', 'item2'], $storage->getItems());
|
||||
}
|
||||
|
||||
public function testSetItems()
|
||||
{
|
||||
$storage = new Storage(['item1']);
|
||||
$this->assertEquals($storage, $storage->setItems(['item2']));
|
||||
$this->assertEquals(['item2'], $storage->getItems());
|
||||
}
|
||||
|
||||
public function testAppendItems()
|
||||
{
|
||||
$storage = new Storage(['item1']);
|
||||
$this->assertEquals($storage, $storage->appendItems(['item2']));
|
||||
$this->assertEquals(['item1', 'item2'], $storage->getItems());
|
||||
|
||||
$storage = new Storage(['item1']);
|
||||
$this->assertEquals($storage, $storage->appendItems('item2'));
|
||||
$this->assertEquals(['item1', 'item2'], $storage->getItems());
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user