Skip to content

Commit

Permalink
Minor tidy ups
Browse files Browse the repository at this point in the history
  • Loading branch information
eileenmcnaughton committed Jan 30, 2023
1 parent e9e0a40 commit 606679e
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 42 deletions.
2 changes: 1 addition & 1 deletion CRM/Civixero/BankTransaction.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ protected function mapToAccounts($invoiceData, $accountsID) {
*
* @return bool
*/
protected function isSplitTransactions() {
protected function isSplitTransactions(): bool {
return TRUE;
}

Expand Down
17 changes: 8 additions & 9 deletions CRM/Civixero/Invoice.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,9 @@ public function pull($params) {
foreach ($invoices as $invoice) {
$save = TRUE;
// Strip out the invoice number prefix if present.
$contributionId = preg_replace("/^\Q{$prefix}\E/", '', CRM_Utils_Array::value('InvoiceNumber', $invoice));
$contributionID = preg_replace("/^\Q{$prefix}\E/", '', CRM_Utils_Array::value('InvoiceNumber', $invoice));
$params = [
'contribution_id' => $contributionId,
'contribution_id' => $contributionID,
'accounts_modified_date' => $invoice['UpdatedDateUTC'],
'plugin' => 'xero',
'accounts_invoice_id' => $invoice['InvoiceID'],
Expand All @@ -94,7 +94,7 @@ public function pull($params) {
try {
$existing = civicrm_api3('AccountInvoice', 'getsingle', [
'return' => 'id',
'contribution_id' => $contributionId,
'contribution_id' => $contributionID,
'plugin' => $this->_plugin,
]);
$params['id'] = $existing['id'];
Expand Down Expand Up @@ -160,7 +160,7 @@ public function push($params, $limit = 10) {
}
catch (CiviCRM_API3_Exception $e) {
$errors[] = E::ts('Failed to store %1 (%2)', [1 => $record['contribution_id'], 2 => $record['accounts_contact_id']])
. E::ts(' with error ') . $e->getMessage() . print_r($responseErrors, TRUE)
. E::ts(' with error ') . $e->getMessage() . print_r($responseErrors ?? [], TRUE)
. E::ts('%1 Push failed', [1 => $this->xero_entity]);
}
}
Expand Down Expand Up @@ -266,15 +266,15 @@ protected function mapToAccounts($invoiceData, $accountsID) {
*
* @return array
*/
protected function mapCancelled($contributionID, $accounts_invoice_id) {
$newInvoice = [
protected function mapCancelled(int $contributionID, int $accounts_invoice_id): array {
return [
'Invoice' => [
'InvoiceID' => $accounts_invoice_id,
'InvoiceNumber' => $contributionID,
'Type' => 'ACCREC',
'Reference' => 'Cancelled',
'Date' => date('Y-m-d', strtotime('now')),
'DueDate' => date('Y-m-d', strtotime('now')),
'Date' => date('Y-m-d'),
'DueDate' => date('Y-m-d'),
'Status' => 'DRAFT',
'LineAmountTypes' => 'Exclusive',
'LineItems' => [
Expand All @@ -287,7 +287,6 @@ protected function mapCancelled($contributionID, $accounts_invoice_id) {
],
],
];
return $newInvoice;
}

/**
Expand Down
44 changes: 19 additions & 25 deletions CRM/Civixero/OAuth2/Provider/Xero.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,43 +10,37 @@
/**
*/
class CRM_Civixero_OAuth2_Provider_Xero extends \League\OAuth2\Client\Provider\GenericProvider {

/**
*
* @var string
*/
private $tenantID = null;

/**
*
* @var string
*/
private $authorizeURL = 'https://login.xero.com/identity/connect/authorize';

/**
*
* @var string
*/
private $tokenURL = 'https://identity.xero.com/connect/token';

/**
*
* @var string
*/
private $resourceOwnerURL = 'https://api.xero.com/api.xro/2.0/Organisation';

/**
*
* @var string
*/
private $connectionsURL = 'https://api.xero.com/connections';

/**
*
* @var string
*/
private $urlBaseAuthorize;


/**
*
* @var array
Expand All @@ -60,7 +54,7 @@ class CRM_Civixero_OAuth2_Provider_Xero extends \League\OAuth2\Client\Provider\G
'accounting.journals.read',
'accounting.reports.read'
];

/**
*
* {@inheritdoc}
Expand All @@ -69,7 +63,7 @@ class CRM_Civixero_OAuth2_Provider_Xero extends \League\OAuth2\Client\Provider\G
public function getDefaultScopes() {
return is_array($this->defaultScopes) ? implode($this->getScopeSeparator(), $this->defaultScopes) : $this->defaultScopes;
}

/**
*
* {@inheritdoc}
Expand All @@ -78,13 +72,13 @@ public function getDefaultScopes() {
public function getScopeSeparator() {
return ' ';
}

/**
*
* @param array $options
* If being used for authorization then options should include:
* - redirectUri
*
*
* @param array $collaborators
*/
public function __construct($options = [], $collaborators = []) {
Expand All @@ -94,10 +88,10 @@ public function __construct($options = [], $collaborators = []) {
'urlResourceOwnerDetails' => $this->resourceOwnerURL,
'scopes' => $this->getDefaultScopes()
]);

parent::__construct($options, $collaborators);
}

/**
*
* {@inheritdoc}
Expand All @@ -108,7 +102,7 @@ public function getAuthorizationUrl(Array $options = []) {
], $options);
return parent::getAuthorizationUrl($options);
}

/**
* Get headers for authenticated request to Xero.
*
Expand All @@ -123,11 +117,11 @@ protected function getAuthorizationHeaders($token = null) {
}
return $headers;
}
public function getTenantID($access_token) {
return $this->tenantID ? $this->tenantID : $this->getConnectedTenantID($access_token);

public function getTenantID($access_token): ?string {
return $this->tenantID ?: $this->getConnectedTenantID($access_token);
}

/**
* Gets the Tenant ID for the connected tenant.
*
Expand All @@ -146,5 +140,5 @@ public function getConnectedTenantID($access_token) {
return !empty($connection['tenantId']) ? $connection['tenantId'] : NULL;
}
}
}

}
2 changes: 1 addition & 1 deletion CRM/Civixero/Page/Inline/ContactSyncErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function run() {
* @param CRM_Core_Page $page
* @param int $contactID
*/
public static function addContactSyncErrorsBlock(&$page, $contactID) {
public static function addContactSyncErrorsBlock($page, $contactID) {
$hasContactErrors = FALSE;

try {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Civixero/Page/Inline/ContactSyncLink.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function run() {
* @param CRM_Core_Page $page
* @param int $contactID
*/
public static function addContactSyncLinkBlock(&$page, $contactID) {
public static function addContactSyncLinkBlock($page, int $contactID) {

$isContactSynced = 0;

Expand Down
2 changes: 1 addition & 1 deletion CRM/Civixero/Page/Inline/ContactSyncStatus.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public function run() {
* @param CRM_Core_Page $page
* @param int $contactID
*/
public static function addContactSyncStatusBlock(CRM_Core_Page &$page, int $contactID) {
public static function addContactSyncStatusBlock(CRM_Core_Page $page, int $contactID): void {
$syncStatus = 0;

try {
Expand Down
2 changes: 1 addition & 1 deletion CRM/Civixero/Page/Inline/InvoiceSyncErrors.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public function run() {
* @param CRM_Core_Page $page
* @param int $contactID
*/
public static function addInvoiceSyncErrorsBlock(&$page, $contactID) {
public static function addInvoiceSyncErrorsBlock($page, int $contactID): void {

$hasInvoiceErrors = FALSE;

Expand Down
2 changes: 0 additions & 2 deletions CRM/Civixero/TrackingCategory.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ class CRM_Civixero_TrackingCategory extends CRM_Civixero_Base {
* - I can't think of a reason why they would but it seems consistent
*
* @param array $params
*
* @throws API_Exception
*/
function pull($params) {
static $trackingOptions = [];
Expand Down
4 changes: 3 additions & 1 deletion Civixero.civix.php
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ function _Civixero_civix_civicrm_config($config = NULL) {

$extRoot = __DIR__ . DIRECTORY_SEPARATOR;
$extDir = $extRoot . 'templates';
CRM_Core_Smarty::singleton()->addTemplateDir($extDir);
if (file_exists($extDir)) {
CRM_Core_Smarty::singleton()->addTemplateDir($extDir);
}

$include_path = $extRoot . PATH_SEPARATOR . get_include_path();
set_include_path($include_path);
Expand Down

0 comments on commit 606679e

Please sign in to comment.