Skip to content

Commit

Permalink
Fix errors specified by PHPStorm
Browse files Browse the repository at this point in the history
  • Loading branch information
Aaron Suarez committed Oct 12, 2018
1 parent 9198e34 commit 41375f1
Show file tree
Hide file tree
Showing 27 changed files with 398 additions and 79 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
*.tmproj
composer.lock
vendor
composer.phar
composer.phar
.idea
1 change: 1 addition & 0 deletions lib/recurly/addon.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* @property string $revenue_schedule_type Optional field for setting a revenue schedule type. This will determine how revenue for the associated Plan should be recognized. When creating a Plan, if you supply an end_date and end_date available schedule types are never, evenly, at_range_start, or at_range_end.
* @property DateTime $created_at The date and time the add-on was created.
* @property DateTime $updated_at The date and time the add-on was last updated.
* @property string $plan_code Unique code to identify the plan.
*/
class Recurly_Addon extends Recurly_Resource
{
Expand Down
12 changes: 12 additions & 0 deletions lib/recurly/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ abstract class Recurly_Base
protected $_type;
protected $_client;
protected $_links;
protected $_values;
protected $_errors;

public function __construct($href = null, $client = null)
{
Expand All @@ -18,6 +20,8 @@ public function __construct($href = null, $client = null)
* Request the URI, validate the response and return the object.
* @param string Resource URI, if not fully qualified, the base URL will be prepended
* @param string Optional client for the request, useful for mocking the client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
public static function _get($uri, $client = null)
{
Expand All @@ -33,6 +37,7 @@ public static function _get($uri, $client = null)
* Send a HEAD request to the URI, validate the response and return the headers.
* @param string Resource URI, if not fully qualified, the base URL will be prepended
* @param string Optional client for the request, useful for mocking the client
* @throws Recurly_Error
*/
public static function _head($uri, $client = null)
{
Expand All @@ -49,6 +54,8 @@ public static function _head($uri, $client = null)
* @param string Resource URI, if not fully qualified, the base URL will be prepended
* @param string Data to post to the URI
* @param string Optional client for the request, useful for mocking the client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
protected static function _post($uri, $data = null, $client = null)
{
Expand All @@ -66,6 +73,8 @@ protected static function _post($uri, $data = null, $client = null)
* Put to the URI, validate the response and return the object.
* @param string Resource URI, if not fully qualified, the base URL will be prepended
* @param string Optional client for the request, useful for mocking the client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
protected static function _put($uri, $client = null)
{
Expand All @@ -74,6 +83,7 @@ protected static function _put($uri, $client = null)
}
$response = $client->request(Recurly_Client::PUT, $uri);
$response->assertValidResponse();
$object = null;
if ($response->body) {
$object = Recurly_Base::__parseResponseToNewObject($response, $uri, $client);
}
Expand All @@ -85,6 +95,8 @@ protected static function _put($uri, $client = null)
* Delete the URI, validate the response and return the object.
* @param string Resource URI, if not fully qualified, the base URL will be appended
* @param string Optional client for the request, useful for mocking the client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
protected static function _delete($uri, $client = null)
{
Expand Down
24 changes: 23 additions & 1 deletion lib/recurly/billing_info.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
* @property string $phone Phone number
* @property string $company Customer's company
* @property string $vat_number Customer's VAT Number
* @property string $currency Currency in which invoices will be posted. Only applicable if this account is enrolled in a plan has a different currency than your site's default.
* @property string $verification_value Security code or CVV, 3-4 digits STRONGLY RECOMMENDED
* @property string $ip_address Customer's IP address when updating their Billing Information STRONGLY RECOMMENDED
* @property string $external_hpp_type Used to indicate payment made out of band via an external service (e.g. Adyen HPP).
Expand All @@ -28,24 +27,47 @@
*/
class Recurly_BillingInfo extends Recurly_Resource
{
/**
* @param string $accountCode The account code
* @param Recurly_Client $client The recurly client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
public static function get($accountCode, $client = null) {
return Recurly_Base::_get(Recurly_BillingInfo::uriForBillingInfo($accountCode), $client);
}

public function create() {
$this->update();
}

/**
* @throws Recurly_Error
*/
public function update() {
$this->_save(Recurly_Client::PUT, $this->uri());
}

/**
* @throws Recurly_Error
*/
public function delete() {
return Recurly_Base::_delete($this->uri(), $this->_client);
}

/**
* @param string $accountCode The account code
* @param Recurly_Client $client The recurly client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
public static function deleteForAccount($accountCode, $client = null) {
return Recurly_Base::_delete(Recurly_BillingInfo::uriForBillingInfo($accountCode), $client);
}

/**
* @throws Recurly_Error
*/
protected function uri() {
if (!empty($this->_href))
return $this->getHref();
Expand Down
32 changes: 24 additions & 8 deletions lib/recurly/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,13 @@ function __construct($apiKey = null, $acceptLanguage = 'en-US') {
$this->_acceptLanguage = $acceptLanguage;
}

/**
* @param string $method The HTTP method
* @param string $uri The URI
* @param string $data XML string to post to the URI
* @return Recurly_ClientResponse
* @throws Recurly_Error
*/
public function request($method, $uri, $data = null)
{
return $this->_sendRequest($method, $uri, $data);
Expand All @@ -103,14 +110,16 @@ public function apiKey() {
}

/**
* Sends an HTTP request to the Recurly API
*
* @param string $method Specifies the HTTP method to be used for this request
* @param string $uri Target URI for this request (relative to the API root)
* @param mixed $data x-www-form-urlencoded data (or array) to be sent in a POST request body
*
* @return $code, $response
*/
* Sends an HTTP request to the Recurly API
*
* @param string $method Specifies the HTTP method to be used for this request
* @param string $uri Target URI for this request (relative to the API root)
* @param mixed $data x-www-form-urlencoded data (or array) to be sent in a POST request body
*
* @return Recurly_ClientResponse
*
* @throws Recurly_Error
*/
private function _sendRequest($method, $uri, $data = '')
{
if(function_exists('mb_internal_encoding'))
Expand Down Expand Up @@ -200,6 +209,11 @@ private function _getHeaders($headerText)
return $returnHeaders;
}

/**
* @param int $errorNumber The curl error number
* @param string $message The error message
* @throws Recurly_Error
*/
private function _raiseCurlError($errorNumber, $message)
{
switch ($errorNumber) {
Expand All @@ -220,6 +234,7 @@ private function _raiseCurlError($errorNumber, $message)
*
* @param string $uri Target URI for the request (complete URL)
* @param resource $file_pointer Resourced returned from fopen() with write mode.
* @throws Recurly_Error
*/
public function getFile($uri, $file_pointer) {
$ch = curl_init();
Expand Down Expand Up @@ -254,6 +269,7 @@ public function getFile($uri, $file_pointer) {
* @param string $uri Target URI for this request (relative to the API root)
* @param string $locale Locale for the PDF invoice (e.g. "en-GB", "en-US", "fr")
* @return string $response PDF document
* @throws Recurly_Error
*/
public function getPdf($uri, $locale = null)
{
Expand Down
32 changes: 32 additions & 0 deletions lib/recurly/coupon.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
* @property DateTime $created_at The date and time the coupon was created.
* @property DateTime $updated_at The date and time the coupon was last updated.
* @property DateTime $deleted_at The date and time the coupon was deleted.
* @property string $state The state of coupons to return: redeemable, expired, maxed_out, or inactive.
*/
class Recurly_Coupon extends Recurly_Resource
{
Expand All @@ -38,6 +39,12 @@ function __construct($href = null, $client = null) {
$this->discount_in_cents = new Recurly_CurrencyList('discount_in_cents');
}

/**
* @param string $couponCode The coupon code
* @param Recurly_Client $client The recurly client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
public static function get($couponCode, $client = null) {
return Recurly_Base::_get(Recurly_Coupon::uriForCoupon($couponCode), $client);
}
Expand All @@ -46,6 +53,13 @@ public function create() {
$this->_save(Recurly_Client::POST, Recurly_Client::PATH_COUPONS);
}

/**
* @param string $accountCode The account code
* @param string $currency The currency of
* @param string $subscriptionUUID The UUID of the subscription
* @return Recurly_CouponRedemption
* @throws Recurly_Error
*/
public function redeemCoupon($accountCode, $currency, $subscriptionUUID = null) {
if ($this->state != 'redeemable') {
throw new Recurly_Error('Coupon is not redeemable.');
Expand All @@ -62,6 +76,8 @@ public function redeemCoupon($accountCode, $currency, $subscriptionUUID = null)
return $redemption;
}
}

return null;
}

public function update() {
Expand All @@ -72,9 +88,20 @@ public function restore() {
$this->_save(Recurly_Client::PUT, $this->uri() . '/restore', $this->createUpdateXML());
}

/**
* @return object
* @throws Recurly_Error
*/
public function delete() {
return Recurly_Base::_delete($this->uri(), $this->_client);
}

/**
* @param string $couponCode The coupon code
* @param Recurly_Client $client The recurly client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
public static function deleteCoupon($couponCode, $client = null) {
return Recurly_Base::_delete(Recurly_Coupon::uriForCoupon($couponCode), $client);
}
Expand All @@ -99,6 +126,11 @@ public function createUpdateXML() {
return $this->renderXML($doc);
}

/**
* @param int $number Number of unique codes to generate
* @return array
* @throws Recurly_Error
*/
public function generate($number) {
$doc = $this->createDocument();

Expand Down
2 changes: 2 additions & 0 deletions lib/recurly/custom_field.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

/**
* An name/value pair.
* @property string $name The name of the custom field
* @property string $value The value of the custom field
*/
class Recurly_CustomField extends Recurly_Resource
{
Expand Down
5 changes: 5 additions & 0 deletions lib/recurly/custom_field_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@
// values are used to clear a value.
class Recurly_CustomFieldList extends ArrayObject
{
/**
* @param mixed $index
* @param object $value Must be instance of Recurly_CustomField
* @throws Exception
*/
public function offsetSet($index, $value) {
if (!$value instanceof Recurly_CustomField) {
throw new Exception("value must be an instance of Recurly_CustomField");
Expand Down
3 changes: 3 additions & 0 deletions lib/recurly/export_date_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ class Recurly_ExportDateList extends Recurly_Pager
{
/**
* Fetch a list of dates that have exports.
* @param array $params An array of parameters to include with the request
* @param Recurly_Client $client The recurly client
* @return Recurly_ExportDateList
*/
public static function get($params = null, $client = null) {
return new self(self::_uriWithParams('/export_dates', $params), $client);
Expand Down
5 changes: 4 additions & 1 deletion lib/recurly/export_file.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@ class Recurly_ExportFile extends Recurly_Resource
* Look up a file by date and name.
* @param string date
* @param string name
* @return Recurly_ExportFile
* @param Recurly_Client $client
* @return object Recurly_ExportFile
* @throws Recurly_Error
*/
public static function get($date, $name, $client = null) {
return self::_get('/export_dates/' . rawurlencode($date) . '/export_files/' . rawurlencode($name), $client);
Expand All @@ -24,6 +26,7 @@ protected function getWriteableAttributes() {
* Download the file.
*
* @param resource $file_pointer Resourced returned from fopen() with write mode.
* @throws Recurly_Error
*/
function download($file_pointer) {
if (empty($this->download_url)) {
Expand Down
2 changes: 2 additions & 0 deletions lib/recurly/export_file_list.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ class Recurly_ExportFileList extends Recurly_Pager
* Fetch a list of export files for a given date.
*
* @param string $date Date in YYYY-MM-DD format.
* @param array $params An array of parameters to include with the request
* @param Recurly_Client $client The recurly client
* @return Recurly_ExportFileList
*/
public static function get($date, $params = null, $client = null) {
Expand Down
11 changes: 10 additions & 1 deletion lib/recurly/gift_card.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,22 @@ class Recurly_GiftCard extends Recurly_Resource
{
/**
* Get a gift card by the id
*
* @param string $giftCardId The gift card ID
* @param Recurly_Client $client The recurly client
* @return object Recurly_Resource or null
* @throws Recurly_Error
*/
public static function get($giftCardId, $client = null) {
return Recurly_Base::_get(Recurly_GiftCard::uriForGiftCard($giftCardId), $client);
}

/**
* Redeem a gift card given an account code
*
* @param string $accountCode The account code
*
* @throws Recurly_Error
*/
public function redeem($accountCode) {
$doc = $this->createDocument();
Expand All @@ -48,7 +57,7 @@ public function create() {
* Preview the creation and check for errors.
*
* Note: once preview() has been called you will not be able to call create()
* without reassiging all the attributes.
* without reassigning all the attributes.
*/
public function preview() {
$this->_save(Recurly_Client::POST, Recurly_Client::PATH_GIFT_CARDS . '/preview');
Expand Down
Loading

0 comments on commit 41375f1

Please sign in to comment.