inject logger, do not catch exceptions that should lead to termination
This commit is contained in:
@ -17,6 +17,7 @@ declare(strict_types=1);
|
||||
|
||||
namespace D3\LinkmobilityClient\RecipientsList;
|
||||
|
||||
use D3\LinkmobilityClient\Client;
|
||||
use D3\LinkmobilityClient\Exceptions\ExceptionMessages;
|
||||
use D3\LinkmobilityClient\Exceptions\RecipientException;
|
||||
use D3\LinkmobilityClient\ValueObject\Recipient;
|
||||
@ -27,11 +28,21 @@ use libphonenumber\PhoneNumberUtil;
|
||||
|
||||
class RecipientsList implements RecipientsListInterface, Iterator
|
||||
{
|
||||
/**
|
||||
* @var Client
|
||||
*/
|
||||
private $client;
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
private $recipients = [];
|
||||
|
||||
public function __construct( Client $client )
|
||||
{
|
||||
$this->setClient($client);
|
||||
}
|
||||
|
||||
public function add(Recipient $recipient) : RecipientsListInterface
|
||||
{
|
||||
$phoneUtil = PhoneNumberUtil::getInstance();
|
||||
@ -54,9 +65,13 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||
|
||||
$this->recipients[ md5( serialize( $recipient ) ) ] = $recipient;
|
||||
} catch (NumberParseException $e) {
|
||||
// var_dump($e);
|
||||
if ($this->getClient()->hasLogger()) {
|
||||
$this->getClient()->getLogger()->info($e->getMessage());
|
||||
}
|
||||
} catch (RecipientException $e) {
|
||||
// var_dump($e);
|
||||
if ($this->getClient()->hasLogger()) {
|
||||
$this->getClient()->getLogger()->info($e->getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
return $this;
|
||||
@ -119,4 +134,20 @@ class RecipientsList implements RecipientsListInterface, Iterator
|
||||
{
|
||||
return current($this->recipients) instanceof Recipient;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Client
|
||||
*/
|
||||
public function getClient(): Client
|
||||
{
|
||||
return $this->client;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Client $client
|
||||
*/
|
||||
public function setClient( Client $client )
|
||||
{
|
||||
$this->client = $client;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user