Skip to content
This repository has been archived by the owner on Oct 30, 2020. It is now read-only.

Commit

Permalink
Adjusts customer to use preparable instead of direct setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 26, 2016
1 parent 942b8d0 commit 85ba6e9
Showing 1 changed file with 36 additions and 33 deletions.
69 changes: 36 additions & 33 deletions src/Customer.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,42 +5,22 @@
/**
* CraigPaul\Moneris\Customer
*
* @property string|null $id
* @property string|null $email
* @property string|null $phone
* @property string|null $note
* @property array $data
* @property string $email
* @property string $id
* @property string $note
* @property string $phone
*/
class Customer
{
use Gettable, Settable;
use Gettable, Preparable, Settable;

/**
* The Customer ID.
* The Customer data.
*
* @var string
* @var array
*/
protected $id;

/**
* The Customer email.
*
* @var string
*/
protected $email;

/**
* The Customer phone.
*
* @var string
*/
protected $phone;

/**
* The Customer note.
*
* @var string
*/
protected $note;
protected $data = [];

/**
* Create a new Customer instance.
Expand All @@ -51,10 +31,12 @@ class Customer
*/
public function __construct(array $params = [])
{
$this->id = isset($params['id']) ? $params['id'] : null;
$this->email = isset($params['email']) ? $params['email'] : null;
$this->phone = isset($params['phone']) ? $params['phone'] : null;
$this->note = isset($params['note']) ? $params['note'] : null;
$this->data = $this->prepare($params, [
['property' => 'id', 'key' => 'id'],
['property' => 'email', 'key' => 'email'],
['property' => 'phone', 'key' => 'phone'],
['property' => 'note', 'key' => 'note'],
]);
}

/**
Expand All @@ -68,4 +50,25 @@ public static function create(array $params = [])
{
return new static($params);
}

/**
* Retrieve a property off of the class.
*
* @param string $property
*
* @throws \InvalidArgumentException
* @return mixed
*/
public function __get($property)
{
if (property_exists($this, $property)) {
return $this->$property;
}

if (isset($this->data[$property]) && !is_null($this->data[$property])) {
return $this->data[$property];
}

throw new \InvalidArgumentException('['.get_class($this).'] does not contain a property named ['.$property.']');
}
}

0 comments on commit 85ba6e9

Please sign in to comment.