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

Commit

Permalink
Moves magic getter to trait
Browse files Browse the repository at this point in the history
  • Loading branch information
Craig Paul committed Oct 19, 2016
1 parent 2ae5925 commit 4469fbe
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 34 deletions.
23 changes: 23 additions & 0 deletions src/Gettable.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace CraigPaul\Moneris;

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

throw new \InvalidArgumentException('['.get_class($this).'] does not contain a property named ['.$property.']');
}
}
36 changes: 2 additions & 34 deletions src/Moneris.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,10 @@
*/
class Moneris
{
/**
* The live Moneris API.
*
* @var string
*/
const ENV_LIVE = 'live';
use Gettable;

/**
* The sandbox Moneris API.
*
* @var string
*/
const ENV_LIVE = 'live';
const ENV_STAGING = 'staging';

/**
* The mocked Moneris API.
*
* @var string
*/
const ENV_TESTING = 'testing';

/**
Expand Down Expand Up @@ -101,21 +86,4 @@ public function gateway()
{
return new Gateway($this->id, $this->token, $this->environment);
}

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

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

0 comments on commit 4469fbe

Please sign in to comment.