diff --git a/CRM/Civixero/BankTransaction.php b/CRM/Civixero/BankTransaction.php index c92cd45b..b2cfd30f 100644 --- a/CRM/Civixero/BankTransaction.php +++ b/CRM/Civixero/BankTransaction.php @@ -126,7 +126,7 @@ protected function mapToAccounts($invoiceData, $accountsID) { * * @return bool */ - protected function isSplitTransactions() { + protected function isSplitTransactions(): bool { return TRUE; } diff --git a/CRM/Civixero/Invoice.php b/CRM/Civixero/Invoice.php index db338897..96ccaa68 100644 --- a/CRM/Civixero/Invoice.php +++ b/CRM/Civixero/Invoice.php @@ -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'], @@ -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']; @@ -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]); } } @@ -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' => [ @@ -287,7 +287,6 @@ protected function mapCancelled($contributionID, $accounts_invoice_id) { ], ], ]; - return $newInvoice; } /** diff --git a/CRM/Civixero/OAuth2/Provider/Xero.php b/CRM/Civixero/OAuth2/Provider/Xero.php index 972eaee4..eba5becb 100755 --- a/CRM/Civixero/OAuth2/Provider/Xero.php +++ b/CRM/Civixero/OAuth2/Provider/Xero.php @@ -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 @@ -60,7 +54,7 @@ class CRM_Civixero_OAuth2_Provider_Xero extends \League\OAuth2\Client\Provider\G 'accounting.journals.read', 'accounting.reports.read' ]; - + /** * * {@inheritdoc} @@ -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} @@ -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 = []) { @@ -94,10 +88,10 @@ public function __construct($options = [], $collaborators = []) { 'urlResourceOwnerDetails' => $this->resourceOwnerURL, 'scopes' => $this->getDefaultScopes() ]); - + parent::__construct($options, $collaborators); } - + /** * * {@inheritdoc} @@ -108,7 +102,7 @@ public function getAuthorizationUrl(Array $options = []) { ], $options); return parent::getAuthorizationUrl($options); } - + /** * Get headers for authenticated request to Xero. * @@ -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. * @@ -146,5 +140,5 @@ public function getConnectedTenantID($access_token) { return !empty($connection['tenantId']) ? $connection['tenantId'] : NULL; } } - -} \ No newline at end of file + +} diff --git a/CRM/Civixero/Page/Inline/ContactSyncErrors.php b/CRM/Civixero/Page/Inline/ContactSyncErrors.php index fe21eaa3..257cc574 100644 --- a/CRM/Civixero/Page/Inline/ContactSyncErrors.php +++ b/CRM/Civixero/Page/Inline/ContactSyncErrors.php @@ -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 { diff --git a/CRM/Civixero/Page/Inline/ContactSyncLink.php b/CRM/Civixero/Page/Inline/ContactSyncLink.php index 70419680..ed6c351c 100644 --- a/CRM/Civixero/Page/Inline/ContactSyncLink.php +++ b/CRM/Civixero/Page/Inline/ContactSyncLink.php @@ -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; diff --git a/CRM/Civixero/Page/Inline/ContactSyncStatus.php b/CRM/Civixero/Page/Inline/ContactSyncStatus.php index 3fac2953..a7c420a0 100644 --- a/CRM/Civixero/Page/Inline/ContactSyncStatus.php +++ b/CRM/Civixero/Page/Inline/ContactSyncStatus.php @@ -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 { diff --git a/CRM/Civixero/Page/Inline/InvoiceSyncErrors.php b/CRM/Civixero/Page/Inline/InvoiceSyncErrors.php index 3170d491..46cf8529 100644 --- a/CRM/Civixero/Page/Inline/InvoiceSyncErrors.php +++ b/CRM/Civixero/Page/Inline/InvoiceSyncErrors.php @@ -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; diff --git a/CRM/Civixero/TrackingCategory.php b/CRM/Civixero/TrackingCategory.php index 4fe817f9..a6673a9f 100644 --- a/CRM/Civixero/TrackingCategory.php +++ b/CRM/Civixero/TrackingCategory.php @@ -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 = []; diff --git a/Civixero.civix.php b/Civixero.civix.php index 71f42691..011eb6a0 100755 --- a/Civixero.civix.php +++ b/Civixero.civix.php @@ -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);