Skip to content

Commit

Permalink
Finish 1.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
paulgoodchild committed Feb 22, 2023
2 parents 8354a69 + b39cd98 commit 2cef556
Show file tree
Hide file tree
Showing 23 changed files with 122 additions and 279 deletions.
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
],
"require": {
"php": ">=7.4",
"fernleafsystems/apiwrappers-base": "^2.0",
"league/oauth2-client": "^2.0"
"fernleafsystems/apiwrappers-base": "^2.1",
"league/oauth2-client": "^2.6"
},
"require-dev": {
},
Expand Down
20 changes: 4 additions & 16 deletions src/Api.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,11 @@ protected function getResponseDataPayloadKey() :string {
return $this->getRequestDataPayloadKey();
}

/**
* @return array|null
*/
public function getCoreResponseData() {
public function getCoreResponseData() :?array {
$data = null;
if ( $this->isLastRequestSuccess() ) {
$key = $this->getResponseDataPayloadKey();
$decoded = $this->getDecodedResponseBody();
$data = empty( $key ) ? $decoded : $decoded[ $key ];
$data = empty( $key ) ? $this->getDecodedResponseBody() : $this->getDecodedResponseBody()[ $key ];
}
return $data;
}
Expand Down Expand Up @@ -101,17 +97,9 @@ protected function preSendVerification() {
}
}

/**
* @return EntityVO|mixed|null
*/
public function sendRequestWithVoResponse() {
public function sendRequestWithVoResponse() :?EntityVO {
$data = $this->req()->getCoreResponseData();

$VO = null;
if ( !empty( $data ) ) {
$VO = $this->getVO()->applyFromArray( $data );
}
return $VO;
return empty( $data ) ? null : $this->getVO()->applyFromArray( $data );
}

/**
Expand Down
22 changes: 11 additions & 11 deletions src/Entities/BankTransactionExplanation/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,35 @@ public function setAssociatedPaidTo( $sAssociatedTo, $sAssociatedId ) {
*/
public function setBankAccount( $oBankAccount ) {
return $this->removeRequestDataItem( 'bank_transaction' )
->setRequestDataItem( 'bank_account', $oBankAccount->getUri() );
->setRequestDataItem( 'bank_account', $oBankAccount->url );
}

/**
* @param BankTransactionVO $oBankTxn
* @param BankTransactionVO $txn
* @return $this
*/
public function setBankTxn( $oBankTxn ) {
public function setBankTxn( $txn ) {
return $this->removeRequestDataItem( 'bank_account' )
->setRequestDataItem( 'bank_transaction', $oBankTxn->getUri() )
->setDatedOn( $oBankTxn->getDatedOn() );
->setRequestDataItem( 'bank_transaction', $txn->url )
->setDatedOn( $txn->dated_on );
}

/**
* @param BillVO $oBill
* @param BillVO $bill
* @return $this
*/
public function setBillPaid( $oBill ) {
public function setBillPaid( $bill ) {
return $this->removeRequestDataItem( 'paid_invoice' )
->setAssociatedPaidTo( 'bill', $oBill->getUri() );
->setAssociatedPaidTo( 'bill', $bill->url );
}

/**
* @param InvoiceVO $oInvoice
* @param InvoiceVO $invoice
* @return $this
*/
public function setInvoicePaid( $oInvoice ) {
public function setInvoicePaid( $invoice ) {
return $this->removeRequestDataItem( 'paid_bill' )
->setAssociatedPaidTo( 'invoice', $oInvoice->getUri() );
->setAssociatedPaidTo( 'invoice', $invoice->url );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,9 @@
class CreateTransferToAnotherAccount extends Create {

/**
* @param BankAccountVO $oBankAccount
* @return $this
*/
public function setTargetBankAccount( $oBankAccount ) {
return $this->setRequestDataItem( 'transfer_bank_account', $oBankAccount->getUri() );
public function setTargetBankAccount( BankAccountVO $bankAccount ) {
return $this->setRequestDataItem( 'transfer_bank_account', $bankAccount->url );
}
}
2 changes: 1 addition & 1 deletion src/Entities/BankTransactionExplanation/RetrieveBulk.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,6 @@ class RetrieveBulk extends RetrieveBulkBase {
* @return $this
*/
public function setBankAccount( $oBankAccount ) {
return $this->setRequestDataItem( 'bank_account', $oBankAccount->getUri() );
return $this->setRequestDataItem( 'bank_account', $oBankAccount->url );
}
}
8 changes: 2 additions & 6 deletions src/Entities/BankTransactions/BankTransactionsIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@

class BankTransactionsIterator extends Entities\Common\CommonIterator {

/**
* @param Entities\BankAccounts\BankAccountVO $oBankAccount
* @return $this
*/
public function filterByBankAccount( $oBankAccount ) {
public function filterByBankAccount( Entities\BankAccounts\BankAccountVO $bankAccount ) :self {
$this->getRetriever()
->setRequestDataItem( 'bank_account', $oBankAccount->getUri() );
->setRequestDataItem( 'bank_account', $bankAccount->url );
return $this;
}

Expand Down
6 changes: 3 additions & 3 deletions src/Entities/BankTransactions/Find.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
class Find extends RetrieveBulk {

/**
* @param BankAccountVO $oBankAccount
* @param BankAccountVO $bankAccount
* @return $this
*/
public function setBankAccount( $oBankAccount ) {
return $this->setRequestDataItem( 'bank_account', $oBankAccount->getUri() );
public function setBankAccount( $bankAccount ) {
return $this->setRequestDataItem( 'bank_account', $bankAccount->url );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/BankTransactions/UploadStatement.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ protected function getUrlEndpoint() :string {
* @return $this
*/
public function setBankAccount( $oBankAccount ) {
return $this->setRequestQueryDataItem( 'bank_account', $oBankAccount->getUri() );
return $this->setRequestQueryDataItem( 'bank_account', $oBankAccount->url );
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Bills/BillsIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class BillsIterator extends Entities\Common\CommonIterator {
*/
public function filterByContact( $contact ) {
$this->getRetriever()
->setRequestDataItem( 'contact', $contact->getUri() );
->setRequestDataItem( 'contact', $contact->url );
return $this;
}

Expand Down
4 changes: 2 additions & 2 deletions src/Entities/Bills/Create.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function addBillItem( BillItemVO $item, bool $merge = true ) :self {
}

public function setCategory( CategoryVO $category ) :self {
return $this->setRequestDataItem( 'category', $category->getUri() );
return $this->setRequestDataItem( 'category', $category->url );
}

/**
Expand All @@ -47,7 +47,7 @@ public function setComment( $comment ) :self {
* @param ContactVO $contact
*/
public function setContact( $contact ) :self {
return $this->setRequestDataItem( 'contact', $contact->getUri() );
return $this->setRequestDataItem( 'contact', $contact->url );
}

/**
Expand Down
30 changes: 8 additions & 22 deletions src/Entities/Categories/Retrieve.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,37 +4,26 @@

class Retrieve extends Base {

/**
* @return bool
*/
public function exists() {
return !is_null( $this->retrieve() );
public function exists() :bool {
return $this->retrieve() !== null;
}

/**
* @return CategoryVO
*/
public function retrieve() {
public function retrieve() :?CategoryVO {
return $this->sendRequestWithVoResponse();
}

/**
* @return CategoryVO|mixed|null
*/
public function sendRequestWithVoResponse() {
public function sendRequestWithVoResponse() :?CategoryVO {
try {
$aData = $this->send()
->getCoreResponseData();
$data = $this->send()->getCoreResponseData();
}
catch ( \Exception $e ) {
}

$VO = null;
if ( !empty( $aData ) && is_array( $aData ) ) {
foreach ( $aData as $sCatType => $aCategory ) {
if ( !empty( $data ) && is_array( $data ) ) {
foreach ( $data as $sCatType => $aCategory ) {
if ( $aCategory[ 'nominal_code' ] == $this->entity_id ) {
$VO = $this->getVO()
->applyFromArray( $aCategory );
$VO = $this->getVO()->applyFromArray( $aCategory );
}
}
}
Expand All @@ -50,9 +39,6 @@ public function setEntityId( $id ) :self {
return $this;
}

/**
* @throws \Exception
*/
protected function preSendVerification() {
parent::preSendVerification();
if ( !$this->hasEntityId() ) {
Expand Down
2 changes: 1 addition & 1 deletion src/Entities/Contacts/Base.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?php
<?php declare( strict_types=1 );

namespace FernleafSystems\ApiWrappers\Freeagent\Entities\Contacts;

Expand Down
90 changes: 17 additions & 73 deletions src/Entities/Contacts/ContactVO.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,82 +10,26 @@
* @property string $first_name
* @property string $last_name
* @property string $organisation_name
* @property string $country
* @property string $sales_tax_registration_number
* @property string $charge_sales_tax - 'Auto', 'Always', 'Never'
* @property string $sales_tax_registration_number
* @property string $status
* @property string $billing_email
* @property string $phone_number
* @property string $mobile
* @property string $address1
* @property string $address2
* @property string $address3
* @property string $town
* @property string $region
* @property string $postcode
* @property string $country
* @property bool $uses_contact_invoice_sequence
*/
class ContactVO extends EntityVO {

/**
* @return string
* @deprecated
*/
public function getChargeSalesTax() {
return $this->charge_sales_tax;
}

/**
* @return string
* @deprecated
*/
public function getCountry() {
return $this->country;
}

/**
* @return string
* @deprecated
*/
public function getEmail() {
return $this->email;
}

/**
* @return string
* @deprecated
*/
public function getFirstName() {
return $this->first_name;
}

/**
* @return string
* @deprecated
*/
public function getLastName() {
return $this->last_name;
}

/**
* @return string
* @deprecated
*/
public function getOrganisationName() {
return $this->organisation_name;
}

/**
* @return string
* @deprecated
*/
public function getSalesTaxRegistrationNumber() {
return $this->sales_tax_registration_number;
}

/**
* @return string 'Active', 'Hidden'
* @deprecated
*/
public function getStatus() {
return $this->status;
}

/**
* @return bool
* @deprecated
*/
public function hasSalesTaxRegistrationNumber() {
return !empty( $this->sales_tax_registration_number );
}
public const CHARGE_SALES_TAX_AUTO = 'Auto';
public const CHARGE_SALES_TAX_ALWAYS = 'Always';
public const CHARGE_SALES_TAX_NEVER = 'Never';
public const STATUS_ACTIVE = 'Active';
public const STATUS_HIDDEN = 'Hidden';
}
6 changes: 3 additions & 3 deletions src/Entities/Contacts/ContactsIterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,12 @@
class ContactsIterator extends Entities\Common\CommonIterator {

/**
* @param Entities\Contacts\ContactVO $oContact
* @param Entities\Contacts\ContactVO $contact
* @return $this
*/
public function filterByContact( $oContact ) {
public function filterByContact( $contact ) {
$this->getRetriever()
->setRequestDataItem( 'contact', $oContact->getUri() );
->setRequestDataItem( 'contact', $contact->url );
return $this;
}

Expand Down
3 changes: 0 additions & 3 deletions src/Entities/Contacts/ContactsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,6 @@

trait ContactsTrait {

/**
* @return string
*/
protected function getApiEndpoint() :string {
return 'contacts';
}
Expand Down
Loading

0 comments on commit 2cef556

Please sign in to comment.