From 53cc23036f9a8f380135c9fdfda540857d6d6552 Mon Sep 17 00:00:00 2001 From: Brett Bailey Date: Mon, 1 Jul 2024 13:38:52 +1000 Subject: [PATCH 1/3] Test Updates --- composer.json | 2 +- tests/Application/ApplicationTest.php | 11 +- tests/HelpersTest.php | 3 +- tests/Remote/ModelTest.php | 3 +- tests/Remote/QueryTest.php | 220 +++++++++++++------------- tests/Remote/RequestTest.php | 3 +- tests/Remote/ResponseTest.php | 31 +++- tests/Webhook/EventTest.php | 5 +- tests/WebhookTest.php | 5 +- 9 files changed, 158 insertions(+), 125 deletions(-) diff --git a/composer.json b/composer.json index da957bc2..d165be1c 100644 --- a/composer.json +++ b/composer.json @@ -13,7 +13,7 @@ "ext-simplexml": "*" }, "require-dev": { - "phpunit/phpunit": "^5" + "phpunit/phpunit": "^10" }, "suggest": { "ext-fileinfo": "*", diff --git a/tests/Application/ApplicationTest.php b/tests/Application/ApplicationTest.php index 38457351..3d478e8a 100644 --- a/tests/Application/ApplicationTest.php +++ b/tests/Application/ApplicationTest.php @@ -2,9 +2,10 @@ namespace XeroPHP\Tests\Application; +use PHPUnit\Framework\TestCase; use XeroPHP\Application; -class ApplicationTest extends \PHPUnit_Framework_TestCase +class ApplicationTest extends TestCase { public function testAllowsFQNWhenValidatingModelClass() { @@ -28,7 +29,7 @@ public function testAllowsFQNBeginningWithBackslashWhenValidatingModelClass() public function testThrowsExceptionWhenUnableToValidateClass() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $this->instance()->validateModelClass('Unknown\\Namespaced\\Class'); @@ -36,7 +37,7 @@ public function testThrowsExceptionWhenUnableToValidateClass() public function testSettingMissingConfigOptionThrowsException() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $this->instance()->setConfigOption('non_exitant_key', 'sub_key', 'value'); } @@ -80,14 +81,14 @@ public function testCanRetrieveConfigOption() public function testAccessingMissingConfigOptionThrowsException() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $this->instance()->getConfigOption('xero', 'non_existent_key'); } public function testAccessingMissingConfigThrowsException() { - $this->setExpectedException(\Exception::class); + $this->expectException(\Exception::class); $this->instance()->getConfig('non_existent_key'); } diff --git a/tests/HelpersTest.php b/tests/HelpersTest.php index 6714a120..3d8a88f9 100644 --- a/tests/HelpersTest.php +++ b/tests/HelpersTest.php @@ -2,9 +2,10 @@ namespace XeroPHP\Tests; +use PHPUnit\Framework\TestCase; use XeroPHP\Helpers; -class HelpersTest extends \PHPUnit_Framework_TestCase +class HelpersTest extends TestCase { public function testXMLToArrayWithEmptyNodes() { diff --git a/tests/Remote/ModelTest.php b/tests/Remote/ModelTest.php index 07a274b8..98f0957c 100644 --- a/tests/Remote/ModelTest.php +++ b/tests/Remote/ModelTest.php @@ -6,11 +6,12 @@ use GuzzleHttp\Handler\MockHandler; use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\TestCase; use XeroPHP\Application; use XeroPHP\Remote\Model; use XeroPHP\Tests\Remote\Model\ModelWithCollection; -class ModelTest extends \PHPUnit_Framework_TestCase +class ModelTest extends TestCase { public function testAccessorMethods() { diff --git a/tests/Remote/QueryTest.php b/tests/Remote/QueryTest.php index 3d175b41..98dd667e 100644 --- a/tests/Remote/QueryTest.php +++ b/tests/Remote/QueryTest.php @@ -2,120 +2,118 @@ namespace XeroPHP\Tests\Remote; +use PHPUnit\Framework\TestCase; use XeroPHP\Application; use XeroPHP\Remote\Query; -class QueryTest extends \PHPUnit_Framework_TestCase +class QueryTest extends TestCase { - - function testWhere() { - - $xero_app = $this->getApplication(); - - // Where: DateTime(yyyy,mm,dd) - $query = new Query($xero_app); - $query->where('SomeDateKey', 'DateTime(2020,11,25)'); - $where = $query->getWhere(); - $this->assertSame("SomeDateKey==DateTime(2020,11,25)", $where, "DateTime function in where string should not have surrounding quotes (as per xero api documentation v2.0)"); - - // Where: single parameter - $query = new Query($xero_app); - $single_param = 'SomeDateKey>=DateTime(2020,11,25)'; - $query->where($single_param); - $where = $query->getWhere(); - $this->assertSame($single_param, $where, "Single parameter should be unchanged in where string"); - - // Where: integer - $query = new Query($xero_app); - $query->where('SomeKey', 3); - $where = $query->getWhere(); - $this->assertSame("SomeKey==3", $where, "Integer in where string should not have surrounding quotes"); - - // Where: float - $query = new Query($xero_app); - $query->where('SomeKey', 3.7); - $where = $query->getWhere(); - $this->assertSame("SomeKey==3.7", $where, "Float in where string should not have surrounding quotes"); - - // Where: string - $query = new Query($xero_app); - $query->where('SomeKey', 'any string value'); - $where = $query->getWhere(); - $this->assertSame("SomeKey==\"any string value\"", $where, "String in where string should have surrounding quotes"); - - // Where: string contains integer - $query = new Query($xero_app); - $query->where('SomeKey', '3'); - $where = $query->getWhere(); - $this->assertSame("SomeKey==\"3\"", $where, "Integer passed as string should have surrounding quotes"); - - // Where: guid with key ending in ID - $query = new Query($xero_app); - $guid = "44aa0707-f718-4f1c-8d53-f2da9ca59533"; - $query->where('KeyEndingWithID', $guid); - $where = $query->getWhere(); - $this->assertSame("KeyEndingWithID=Guid(\"$guid\")", $where, "Key ends in ID and value is guid string, should have guid format in where string"); - - // Where: guid with key not ending in ID - $query = new Query($xero_app); - $guid = "44aa0707-f718-4f1c-8d53-f2da9ca59533"; - $query->where('SomeKey', $guid); - $where = $query->getWhere(); - $this->assertSame("SomeKey==\"$guid\"", $where, "key does not end in ID and value is guid string, should be formatted as a string in where string"); - - // Where: key ends in ID with non-guid value - $query = new Query($xero_app); - $not_a_guid = "Some-AlphaNu-meric-value9876"; - $query->where('KeyEndingWithID', $not_a_guid); - $where = $query->getWhere(); - $this->assertSame("KeyEndingWithID==\"$not_a_guid\"", $where, "Key ends in ID but value is not a guid, should be formatted as a string in where string"); - - // Where: "true" - $query = new Query($xero_app); - $query->where('SomeKey', "true"); - $where = $query->getWhere(); - $this->assertSame("SomeKey=true", $where, "'true' passed as string should have no quotes in where string"); - - // Where: true (bool) - $query = new Query($xero_app); - $query->where('SomeKey', true); - $where = $query->getWhere(); - $this->assertSame("SomeKey=true", $where, "true passed as bool should have no quotes in where string"); - - // Where: "false" - $query = new Query($xero_app); - $query->where('SomeKey', "false"); - $where = $query->getWhere(); - $this->assertSame("SomeKey=false", $where, "'false' passed as string should have no quotes in where string"); - - // Where: false (bool) - $query = new Query($xero_app); - $query->where('SomeKey', false); - $where = $query->getWhere(); - $this->assertSame("SomeKey=false", $where, "false passed as bool should have no quotes in where string"); - - } - - function testAndWhere() { - - $xero_app = $this->getApplication(); - $query = new Query($xero_app); - $param_1 = 'SomeDateKey >= DateTime(2020,11,25)'; - $param_2 = 'SomeDateKey < DateTime(2020,12,25)'; - $query->where($param_1); - $query->andWhere($param_2); - - $where = $query->getWhere(); - $this->assertSame("$param_1 AND $param_2", $where, "Where conditions should be linked by 'AND'"); - - } - - protected function getApplication($config = []) - { - $xero_app = new Application('token', 'tenantId'); - $xero_app->setConfig($config); - - return $xero_app; - } + function testWhere() + { + $xero_app = $this->getApplication(); + + // Where: DateTime(yyyy,mm,dd) + $query = new Query($xero_app); + $query->where('SomeDateKey', 'DateTime(2020,11,25)'); + $where = $query->getWhere(); + $this->assertSame("SomeDateKey==DateTime(2020,11,25)", $where, "DateTime function in where string should not have surrounding quotes (as per xero api documentation v2.0)"); + + // Where: single parameter + $query = new Query($xero_app); + $single_param = 'SomeDateKey>=DateTime(2020,11,25)'; + $query->where($single_param); + $where = $query->getWhere(); + $this->assertSame($single_param, $where, "Single parameter should be unchanged in where string"); + + // Where: integer + $query = new Query($xero_app); + $query->where('SomeKey', 3); + $where = $query->getWhere(); + $this->assertSame("SomeKey==3", $where, "Integer in where string should not have surrounding quotes"); + + // Where: float + $query = new Query($xero_app); + $query->where('SomeKey', 3.7); + $where = $query->getWhere(); + $this->assertSame("SomeKey==3.7", $where, "Float in where string should not have surrounding quotes"); + + // Where: string + $query = new Query($xero_app); + $query->where('SomeKey', 'any string value'); + $where = $query->getWhere(); + $this->assertSame("SomeKey==\"any string value\"", $where, "String in where string should have surrounding quotes"); + + // Where: string contains integer + $query = new Query($xero_app); + $query->where('SomeKey', '3'); + $where = $query->getWhere(); + $this->assertSame("SomeKey==\"3\"", $where, "Integer passed as string should have surrounding quotes"); + + // Where: guid with key ending in ID + $query = new Query($xero_app); + $guid = "44aa0707-f718-4f1c-8d53-f2da9ca59533"; + $query->where('KeyEndingWithID', $guid); + $where = $query->getWhere(); + $this->assertSame("KeyEndingWithID=Guid(\"$guid\")", $where, "Key ends in ID and value is guid string, should have guid format in where string"); + + // Where: guid with key not ending in ID + $query = new Query($xero_app); + $guid = "44aa0707-f718-4f1c-8d53-f2da9ca59533"; + $query->where('SomeKey', $guid); + $where = $query->getWhere(); + $this->assertSame("SomeKey==\"$guid\"", $where, "key does not end in ID and value is guid string, should be formatted as a string in where string"); + + // Where: key ends in ID with non-guid value + $query = new Query($xero_app); + $not_a_guid = "Some-AlphaNu-meric-value9876"; + $query->where('KeyEndingWithID', $not_a_guid); + $where = $query->getWhere(); + $this->assertSame("KeyEndingWithID==\"$not_a_guid\"", $where, "Key ends in ID but value is not a guid, should be formatted as a string in where string"); + + // Where: "true" + $query = new Query($xero_app); + $query->where('SomeKey', "true"); + $where = $query->getWhere(); + $this->assertSame("SomeKey=true", $where, "'true' passed as string should have no quotes in where string"); + + // Where: true (bool) + $query = new Query($xero_app); + $query->where('SomeKey', true); + $where = $query->getWhere(); + $this->assertSame("SomeKey=true", $where, "true passed as bool should have no quotes in where string"); + + // Where: "false" + $query = new Query($xero_app); + $query->where('SomeKey', "false"); + $where = $query->getWhere(); + $this->assertSame("SomeKey=false", $where, "'false' passed as string should have no quotes in where string"); + + // Where: false (bool) + $query = new Query($xero_app); + $query->where('SomeKey', false); + $where = $query->getWhere(); + $this->assertSame("SomeKey=false", $where, "false passed as bool should have no quotes in where string"); + } + + function testAndWhere() + { + $xero_app = $this->getApplication(); + $query = new Query($xero_app); + $param_1 = 'SomeDateKey >= DateTime(2020,11,25)'; + $param_2 = 'SomeDateKey < DateTime(2020,12,25)'; + $query->where($param_1); + $query->andWhere($param_2); + + $where = $query->getWhere(); + $this->assertSame("$param_1 AND $param_2", $where, "Where conditions should be linked by 'AND'"); + } + + protected function getApplication($config = []) + { + $xero_app = new Application('token', 'tenantId'); + $xero_app->setConfig($config); + + return $xero_app; + } } \ No newline at end of file diff --git a/tests/Remote/RequestTest.php b/tests/Remote/RequestTest.php index 56809244..ed4ece3b 100644 --- a/tests/Remote/RequestTest.php +++ b/tests/Remote/RequestTest.php @@ -9,6 +9,7 @@ use GuzzleHttp\HandlerStack; use GuzzleHttp\Psr7\Request as GuzzleRequest; use GuzzleHttp\Psr7\Response; +use PHPUnit\Framework\TestCase; use XeroPHP\Application; use XeroPHP\Remote\Exception\UnknownStatusException; use XeroPHP\Remote\Request as XeroRequest; @@ -16,7 +17,7 @@ use XeroPHP\Remote\Exception\BadRequestException; use XeroPHP\Remote\Exception\RateLimitExceededException; -class RequestTest extends \PHPUnit_Framework_TestCase +class RequestTest extends TestCase { private function getMockedApplication($mockedResponses) { diff --git a/tests/Remote/ResponseTest.php b/tests/Remote/ResponseTest.php index aae1c173..2d8bdd56 100644 --- a/tests/Remote/ResponseTest.php +++ b/tests/Remote/ResponseTest.php @@ -3,12 +3,13 @@ namespace XeroPHP\Tests\Remote; +use PHPUnit\Framework\TestCase; use XeroPHP\Application; use XeroPHP\Remote\Request; use XeroPHP\Remote\Response; use XeroPHP\Remote\URL; -class ResponseTest extends \PHPUnit_Framework_TestCase +class ResponseTest extends TestCase { public function testRootWarningsAreParsedJson() @@ -59,6 +60,34 @@ public function testRootWarningsAreParsedXML() $this->assertEquals("This is a Warning Message.", $rootWarnings[0]["Message"]); } + public function testPaginatedValuesAreParsedXML() + { + $app = $this->getApplication(); + $response = new Response(new Request($app, new URL($app, 'test')), + ' + 2 + OK + + 2024-05-02T14:52:55.8388472Z + + 1 + 1000 + 2 + 1275 + + +', Response::STATUS_OK, [Request::HEADER_CONTENT_TYPE => [Request::CONTENT_TYPE_XML.";"]]); + + $response->parse(); + + $pageInfo = $response->getPageInfo(); + + $this->assertEquals(1, $pageInfo->getPage()); + $this->assertEquals(1000, $pageInfo->getPageSize()); + $this->assertEquals(2, $pageInfo->getTotalPages()); + $this->assertEquals(1275, $pageInfo->getTotalRows()); + } + protected function getApplication($config = []) { $xero_app = new Application('token', 'tenantId'); diff --git a/tests/Webhook/EventTest.php b/tests/Webhook/EventTest.php index eb93e2ce..da143bbe 100644 --- a/tests/Webhook/EventTest.php +++ b/tests/Webhook/EventTest.php @@ -2,18 +2,19 @@ namespace XeroPHP\Tests\Webhook; +use PHPUnit\Framework\TestCase; use XeroPHP\Webhook; use XeroPHP\Application; use XeroPHP\Application\PrivateApplication; -class EventTest extends \PHPUnit_Framework_TestCase +class EventTest extends TestCase { /** * @var Application */ private $application; - protected function setUp() + public function setUp(): void { $this->application = new Application('token', 'tenantId'); $this->application->setConfig([ diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index be9431dc..8752255f 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -2,19 +2,20 @@ namespace XeroPHP\Tests; +use PHPUnit\Framework\TestCase; use XeroPHP\Application; use XeroPHP\Application\PrivateApplication; use XeroPHP\Webhook; use XeroPHP\Webhook\Event; -class WebhookTest extends \PHPUnit_Framework_TestCase +class WebhookTest extends TestCase { /** * @var Application */ private $application; - protected function setUp() + public function setUp(): void { $this->application = new Application('token', 'tenantId'); $this->application->setConfig([ From 3455f804a500744e72e56644d55d26668239a481 Mon Sep 17 00:00:00 2001 From: Brett Bailey Date: Mon, 1 Jul 2024 13:40:09 +1000 Subject: [PATCH 2/3] Add Page Size and Page Info --- src/XeroPHP/Remote/PageInfo.php | 69 +++++++++++++++++++++++++++++++++ src/XeroPHP/Remote/Query.php | 29 ++++++++++++++ src/XeroPHP/Remote/Response.php | 21 +++++++++- 3 files changed, 117 insertions(+), 2 deletions(-) create mode 100644 src/XeroPHP/Remote/PageInfo.php diff --git a/src/XeroPHP/Remote/PageInfo.php b/src/XeroPHP/Remote/PageInfo.php new file mode 100644 index 00000000..9346ab83 --- /dev/null +++ b/src/XeroPHP/Remote/PageInfo.php @@ -0,0 +1,69 @@ + + * 1 + * 1000 + * 2 + * 1275 + * + */ +class PageInfo +{ + private int $page; + private int $pageSize; + private int $totalPages; + private int $totalRows; + + public function getPage(): int + { + return $this->page; + } + + public function setPage($value): self + { + $this->page = $value; + + return $this; + } + + + public function getPageSize(): int + { + return $this->pageSize; + } + + public function setPageSize($value): self + { + $this->pageSize = $value; + + return $this; + } + + public function getTotalPages(): int + { + return $this->totalPages; + } + + public function setTotalPages($value): self + { + $this->totalPages = $value; + + return $this; + } + + public function getTotalRows(): int + { + return $this->totalRows; + } + + public function setTotalRows($value): self + { + $this->totalRows = $value; + + return $this; + } +} diff --git a/src/XeroPHP/Remote/Query.php b/src/XeroPHP/Remote/Query.php index 5bdc896e..40805732 100644 --- a/src/XeroPHP/Remote/Query.php +++ b/src/XeroPHP/Remote/Query.php @@ -24,6 +24,8 @@ class Query private $page; + private $pageSize; + private $fromDate; private $toDate; @@ -48,6 +50,7 @@ public function __construct(Application $app) $this->order = null; $this->modifiedAfter = null; $this->page = null; + $this->pageSize = null; $this->offset = null; $this->includeArchived = false; $this->createdByMyApp = false; @@ -236,6 +239,28 @@ public function page($page = 1) return $this; } + + /** + * @param int $pageSize + * + * @throws Exception + * + * @return $this + */ + public function pageSize($pageSize = 100) + { + /** + * @var ObjectInterface + */ + $from_class = $this->from_class; + if (! $from_class::isPageable()) { + throw new Exception(sprintf('%s does not support paging.', $from_class)); + } + $this->pageSize = (int) $pageSize; + + return $this; + } + /** * @param int $offset * @@ -321,6 +346,10 @@ public function execute() $request->setParameter('page', $this->page); } + if ($this->pageSize !== null) { + $request->setParameter('pageSize', $this->pageSize); + } + if ($this->offset !== null) { $request->setParameter('offset', $this->offset); } diff --git a/src/XeroPHP/Remote/Response.php b/src/XeroPHP/Remote/Response.php index b5570187..932a726f 100644 --- a/src/XeroPHP/Remote/Response.php +++ b/src/XeroPHP/Remote/Response.php @@ -74,6 +74,8 @@ class Response private $root_warnings; + private $pageInfo; + public function __construct(Request $request, $response_body, $status, $headers) { $this->request = $request; @@ -318,7 +320,12 @@ public function parseXML() foreach ($sxml as $child_index => $root_child) { switch ($child_index) { case 'PageInfo': - // TODO: We can potentially handle the page info and make it a value on the response object + $this->pageInfo = (new PageInfo()) + ->setPage((int)$root_child->Page) + ->setPageSize((int)$root_child->PageSize) + ->setTotalPages((int)$root_child->TotalPages) + ->setTotalRows((int)$root_child->TotalRows); + break; case 'ErrorNumber': $this->root_error['code'] = (string)$root_child; @@ -365,7 +372,12 @@ public function parseJSON() foreach ($json as $child_index => $root_child) { switch ($child_index) { case 'PageInfo': - // TODO: We can potentially handle the page info and make it a value on the response object + $this->pageInfo = (new PageInfo()) + ->setPage($root_child['Page']) + ->setPageSize($root_child['PageSize']) + ->setTotalPages($root_child['TotalPages']) + ->setTotalRows($root_child['TotalRows']); + break; case 'ErrorNumber': $this->root_error['code'] = $root_child; @@ -411,4 +423,9 @@ public function parseHTML() { parse_str($this->response_body, $this->oauth_response); } + + public function getPageInfo(): PageInfo + { + return $this->pageInfo; + } } From e780564837625d6b8da8f30ad17254aef423377e Mon Sep 17 00:00:00 2001 From: Brett Bailey Date: Tue, 2 Jul 2024 20:16:21 +1000 Subject: [PATCH 3/3] Deleted Deprecations - Moved to PHP 8.1 --- composer.json | 6 +- phpunit.xml.dist | 24 +- src/XeroPHP/Application.php | 170 ++++---- src/XeroPHP/Models/Accounting/Account.php | 388 +++--------------- src/XeroPHP/Models/Accounting/Address.php | 127 ++---- src/XeroPHP/Models/Accounting/Attachment.php | 4 +- .../BankTransaction/BankAccount.php | 53 +-- .../Accounting/BankTransaction/LineItem.php | 11 - .../Models/Accounting/BankTransfer.php | 6 +- .../BankTransfer/FromBankAccount.php | 60 +-- .../Accounting/BankTransfer/ToBankAccount.php | 60 +-- .../Models/Accounting/BatchPayment.php | 9 - src/XeroPHP/Models/Accounting/Contact.php | 38 -- .../Accounting/Contact/ContactPerson.php | 59 +-- src/XeroPHP/Models/Accounting/CreditNote.php | 9 - src/XeroPHP/Models/Accounting/Currency.php | 33 -- src/XeroPHP/Models/Accounting/Invoice.php | 15 - .../Models/Accounting/Invoice/LineItem.php | 11 - src/XeroPHP/Models/Accounting/Item.php | 40 +- .../Models/Accounting/Item/Purchase.php | 33 -- src/XeroPHP/Models/Accounting/Item/Sale.php | 33 -- src/XeroPHP/Models/Accounting/Overpayment.php | 74 ---- .../Accounting/Overpayment/Allocation.php | 69 +--- .../Accounting/Overpayment/LineItem.php | 11 - src/XeroPHP/Models/Accounting/Prepayment.php | 75 ---- .../Accounting/Prepayment/Allocation.php | 69 +--- .../Models/Accounting/Prepayment/LineItem.php | 11 - .../Accounting/PurchaseOrder/LineItem.php | 11 - .../Models/Accounting/Receipt/LineItem.php | 11 - .../Models/Accounting/RepeatingInvoice.php | 9 - .../Accounting/RepeatingInvoice/LineItem.php | 11 - .../Models/Accounting/ReportTaxType.php | 28 -- .../Models/Accounting/SalesTaxPeriod.php | 16 - src/XeroPHP/Models/Accounting/TaxType.php | 30 -- src/XeroPHP/Models/Files/ObjectGroup.php | 36 ++ .../Files/{Object.php => ObjectType.php} | 32 +- src/XeroPHP/Models/PayrollAU/Employee.php | 33 -- .../PayrollAU/Employee/TaxDeclaration.php | 33 -- .../Models/PayrollAU/PayItem/EarningsRate.php | 37 +- .../Payslip/TimesheetEarningsLine.php | 25 -- .../Models/PayrollAU/Setting/Account.php | 49 +-- src/XeroPHP/Models/PayrollAU/SuperFund.php | 25 -- .../Models/PayrollAU/SuperFund/SuperFund.php | 34 -- .../Models/PayrollAU/SuperFundProduct.php | 34 -- src/XeroPHP/Models/PayrollUK/Timesheet.php | 51 +-- .../PayrollUS/Employee/OpeningBalance.php | 33 -- .../PayrollUS/Employee/SalaryAndWage.php | 33 -- .../Models/PayrollUS/PayItem/EarningsType.php | 66 --- .../Models/PayrollUS/Setting/Account.php | 49 +-- src/XeroPHP/Models/SubscriptionItem.php | 2 +- src/XeroPHP/Remote/Model.php | 132 +++--- src/XeroPHP/Remote/Object.php | 10 - src/XeroPHP/Remote/Query.php | 107 ++--- src/XeroPHP/Remote/Request.php | 36 +- src/XeroPHP/Remote/Response.php | 2 +- src/XeroPHP/Remote/URL.php | 29 +- src/XeroPHP/Webhook/Event.php | 106 ++--- tests/Remote/Model/AccountTest.php | 24 ++ tests/Webhook/EventTest.php | 29 +- tests/WebhookTest.php | 18 +- 60 files changed, 612 insertions(+), 2067 deletions(-) delete mode 100644 src/XeroPHP/Models/Accounting/BankTransaction/LineItem.php delete mode 100644 src/XeroPHP/Models/Accounting/Invoice/LineItem.php delete mode 100644 src/XeroPHP/Models/Accounting/Overpayment/LineItem.php delete mode 100644 src/XeroPHP/Models/Accounting/Prepayment/LineItem.php delete mode 100644 src/XeroPHP/Models/Accounting/PurchaseOrder/LineItem.php delete mode 100644 src/XeroPHP/Models/Accounting/Receipt/LineItem.php delete mode 100644 src/XeroPHP/Models/Accounting/RepeatingInvoice/LineItem.php create mode 100644 src/XeroPHP/Models/Files/ObjectGroup.php rename src/XeroPHP/Models/Files/{Object.php => ObjectType.php} (71%) delete mode 100644 src/XeroPHP/Remote/Object.php create mode 100644 tests/Remote/Model/AccountTest.php diff --git a/composer.json b/composer.json index d165be1c..fd2e3eb2 100644 --- a/composer.json +++ b/composer.json @@ -5,10 +5,10 @@ "homepage": "https://github.com/calcinai/xero-php", "license": "MIT", "require": { - "php": ">=5.5.0", + "php": ">=8.1", "calcinai/oauth2-xero": "^1.0", - "guzzlehttp/guzzle": "^6.5|^7.0", - "guzzlehttp/psr7": "^1.5|^1.6|^2.1.1", + "guzzlehttp/guzzle": "^7.0", + "guzzlehttp/psr7": "^2.1.1", "ext-json": "*", "ext-simplexml": "*" }, diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 903fe8b1..eb0bcf16 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -1,30 +1,18 @@ - + bootstrap="vendor/autoload.php"> ./tests - - - - src - - - - - - + + + ./src + + diff --git a/src/XeroPHP/Application.php b/src/XeroPHP/Application.php index 7c33f3a3..de87719b 100644 --- a/src/XeroPHP/Application.php +++ b/src/XeroPHP/Application.php @@ -15,13 +15,13 @@ class Application protected static $_config_defaults = [ 'xero' => [ - 'base_url' => 'https://api.xero.com', - 'default_content_type' => Request::CONTENT_TYPE_XML, - 'core_version' => '2.0', - 'payroll_version' => '1.0', - 'file_version' => '1.0', - 'practice_manager_version' => '3.0' - ] + 'base_url' => 'https://api.xero.com', + 'default_content_type' => Request::CONTENT_TYPE_XML, + 'core_version' => '2.0', + 'payroll_version' => '1.0', + 'file_version' => '1.0', + 'practice_manager_version' => '3.0', + ], ]; /** @@ -30,72 +30,64 @@ class Application protected $config; private ?int $lastApiCall = null; - private ?int $appMinLimitRemining = null; - private ?int $tenantDayLimitRemining = null; - private ?int $tenantMinLimitRemining = null; + private ?int $appMinLimitRemaining = null; + private ?int $tenantDayLimitRemaining = null; + private ?int $tenantMinLimitRemaining = null; - /** - * @var ClientInterface - */ - private $transport; + private ClientInterface $transport; - /** - * @param $token - * @param $tenantId - * $param $constructClient - */ - public function __construct($token, $tenantId, ?bool $constructClient = true) + public function __construct(string $token, string $tenantId, ?bool $constructClient = true) { $this->config = static::$_config_defaults; - if($constructClient){ + if ($constructClient) { //Not sure if this is necessary, but it's one less thing to have to create outside the instance. $transport = new Client([ 'headers' => [ - 'User-Agent' => sprintf(static::USER_AGENT_STRING, Helpers::getPackageVersion()), - 'Authorization' => sprintf('Bearer %s', $token), + 'User-Agent' => sprintf(static::USER_AGENT_STRING, Helpers::getPackageVersion()), + 'Authorization' => sprintf('Bearer %s', $token), 'Xero-tenant-id' => $tenantId, - ] + ], ]); - + $this->transport = $transport; } } /** - * @param mixed $key + * @param mixed $key * + * @return mixed * @throws Exception * - * @return mixed */ public function getConfig($key) { if (!isset($this->config[$key])) { - throw new Exception("Invalid configuration key [{$key}]"); + throw new Exception("Invalid configuration key [$key]"); } return $this->config[$key]; } /** - * @param string $config - * @param mixed $option + * @param string $config + * @param mixed $option * @return mixed * @throws Exception */ public function getConfigOption($config, $option) { if (!isset($this->getConfig($config)[$option])) { - throw new Exception("Invalid configuration option [{$option}]"); + throw new Exception("Invalid configuration option [$option]"); } return $this->getConfig($config)[$option]; } /** - * @param array $config + * @param array $config * * @return array */ @@ -110,18 +102,18 @@ public function setConfig($config) } /** - * @param string $config - * @param mixed $option - * @param mixed $value + * @param string $config + * @param mixed $option + * @param mixed $value * + * @return array * @throws Exception * - * @return array */ public function setConfigOption($config, $option, $value) { if (!isset($this->config[$config])) { - throw new Exception("Invalid configuration key [{$config}]"); + throw new Exception("Invalid configuration key [$config]"); } $this->config[$config][$option] = $value; @@ -137,7 +129,7 @@ public function getTransport() } /** - * @param ClientInterface $client + * @param ClientInterface $client * @return ClientInterface */ public function setTransport(ClientInterface $client) @@ -148,11 +140,11 @@ public function setTransport(ClientInterface $client) /** * Validates and expands the provided model class to a full PHP class. * - * @param string $class + * @param string $class * + * @return string * @throws Exception * - * @return string */ public function validateModelClass($class) { @@ -163,7 +155,7 @@ public function validateModelClass($class) $class = $this->prependConfigNamespace($class); if (!class_exists($class)) { - throw new Exception("Class does not exist [{$class}]"); + throw new Exception("Class does not exist [$class]"); } return $class; @@ -172,7 +164,7 @@ public function validateModelClass($class) /** * Prepend the configuration namespace to the class. * - * @param string $class + * @param string $class * * @return string */ @@ -187,31 +179,29 @@ protected function prependConfigNamespace($class) * @param $model * @param $guid * - * @throws Exception + * @return Remote\Model|null * @throws Remote\Exception\NotFoundException * - * @return Remote\Model|null + * @throws Exception */ public function loadByGUID($model, $guid) { /** @var Remote\Model $class */ $class = $this->validateModelClass($model); - if(!$guid){ + if (!$guid) { throw new Remote\Exception\NotFoundException; } $uri = sprintf('%s/%s', $class::getResourceURI(), $guid); $api = $class::getAPIStem(); - $url = new URL($this, $uri, $api); + $url = new URL($this, $uri, $api); $request = new Request($this, $url, Request::METHOD_GET); $request->send(); //Return the first (if any) element from the response. foreach ($request->getResponse()->getElements() as $element) { - - /** @var $object Remote\Model */ $object = new $class($this); $object->fromStringArray($element); @@ -226,34 +216,32 @@ public function loadByGUID($model, $guid) * Filter by comma separated string of guid's. * * @param $model - * @param string $guids + * @param string $guids * - * @throws Exception + * @return Collection|array * @throws Remote\Exception\NotFoundException * - * @return Collection|array + * @throws Exception */ public function loadByGUIDs($model, $guids) { /** @var $class Remote\Model */ $class = $this->validateModelClass($model); - if(empty($guids)){ + if (empty($guids)) { return []; } $uri = sprintf('%s', $class::getResourceURI()); $api = $class::getAPIStem(); - $url = new URL($this, $uri, $api); + $url = new URL($this, $uri, $api); $request = new Request($this, $url, Request::METHOD_GET); $request->setParameter('IDs', $guids); $request->send(); $elements = new Collection(); foreach ($request->getResponse()->getElements() as $element) { - - /** @var $object Remote\Model */ $object = new $class($this); $object->fromStringArray($element); $elements->append($object); @@ -263,7 +251,7 @@ public function loadByGUIDs($model, $guids) } /** - * @param string $model + * @param string $model * * @return Query */ @@ -275,12 +263,12 @@ public function load($model) } /** - * @param Remote\Model $object - * @param bool $replace_data + * @param Remote\Model $object + * @param bool $replace_data * + * @return Remote\Response|null * @throws Exception * - * @return Remote\Response|null */ public function save(Remote\Model $object, $replace_data = false) { @@ -296,11 +284,11 @@ public function save(Remote\Model $object, $replace_data = false) if ($object->hasGUID()) { $method = $object::supportsMethod(Request::METHOD_POST) ? Request::METHOD_POST : Request::METHOD_PUT; - $uri = sprintf('%s/%s', $object::getResourceURI(), $object->getGUID()); + $uri = sprintf('%s/%s', $object::getResourceURI(), $object->getGUID()); } else { //In this case it's new $method = $object::supportsMethod(Request::METHOD_PUT) ? Request::METHOD_PUT : Request::METHOD_POST; - $uri = $object::getResourceURI(); + $uri = $object::getResourceURI(); //@todo, bump version so you must create objects with app context. $object->setApplication($this); } @@ -310,8 +298,8 @@ public function save(Remote\Model $object, $replace_data = false) } //Put in an array with the first level containing only the 'root node'. - $data = [$object::getRootNodeName() => $object->toStringArray(true)]; - $url = new URL($this, $uri, $object::getAPIStem()); + $data = [$object::getRootNodeName() => $object->toStringArray(true)]; + $url = new URL($this, $uri, $object::getAPIStem()); $request = new Request($this, $url, $method); $request->setBody(Helpers::arrayToXML($data))->send(); @@ -327,13 +315,13 @@ public function save(Remote\Model $object, $replace_data = false) } /** - * @param array|Collection $objects - * @param mixed $checkGuid - * @param mixed $replace_data + * @param array|Collection $objects + * @param mixed $checkGuid + * @param mixed $replace_data * + * @return Remote\Response * @throws Exception * - * @return Remote\Response */ public function saveAll($objects, $checkGuid = true, $replace_data = false) { @@ -343,8 +331,8 @@ public function saveAll($objects, $checkGuid = true, $replace_data = false) $current_object = $objects[0]; /** @var $type Remote\Model */ - $type = get_class($current_object); - $has_guid = $checkGuid ? $current_object->hasGUID() : true; + $type = get_class($current_object); + $has_guid = $checkGuid ? $current_object->hasGUID() : true; $object_arrays = []; foreach ($objects as $object) { @@ -362,12 +350,12 @@ public function saveAll($objects, $checkGuid = true, $replace_data = false) $request_method = $has_guid ? Request::METHOD_POST : Request::METHOD_PUT; - $url = new URL($this, $type::getResourceURI(), $type::getAPIStem()); + $url = new URL($this, $type::getResourceURI(), $type::getAPIStem()); $request = new Request($this, $url, $request_method); //This might need to be parsed and stored some day. $root_node_name = Helpers::pluralize($type::getRootNodeName()); - $data = [$root_node_name => $object_arrays]; + $data = [$root_node_name => $object_arrays]; $request->setBody(Helpers::arrayToXML($data)); $request->setParameter('SummarizeErrors', 'false'); @@ -391,7 +379,7 @@ public function saveAll($objects, $checkGuid = true, $replace_data = false) * This is called automatically from the save method for things like * adding contacts to ContactGroups * - * @param Remote\Model $object + * @param Remote\Model $object * * @throws Exception */ @@ -404,7 +392,7 @@ private function savePropertiesDirectly(Remote\Model $object) /** @var Remote\Model $property_type */ $property_type = get_class(current($property_objects->getArrayCopy())); - $url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI())); + $url = new URL($this, sprintf('%s/%s/%s', $object::getResourceURI(), $object->getGUID(), $property_type::getResourceURI())); $request = new Request($this, $url, Request::METHOD_PUT); $property_array = []; @@ -433,11 +421,11 @@ private function savePropertiesDirectly(Remote\Model $object) } /** - * @param Remote\Model $object + * @param Remote\Model $object * + * @return Remote\Model * @throws Exception * - * @return Remote\Model */ public function delete(Remote\Model $object) { @@ -450,9 +438,9 @@ public function delete(Remote\Model $object) ); } - $uri = sprintf('%s/%s', $object::getResourceURI(), $object->getGUID()); - $url = new URL($this, $uri); - $request = new Request($this, $url, Request::METHOD_DELETE); + $uri = sprintf('%s/%s', $object::getResourceURI(), $object->getGUID()); + $url = new URL($this, $uri); + $request = new Request($this, $url, Request::METHOD_DELETE); $response = $request->send(); if (false !== $element = current($response->getElements())) { @@ -462,18 +450,18 @@ public function delete(Remote\Model $object) return $object; } - public function updateAppRateLimit(int $appMinLimitRemining) + public function updateAppRateLimit(int $appMinLimitRemaining) { - $this->lastApiCall = time(); - $this->appMinLimitRemining = $appMinLimitRemining; + $this->lastApiCall = time(); + $this->appMinLimitRemaining = $appMinLimitRemaining; return $this; } - public function updateTenantRateLimits(int $tenantDayLimitRemining, int $tenantMinLimitRemining) + public function updateTenantRateLimits(int $tenantDayLimitRemaining, int $tenantMinLimitRemaining) { - $this->lastApiCall = time(); - $this->tenantDayLimitRemining = $tenantDayLimitRemining; - $this->tenantMinLimitRemining = $tenantMinLimitRemining; + $this->lastApiCall = time(); + $this->tenantDayLimitRemaining = $tenantDayLimitRemaining; + $this->tenantMinLimitRemaining = $tenantMinLimitRemaining; return $this; } @@ -488,24 +476,24 @@ public function getLastApiCall(): ?int /** * @return int|null Application call limit remaining across all tenants. */ - public function getAppMinLimitRemining(): ?int + public function getAppMinLimitRemaining(): ?int { - return $this->appMinLimitRemining; + return $this->appMinLimitRemaining; } /** * @return int|null Tenant daily call limit remaining */ - public function getTenantDayLimitRemining(): ?int + public function getTenantDayLimitRemaining(): ?int { - return $this->tenantDayLimitRemining; + return $this->tenantDayLimitRemaining; } /** * @return int|null Tenant minute call limit remaining */ - public function getTenantMinLimitRemining(): ?int + public function getTenantMinLimitRemaining(): ?int { - return $this->tenantMinLimitRemining; + return $this->tenantMinLimitRemaining; } } diff --git a/src/XeroPHP/Models/Accounting/Account.php b/src/XeroPHP/Models/Accounting/Account.php index e17db7b1..26a7b56e 100644 --- a/src/XeroPHP/Models/Accounting/Account.php +++ b/src/XeroPHP/Models/Accounting/Account.php @@ -5,6 +5,38 @@ use XeroPHP\Remote; use XeroPHP\Traits\AttachmentTrait; +/** + * @method string getCode() + * @method self setCode(string $value) + * @method string getName() + * @method self setName(string $value) + * @method string getType() + * @method self setType(string $value) + * @method string getBankAccountNumber() + * @method self setBankAccountNumber(string $value) + * @method string getStatus() + * @method self setStatus(string $value) + * @method string getDescription() + * @method self setDescription(string $value) + * @method string getBankAccountType() + * @method self setBankAccountType(string $value) + * @method string getCurrencyCode() + * @method self setCurrencyCode(string $value) + * @method string getTaxType() + * @method self setTaxType(string $value) + * @method bool getEnablePaymentsToAccount() + * @method self setEnablePaymentsToAccount(bool $value) + * @method bool getShowInExpenseClaims() + * @method self setShowInExpenseClaims(bool $value) + * @method string getAccountID() + * @method self setAccountID(string $value) + * @method string getClass() + * @method string getSystemAccount() + * @method string getReportingCode() + * @method string getReportingCodeName() + * @method bool getHasAttachments() + * @method \DateTimeInterface getUpdatedDateUTC() + */ class Account extends Remote\Model { use AttachmentTrait; @@ -211,40 +243,32 @@ class Account extends Remote\Model /** * Get the resource uri of the class (Contacts) etc. - * - * @return string */ - public static function getResourceURI() + public static function getResourceURI(): string { return 'Accounts'; } /** * Get the root node name. Just the unqualified classname. - * - * @return string */ - public static function getRootNodeName() + public static function getRootNodeName(): string { return 'Account'; } /** * Get the guid property. - * - * @return string */ - public static function getGUIDProperty() + public static function getGUIDProperty(): string { return 'AccountID'; } /** * Get the stem of the API (core.xro) etc. - * - * @return string */ - public static function getAPIStem() + public static function getAPIStem(): string { return Remote\URL::API_CORE; } @@ -252,7 +276,7 @@ public static function getAPIStem() /** * Get the supported methods. */ - public static function getSupportedMethods() + public static function getSupportedMethods(): array { return [ Remote\Request::METHOD_GET, @@ -269,335 +293,41 @@ public static function getSupportedMethods() * [2] - PHP type * [3] - Is an Array * [4] - Saves directly. - * - * @return array */ - public static function getProperties() + public static function getProperties(): array { return [ - 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Type' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], - 'BankAccountNumber' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Status' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], - 'Description' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'BankAccountType' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], - 'CurrencyCode' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'TaxType' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Type' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'BankAccountNumber' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Status' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'Description' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'BankAccountType' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'CurrencyCode' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'TaxType' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], 'EnablePaymentsToAccount' => [false, self::PROPERTY_TYPE_BOOLEAN, null, false, false], - 'ShowInExpenseClaims' => [false, self::PROPERTY_TYPE_BOOLEAN, null, false, false], - 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Class' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], - 'SystemAccount' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], - 'ReportingCode' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'ReportingCodeName' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'HasAttachments' => [false, self::PROPERTY_TYPE_BOOLEAN, null, false, false], - 'UpdatedDateUTC' => [false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTimeInterface', false, false], + 'ShowInExpenseClaims' => [false, self::PROPERTY_TYPE_BOOLEAN, null, false, false], + 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Class' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'SystemAccount' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'ReportingCode' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'ReportingCodeName' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'HasAttachments' => [false, self::PROPERTY_TYPE_BOOLEAN, null, false, false], + 'UpdatedDateUTC' => [false, self::PROPERTY_TYPE_TIMESTAMP, '\\DateTimeInterface', false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } /** - * @return string - */ - public function getCode() - { - return $this->_data['Code']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setCode($value) - { - $this->propertyUpdated('Code', $value); - $this->_data['Code'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getName() - { - return $this->_data['Name']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setName($value) - { - $this->propertyUpdated('Name', $value); - $this->_data['Name'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getType() - { - return $this->_data['Type']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setType($value) - { - $this->propertyUpdated('Type', $value); - $this->_data['Type'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getBankAccountNumber() - { - return $this->_data['BankAccountNumber']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setBankAccountNumber($value) - { - $this->propertyUpdated('BankAccountNumber', $value); - $this->_data['BankAccountNumber'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getStatus() - { - return $this->_data['Status']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setStatus($value) - { - $this->propertyUpdated('Status', $value); - $this->_data['Status'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getDescription() - { - return $this->_data['Description']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setDescription($value) - { - $this->propertyUpdated('Description', $value); - $this->_data['Description'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getBankAccountType() - { - return $this->_data['BankAccountType']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setBankAccountType($value) - { - $this->propertyUpdated('BankAccountType', $value); - $this->_data['BankAccountType'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getCurrencyCode() - { - return $this->_data['CurrencyCode']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setCurrencyCode($value) - { - $this->propertyUpdated('CurrencyCode', $value); - $this->_data['CurrencyCode'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getTaxType() - { - return $this->_data['TaxType']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setTaxType($value) - { - $this->propertyUpdated('TaxType', $value); - $this->_data['TaxType'] = $value; - - return $this; - } - - /** - * @return bool - */ - public function getEnablePaymentsToAccount() - { - return $this->_data['EnablePaymentsToAccount']; - } - - /** - * @param bool $value - * - * @return Account - */ - public function setEnablePaymentsToAccount($value) - { - $this->propertyUpdated('EnablePaymentsToAccount', $value); - $this->_data['EnablePaymentsToAccount'] = $value; - - return $this; - } - - /** - * @return bool - */ - public function getShowInExpenseClaims() - { - return $this->_data['ShowInExpenseClaims']; - } - - /** - * @param bool $value - * - * @return Account - */ - public function setShowInExpenseClaim($value) - { - $this->propertyUpdated('ShowInExpenseClaims', $value); - $this->_data['ShowInExpenseClaims'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getAccountID() - { - return $this->_data['AccountID']; - } - - /** - * @param string $value - * - * @return Account - */ - public function setAccountID($value) - { - $this->propertyUpdated('AccountID', $value); - $this->_data['AccountID'] = $value; - - return $this; - } - - /** - * @return string - */ - public function getClass() - { - return $this->_data['Class']; - } - - /** - * @return string - */ - public function getSystemAccount() - { - return $this->_data['SystemAccount']; - } - - /** - * @return string - */ - public function getReportingCode() - { - return $this->_data['ReportingCode']; - } - - /** - * @return string - */ - public function getReportingCodeName() - { - return $this->_data['ReportingCodeName']; - } - - /** - * @return bool - */ - public function getHasAttachments() - { - return $this->_data['HasAttachments']; - } - - /** - * @return \DateTimeInterface + * @deprecated */ - public function getUpdatedDateUTC() + public function setShowInExpenseClaim(bool $value): static { - return $this->_data['UpdatedDateUTC']; + return $this->setShowInExpenseClaims($value); } } diff --git a/src/XeroPHP/Models/Accounting/Address.php b/src/XeroPHP/Models/Accounting/Address.php index c2658d1f..03104005 100644 --- a/src/XeroPHP/Models/Accounting/Address.php +++ b/src/XeroPHP/Models/Accounting/Address.php @@ -131,16 +131,16 @@ public static function getSupportedMethods() public static function getProperties() { return [ - 'AddressType' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'AddressType' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], 'AddressLine1' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'AddressLine2' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'AddressLine3' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'AddressLine4' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'City' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Region' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'PostalCode' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Country' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'AttentionTo' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'City' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Region' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'PostalCode' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Country' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'AttentionTo' => [false, self::PROPERTY_TYPE_STRING, null, false, false], ]; } @@ -157,12 +157,7 @@ public function getAddressType() return $this->_data['AddressType']; } - /** - * @param string $value - * - * @return Address - */ - public function setAddressType($value) + public function setAddressType(string $value): static { $this->propertyUpdated('AddressType', $value); $this->_data['AddressType'] = $value; @@ -170,20 +165,12 @@ public function setAddressType($value) return $this; } - /** - * @return string - */ - public function getAddressLine1() + public function getAddressLine1(): string { return $this->_data['AddressLine1']; } - /** - * @param string $value - * - * @return Address - */ - public function setAddressLine1($value) + public function setAddressLine1(string $value): static { $this->propertyUpdated('AddressLine1', $value); $this->_data['AddressLine1'] = $value; @@ -191,20 +178,12 @@ public function setAddressLine1($value) return $this; } - /** - * @return string - */ - public function getAddressLine2() + protected function getAddressLine2(): string { return $this->_data['AddressLine2']; } - /** - * @param string $value - * - * @return Address - */ - public function setAddressLine2($value) + public function setAddressLine2(string $value): static { $this->propertyUpdated('AddressLine2', $value); $this->_data['AddressLine2'] = $value; @@ -212,20 +191,12 @@ public function setAddressLine2($value) return $this; } - /** - * @return string - */ - public function getAddressLine3() + public function getAddressLine3(): string { return $this->_data['AddressLine3']; } - /** - * @param string $value - * - * @return Address - */ - public function setAddressLine3($value) + public function setAddressLine3(string $value): static { $this->propertyUpdated('AddressLine3', $value); $this->_data['AddressLine3'] = $value; @@ -233,20 +204,12 @@ public function setAddressLine3($value) return $this; } - /** - * @return string - */ - public function getAddressLine4() + public function getAddressLine4(): string { return $this->_data['AddressLine4']; } - /** - * @param string $value - * - * @return Address - */ - public function setAddressLine4($value) + public function setAddressLine4(string $value): static { $this->propertyUpdated('AddressLine4', $value); $this->_data['AddressLine4'] = $value; @@ -254,20 +217,12 @@ public function setAddressLine4($value) return $this; } - /** - * @return string - */ - public function getCity() + public function getCity(): string { return $this->_data['City']; } - /** - * @param string $value - * - * @return Address - */ - public function setCity($value) + public function setCity(string $value): static { $this->propertyUpdated('City', $value); $this->_data['City'] = $value; @@ -275,20 +230,12 @@ public function setCity($value) return $this; } - /** - * @return string - */ - public function getRegion() + public function getRegion(): string { return $this->_data['Region']; } - /** - * @param string $value - * - * @return Address - */ - public function setRegion($value) + public function setRegion(string $value): static { $this->propertyUpdated('Region', $value); $this->_data['Region'] = $value; @@ -296,20 +243,12 @@ public function setRegion($value) return $this; } - /** - * @return string - */ - public function getPostalCode() + public function getPostalCode(): string { return $this->_data['PostalCode']; } - /** - * @param string $value - * - * @return Address - */ - public function setPostalCode($value) + public function setPostalCode(string $value): static { $this->propertyUpdated('PostalCode', $value); $this->_data['PostalCode'] = $value; @@ -317,20 +256,12 @@ public function setPostalCode($value) return $this; } - /** - * @return string - */ - public function getCountry() + public function getCountry(): string { return $this->_data['Country']; } - /** - * @param string $value - * - * @return Address - */ - public function setCountry($value) + public function setCountry(string $value): static { $this->propertyUpdated('Country', $value); $this->_data['Country'] = $value; @@ -338,20 +269,12 @@ public function setCountry($value) return $this; } - /** - * @return string - */ - public function getAttentionTo() + public function getAttentionTo(): string { return $this->_data['AttentionTo']; } - /** - * @param string $value - * - * @return Address - */ - public function setAttentionTo($value) + public function setAttentionTo(string $value): static { $this->propertyUpdated('AttentionTo', $value); $this->_data['AttentionTo'] = $value; diff --git a/src/XeroPHP/Models/Accounting/Attachment.php b/src/XeroPHP/Models/Accounting/Attachment.php index d5636879..79568606 100644 --- a/src/XeroPHP/Models/Accounting/Attachment.php +++ b/src/XeroPHP/Models/Accounting/Attachment.php @@ -35,10 +35,8 @@ class Attachment extends Model /** * Actual file content (binary). - * - * @var string */ - private $content; + private string $content; private $local_handle; diff --git a/src/XeroPHP/Models/Accounting/BankTransaction/BankAccount.php b/src/XeroPHP/Models/Accounting/BankTransaction/BankAccount.php index 736ae3ac..d9a35750 100644 --- a/src/XeroPHP/Models/Accounting/BankTransaction/BankAccount.php +++ b/src/XeroPHP/Models/Accounting/BankTransaction/BankAccount.php @@ -20,40 +20,32 @@ class BankAccount extends Remote\Model /** * Get the resource uri of the class (Contacts) etc. - * - * @return string */ - public static function getResourceURI() + public static function getResourceURI(): string { return 'BankAccount'; } /** * Get the root node name. Just the unqualified classname. - * - * @return string */ - public static function getRootNodeName() + public static function getRootNodeName(): string { return 'BankAccount'; } /** * Get the guid property. - * - * @return string */ - public static function getGUIDProperty() + public static function getGUIDProperty(): string { return ''; } /** * Get the stem of the API (core.xro) etc. - * - * @return string */ - public static function getAPIStem() + public static function getAPIStem(): string { return Remote\URL::API_CORE; } @@ -61,10 +53,9 @@ public static function getAPIStem() /** * Get the supported methods. */ - public static function getSupportedMethods() + public static function getSupportedMethods(): array { - return [ - ]; + return []; } /** @@ -74,36 +65,26 @@ public static function getSupportedMethods() * [2] - PHP type * [3] - Is an Array * [4] - Saves directly. - * - * @return array */ - public static function getProperties() + public static function getProperties(): array { return [ - 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } - /** - * @return string - */ - public function getCode() + public function getCode(): string { return $this->_data['Code']; } - /** - * @param string $value - * - * @return BankAccount - */ - public function setCode($value) + public function setCode(string $value): static { $this->propertyUpdated('Code', $value); $this->_data['Code'] = $value; @@ -111,20 +92,12 @@ public function setCode($value) return $this; } - /** - * @return string - */ - public function getAccountID() + public function getAccountID(): string { return $this->_data['AccountID']; } - /** - * @param string $value - * - * @return BankAccount - */ - public function setAccountID($value) + public function setAccountID(string $value): static { $this->propertyUpdated('AccountID', $value); $this->_data['AccountID'] = $value; diff --git a/src/XeroPHP/Models/Accounting/BankTransaction/LineItem.php b/src/XeroPHP/Models/Accounting/BankTransaction/LineItem.php deleted file mode 100644 index 4d547b2f..00000000 --- a/src/XeroPHP/Models/Accounting/BankTransaction/LineItem.php +++ /dev/null @@ -1,11 +0,0 @@ - [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } - /** - * @return string - */ - public function getCode() + public function getCode(): string { return $this->_data['Code']; } - /** - * @param string $value - * - * @return FromBankAccount - */ - public function setCode($value) + public function setCode(string $value): static { $this->propertyUpdated('Code', $value); $this->_data['Code'] = $value; @@ -118,20 +99,12 @@ public function setCode($value) return $this; } - /** - * @return string - */ - public function getAccountID() + public function getAccountID(): string { return $this->_data['AccountID']; } - /** - * @param string $value - * - * @return FromBankAccount - */ - public function setAccountID($value) + public function setAccountID(string $value): static { $this->propertyUpdated('AccountID', $value); $this->_data['AccountID'] = $value; @@ -139,10 +112,7 @@ public function setAccountID($value) return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->_data['Name']; } diff --git a/src/XeroPHP/Models/Accounting/BankTransfer/ToBankAccount.php b/src/XeroPHP/Models/Accounting/BankTransfer/ToBankAccount.php index 3697de31..9b74890d 100644 --- a/src/XeroPHP/Models/Accounting/BankTransfer/ToBankAccount.php +++ b/src/XeroPHP/Models/Accounting/BankTransfer/ToBankAccount.php @@ -26,40 +26,32 @@ class ToBankAccount extends Remote\Model /** * Get the resource uri of the class (Contacts) etc. - * - * @return string */ - public static function getResourceURI() + public static function getResourceURI(): string { return 'ToBankAccount'; } /** * Get the root node name. Just the unqualified classname. - * - * @return string */ - public static function getRootNodeName() + public static function getRootNodeName(): string { return 'ToBankAccount'; } /** * Get the guid property. - * - * @return string */ - public static function getGUIDProperty() + public static function getGUIDProperty(): string { return ''; } /** * Get the stem of the API (core.xro) etc. - * - * @return string */ - public static function getAPIStem() + public static function getAPIStem(): string { return Remote\URL::API_CORE; } @@ -67,10 +59,9 @@ public static function getAPIStem() /** * Get the supported methods. */ - public static function getSupportedMethods() + public static function getSupportedMethods(): array { - return [ - ]; + return []; } /** @@ -80,37 +71,27 @@ public static function getSupportedMethods() * [2] - PHP type * [3] - Is an Array * [4] - Saves directly. - * - * @return array */ - public static function getProperties() + public static function getProperties(): array { return [ - 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } - /** - * @return string - */ - public function getCode() + public function getCode(): string { return $this->_data['Code']; } - /** - * @param string $value - * - * @return ToBankAccount - */ - public function setCode($value) + public function setCode(string $value): static { $this->propertyUpdated('Code', $value); $this->_data['Code'] = $value; @@ -118,20 +99,12 @@ public function setCode($value) return $this; } - /** - * @return string - */ - public function getAccountID() + public function getAccountID(): string { return $this->_data['AccountID']; } - /** - * @param string $value - * - * @return ToBankAccount - */ - public function setAccountID($value) + public function setAccountID(string $value): static { $this->propertyUpdated('AccountID', $value); $this->_data['AccountID'] = $value; @@ -139,10 +112,7 @@ public function setAccountID($value) return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->_data['Name']; } diff --git a/src/XeroPHP/Models/Accounting/BatchPayment.php b/src/XeroPHP/Models/Accounting/BatchPayment.php index 42c3dec8..ed5f1cc6 100644 --- a/src/XeroPHP/Models/Accounting/BatchPayment.php +++ b/src/XeroPHP/Models/Accounting/BatchPayment.php @@ -271,15 +271,6 @@ public function setDate(\DateTimeInterface $value) return $this; } - /** - * @return Payment[]|Remote\Collection - * @deprecated Use `getPayments()` instead. This is a typo - */ - public function getPayment() - { - return $this->getPayments(); - } - /** * @param Payment $value * @return BatchPayment diff --git a/src/XeroPHP/Models/Accounting/Contact.php b/src/XeroPHP/Models/Accounting/Contact.php index 3d95175b..f7448ee3 100644 --- a/src/XeroPHP/Models/Accounting/Contact.php +++ b/src/XeroPHP/Models/Accounting/Contact.php @@ -586,18 +586,6 @@ public function setBankAccountDetails($value) return $this; } - /** - * @param string $value - * @deprecated Use setBankAccountDetails - * @return Contact - */ - public function setBankAccountDetail($value) - { - $this->setBankAccountDetails($value); - - return $this; - } - /** * @return string */ @@ -738,15 +726,6 @@ public function getIsSupplier() return $this->_data['IsSupplier']; } - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setIsSupplier($value) - { - } - /** * @return bool */ @@ -755,14 +734,6 @@ public function getIsCustomer() return $this->_data['IsCustomer']; } - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setIsCustomer($value) - { - } /** * @return string @@ -1156,13 +1127,4 @@ public function getHasAttachments() { return $this->_data['HasAttachments']; } - - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setHasAttachment($value) - { - } } diff --git a/src/XeroPHP/Models/Accounting/Contact/ContactPerson.php b/src/XeroPHP/Models/Accounting/Contact/ContactPerson.php index 81717795..6a4eb82a 100644 --- a/src/XeroPHP/Models/Accounting/Contact/ContactPerson.php +++ b/src/XeroPHP/Models/Accounting/Contact/ContactPerson.php @@ -32,40 +32,32 @@ class ContactPerson extends Remote\Model /** * Get the resource uri of the class (Contacts) etc. - * - * @return string */ - public static function getResourceURI() + public static function getResourceURI(): string { return 'ContactPerson'; } /** * Get the root node name. Just the unqualified classname. - * - * @return string */ - public static function getRootNodeName() + public static function getRootNodeName(): string { return 'ContactPerson'; } /** * Get the guid property. - * - * @return string */ - public static function getGUIDProperty() + public static function getGUIDProperty(): string { return ''; } /** * Get the stem of the API (core.xro) etc. - * - * @return string */ - public static function getAPIStem() + public static function getAPIStem(): string { return Remote\URL::API_CORE; } @@ -73,10 +65,9 @@ public static function getAPIStem() /** * Get the supported methods. */ - public static function getSupportedMethods() + public static function getSupportedMethods(): array { - return [ - ]; + return []; } /** @@ -86,38 +77,28 @@ public static function getSupportedMethods() * [2] - PHP type * [3] - Is an Array * [4] - Saves directly. - * - * @return array */ - public static function getProperties() + public static function getProperties(): array { return [ - 'FirstName' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'LastName' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'EmailAddress' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'FirstName' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'LastName' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'EmailAddress' => [false, self::PROPERTY_TYPE_STRING, null, false, false], 'IncludeInEmails' => [false, self::PROPERTY_TYPE_BOOLEAN, null, false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } - /** - * @return string - */ - public function getFirstName() + public function getFirstName(): string { return $this->_data['FirstName']; } - /** - * @param string $value - * - * @return ContactPerson - */ - public function setFirstName($value) + public function setFirstName(string $value): static { $this->propertyUpdated('FirstName', $value); $this->_data['FirstName'] = $value; @@ -125,19 +106,11 @@ public function setFirstName($value) return $this; } - /** - * @return string - */ - public function getLastName() + public function getLastName(): string { return $this->_data['LastName']; } - /** - * @param string $value - * - * @return ContactPerson - */ public function setLastName($value) { $this->propertyUpdated('LastName', $value); @@ -155,7 +128,7 @@ public function getEmailAddress() } /** - * @param string $value + * @param string $value * * @return ContactPerson */ @@ -176,7 +149,7 @@ public function getIncludeInEmails() } /** - * @param bool $value + * @param bool $value * * @return ContactPerson */ diff --git a/src/XeroPHP/Models/Accounting/CreditNote.php b/src/XeroPHP/Models/Accounting/CreditNote.php index 61e98845..287d8df3 100644 --- a/src/XeroPHP/Models/Accounting/CreditNote.php +++ b/src/XeroPHP/Models/Accounting/CreditNote.php @@ -691,13 +691,4 @@ public function getHasAttachments() { return $this->_data['HasAttachments']; } - - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setHasAttachment($value) - { - } } diff --git a/src/XeroPHP/Models/Accounting/Currency.php b/src/XeroPHP/Models/Accounting/Currency.php index 312fb3d2..1da66b03 100644 --- a/src/XeroPHP/Models/Accounting/Currency.php +++ b/src/XeroPHP/Models/Accounting/Currency.php @@ -6,14 +6,6 @@ class Currency extends Remote\Model { - /** - * This property has been removed from the Xero API. - * - * @property string ModifiedAfter - * - * @deprecated - */ - /** * 3 letter alpha code for the currency – see list of currency codes. * @@ -101,31 +93,6 @@ public static function isPageable() return false; } - /** - * @return string - * - * @deprecated - */ - public function getModifiedAfter() - { - return $this->_data['ModifiedAfter']; - } - - /** - * @param string $value - * - * @return Currency - * - * @deprecated - */ - public function setModifiedAfter($value) - { - $this->propertyUpdated('ModifiedAfter', $value); - $this->_data['ModifiedAfter'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/Accounting/Invoice.php b/src/XeroPHP/Models/Accounting/Invoice.php index 4ee53b10..e058f8d3 100644 --- a/src/XeroPHP/Models/Accounting/Invoice.php +++ b/src/XeroPHP/Models/Accounting/Invoice.php @@ -229,21 +229,6 @@ class Invoice extends Remote\Model const INVOICE_STATUS_VOIDED = 'VOIDED'; - /** - * @deprecated Use \XeroPHP\Models\Accounting\LineItem::TYPE_EXCLUSIVE instead. - */ - const LINEAMOUNT_TYPE_EXCLUSIVE = 'Exclusive'; - - /** - * @deprecated Use \XeroPHP\Models\Accounting\LineItem::TYPE_INCLUSIVE instead. - */ - const LINEAMOUNT_TYPE_INCLUSIVE = 'Inclusive'; - - /** - * @deprecated Use \XeroPHP\Models\Accounting\LineItem::TYPE_NOTAX instead. - */ - const LINEAMOUNT_TYPE_NOTAX = 'NoTax'; - /** * Get the resource uri of the class (Contacts) etc. * diff --git a/src/XeroPHP/Models/Accounting/Invoice/LineItem.php b/src/XeroPHP/Models/Accounting/Invoice/LineItem.php deleted file mode 100644 index 1844316a..00000000 --- a/src/XeroPHP/Models/Accounting/Invoice/LineItem.php +++ /dev/null @@ -1,11 +0,0 @@ -_data['SalesDetails']; } - /** - * @param Sale $value - * - * @return Item - * - * @deprecated - */ - public function addSalesDetail(Sale $value) - { - } - /** * @param Sale $value * diff --git a/src/XeroPHP/Models/Accounting/Item/Purchase.php b/src/XeroPHP/Models/Accounting/Item/Purchase.php index cc92946e..d81530a1 100644 --- a/src/XeroPHP/Models/Accounting/Item/Purchase.php +++ b/src/XeroPHP/Models/Accounting/Item/Purchase.php @@ -26,14 +26,6 @@ class Purchase extends Remote\Model * @property string COGSAccountCode */ - /** - * This property has been removed from the Xero API. - * - * @property \DateTimeInterface UpdatedDateUTC - * - * @deprecated - */ - /** * Used as an override if the default Tax Code for the selected is not correct – see * TaxTypes. @@ -179,31 +171,6 @@ public function setCOGSAccountCode($value) return $this; } - /** - * @return \DateTimeInterface - * - * @deprecated - */ - public function getUpdatedDateUTC() - { - return $this->_data['UpdatedDateUTC']; - } - - /** - * @param \DateTimeInterface $value - * - * @return Purchase - * - * @deprecated - */ - public function setUpdatedDateUTC(\DateTimeInterface $value) - { - $this->propertyUpdated('UpdatedDateUTC', $value); - $this->_data['UpdatedDateUTC'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/Accounting/Item/Sale.php b/src/XeroPHP/Models/Accounting/Item/Sale.php index b02043dd..a85cd3ed 100644 --- a/src/XeroPHP/Models/Accounting/Item/Sale.php +++ b/src/XeroPHP/Models/Accounting/Item/Sale.php @@ -26,14 +26,6 @@ class Sale extends Remote\Model * @property string COGSAccountCode */ - /** - * This property has been removed from the Xero API. - * - * @property \DateTimeInterface UpdatedDateUTC - * - * @deprecated - */ - /** * Used as an override if the default Tax Code for the selected is not correct – see * TaxTypes. @@ -179,31 +171,6 @@ public function setCOGSAccountCode($value) return $this; } - /** - * @return \DateTimeInterface - * - * @deprecated - */ - public function getUpdatedDateUTC() - { - return $this->_data['UpdatedDateUTC']; - } - - /** - * @param \DateTimeInterface $value - * - * @return Sale - * - * @deprecated - */ - public function setUpdatedDateUTC(\DateTimeInterface $value) - { - $this->propertyUpdated('UpdatedDateUTC', $value); - $this->_data['UpdatedDateUTC'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/Accounting/Overpayment.php b/src/XeroPHP/Models/Accounting/Overpayment.php index cac8ab90..5969fbbd 100644 --- a/src/XeroPHP/Models/Accounting/Overpayment.php +++ b/src/XeroPHP/Models/Accounting/Overpayment.php @@ -13,14 +13,6 @@ class Overpayment extends Remote\Model use AttachmentTrait; use HistoryTrait; - /** - * This property has been removed from the Xero API. - * - * @property string Reference - * - * @deprecated - */ - /** * See Overpayment Types. * @@ -87,14 +79,6 @@ class Overpayment extends Remote\Model * @property string CurrencyCode */ - /** - * This property has been removed from the Xero API. - * - * @property string FullyPaidOnDate - * - * @deprecated - */ - /** * Xero generated unique identifier. * @@ -233,31 +217,6 @@ public static function isPageable() return true; } - /** - * @return string - * - * @deprecated - */ - public function getReference() - { - return $this->_data['Reference']; - } - - /** - * @param string $value - * - * @return Overpayment - * - * @deprecated - */ - public function setReference($value) - { - $this->propertyUpdated('Reference', $value); - $this->_data['Reference'] = $value; - - return $this; - } - /** * @return string */ @@ -492,31 +451,6 @@ public function setCurrencyCode($value) return $this; } - /** - * @return string - * - * @deprecated - */ - public function getFullyPaidOnDate() - { - return $this->_data['FullyPaidOnDate']; - } - - /** - * @param string $value - * - * @return Overpayment - * - * @deprecated - */ - public function setFullyPaidOnDate($value) - { - $this->propertyUpdated('FullyPaidOnDate', $value); - $this->_data['FullyPaidOnDate'] = $value; - - return $this; - } - /** * @return string */ @@ -644,12 +578,4 @@ public function getHasAttachments() return $this->_data['HasAttachments']; } - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setHasAttachment($value) - { - } } diff --git a/src/XeroPHP/Models/Accounting/Overpayment/Allocation.php b/src/XeroPHP/Models/Accounting/Overpayment/Allocation.php index 391a2a4b..e93a5127 100644 --- a/src/XeroPHP/Models/Accounting/Overpayment/Allocation.php +++ b/src/XeroPHP/Models/Accounting/Overpayment/Allocation.php @@ -2,8 +2,8 @@ namespace XeroPHP\Models\Accounting\Overpayment; -use XeroPHP\Remote; use XeroPHP\Models\Accounting\Invoice; +use XeroPHP\Remote; class Allocation extends Remote\Model { @@ -28,40 +28,32 @@ class Allocation extends Remote\Model /** * Get the resource uri of the class (Contacts) etc. - * - * @return string */ - public static function getResourceURI() + public static function getResourceURI(): string { return 'Allocations'; } /** * Get the root node name. Just the unqualified classname. - * - * @return string */ - public static function getRootNodeName() + public static function getRootNodeName(): string { return 'Allocation'; } /** * Get the guid property. - * - * @return string */ - public static function getGUIDProperty() + public static function getGUIDProperty(): string { return ''; } /** * Get the stem of the API (core.xro) etc. - * - * @return string */ - public static function getAPIStem() + public static function getAPIStem(): string { return Remote\URL::API_CORE; } @@ -69,10 +61,9 @@ public static function getAPIStem() /** * Get the supported methods. */ - public static function getSupportedMethods() + public static function getSupportedMethods(): array { - return [ - ]; + return []; } /** @@ -82,37 +73,27 @@ public static function getSupportedMethods() * [2] - PHP type * [3] - Is an Array * [4] - Saves directly. - * - * @return array */ - public static function getProperties() + public static function getProperties(): array { return [ - 'Invoice' => [false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\Invoice', false, false], + 'Invoice' => [false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\Invoice', false, false], 'AppliedAmount' => [false, self::PROPERTY_TYPE_FLOAT, null, false, false], - 'Date' => [false, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false], + 'Date' => [false, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } - /** - * @return Invoice - */ - public function getInvoice() + public function getInvoice(): Invoice { return $this->_data['Invoice']; } - /** - * @param Invoice $value - * - * @return Allocation - */ - public function setInvoice(Invoice $value) + public function setInvoice(Invoice $value): static { $this->propertyUpdated('Invoice', $value); $this->_data['Invoice'] = $value; @@ -120,20 +101,12 @@ public function setInvoice(Invoice $value) return $this; } - /** - * @return float - */ - public function getAppliedAmount() + public function getAppliedAmount(): float { return $this->_data['AppliedAmount']; } - /** - * @param float $value - * - * @return Allocation - */ - public function setAppliedAmount($value) + public function setAppliedAmount(float $value): static { $this->propertyUpdated('AppliedAmount', $value); $this->_data['AppliedAmount'] = $value; @@ -141,20 +114,12 @@ public function setAppliedAmount($value) return $this; } - /** - * @return \DateTimeInterface - */ - public function getDate() + public function getDate(): \DateTimeInterface { return $this->_data['Date']; } - /** - * @param \DateTimeInterface $value - * - * @return Allocation - */ - public function setDate(\DateTimeInterface $value) + public function setDate(\DateTimeInterface $value): static { $this->propertyUpdated('Date', $value); $this->_data['Date'] = $value; diff --git a/src/XeroPHP/Models/Accounting/Overpayment/LineItem.php b/src/XeroPHP/Models/Accounting/Overpayment/LineItem.php deleted file mode 100644 index 176966de..00000000 --- a/src/XeroPHP/Models/Accounting/Overpayment/LineItem.php +++ /dev/null @@ -1,11 +0,0 @@ -_data['Reference']; - } - - /** - * @param string $value - * - * @return Prepayment - * - * @deprecated - */ - public function setReference($value) - { - $this->propertyUpdated('Reference', $value); - $this->_data['Reference'] = $value; - - return $this; - } - /** * @return string */ @@ -485,31 +444,6 @@ public function setCurrencyCode($value) return $this; } - /** - * @return string - * - * @deprecated - */ - public function getFullyPaidOnDate() - { - return $this->_data['FullyPaidOnDate']; - } - - /** - * @param string $value - * - * @return Prepayment - * - * @deprecated - */ - public function setFullyPaidOnDate($value) - { - $this->propertyUpdated('FullyPaidOnDate', $value); - $this->_data['FullyPaidOnDate'] = $value; - - return $this; - } - /** * @return string */ @@ -612,13 +546,4 @@ public function getHasAttachments() { return $this->_data['HasAttachments']; } - - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setHasAttachment($value) - { - } } diff --git a/src/XeroPHP/Models/Accounting/Prepayment/Allocation.php b/src/XeroPHP/Models/Accounting/Prepayment/Allocation.php index 16434d79..b71553bd 100644 --- a/src/XeroPHP/Models/Accounting/Prepayment/Allocation.php +++ b/src/XeroPHP/Models/Accounting/Prepayment/Allocation.php @@ -2,8 +2,8 @@ namespace XeroPHP\Models\Accounting\Prepayment; -use XeroPHP\Remote; use XeroPHP\Models\Accounting\Invoice; +use XeroPHP\Remote; class Allocation extends Remote\Model { @@ -28,40 +28,32 @@ class Allocation extends Remote\Model /** * Get the resource uri of the class (Contacts) etc. - * - * @return string */ - public static function getResourceURI() + public static function getResourceURI(): string { return 'Allocations'; } /** * Get the root node name. Just the unqualified classname. - * - * @return string */ - public static function getRootNodeName() + public static function getRootNodeName(): string { return 'Allocation'; } /** * Get the guid property. - * - * @return string */ - public static function getGUIDProperty() + public static function getGUIDProperty(): string { return ''; } /** * Get the stem of the API (core.xro) etc. - * - * @return string */ - public static function getAPIStem() + public static function getAPIStem(): string { return Remote\URL::API_CORE; } @@ -69,10 +61,9 @@ public static function getAPIStem() /** * Get the supported methods. */ - public static function getSupportedMethods() + public static function getSupportedMethods(): array { - return [ - ]; + return []; } /** @@ -82,37 +73,27 @@ public static function getSupportedMethods() * [2] - PHP type * [3] - Is an Array * [4] - Saves directly. - * - * @return array */ - public static function getProperties() + public static function getProperties(): array { return [ - 'Invoice' => [false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\Invoice', false, false], + 'Invoice' => [false, self::PROPERTY_TYPE_OBJECT, 'Accounting\\Invoice', false, false], 'AppliedAmount' => [false, self::PROPERTY_TYPE_FLOAT, null, false, false], - 'Date' => [false, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false], + 'Date' => [false, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false], ]; } - public static function isPageable() + public static function isPageable(): bool { return false; } - /** - * @return Invoice - */ - public function getInvoice() + public function getInvoice(): Invoice { return $this->_data['Invoice']; } - /** - * @param Invoice $value - * - * @return Allocation - */ - public function setInvoice(Invoice $value) + public function setInvoice(Invoice $value): static { $this->propertyUpdated('Invoice', $value); $this->_data['Invoice'] = $value; @@ -120,20 +101,12 @@ public function setInvoice(Invoice $value) return $this; } - /** - * @return float - */ - public function getAppliedAmount() + public function getAppliedAmount(): float { return $this->_data['AppliedAmount']; } - /** - * @param float $value - * - * @return Allocation - */ - public function setAppliedAmount($value) + public function setAppliedAmount(float $value): static { $this->propertyUpdated('AppliedAmount', $value); $this->_data['AppliedAmount'] = $value; @@ -141,20 +114,12 @@ public function setAppliedAmount($value) return $this; } - /** - * @return \DateTimeInterface - */ - public function getDate() + public function getDate(): \DateTimeInterface { return $this->_data['Date']; } - /** - * @param \DateTimeInterface $value - * - * @return Allocation - */ - public function setDate(\DateTimeInterface $value) + public function setDate(\DateTimeInterface $value): static { $this->propertyUpdated('Date', $value); $this->_data['Date'] = $value; diff --git a/src/XeroPHP/Models/Accounting/Prepayment/LineItem.php b/src/XeroPHP/Models/Accounting/Prepayment/LineItem.php deleted file mode 100644 index aefa689c..00000000 --- a/src/XeroPHP/Models/Accounting/Prepayment/LineItem.php +++ /dev/null @@ -1,11 +0,0 @@ -_data['HasAttachments']; } - - /** - * @deprecated - this is a read only property and this method will be removed in future versions - * - * @param $value - */ - public function setHasAttachment($value) - { - } } diff --git a/src/XeroPHP/Models/Accounting/RepeatingInvoice/LineItem.php b/src/XeroPHP/Models/Accounting/RepeatingInvoice/LineItem.php deleted file mode 100644 index bce1db70..00000000 --- a/src/XeroPHP/Models/Accounting/RepeatingInvoice/LineItem.php +++ /dev/null @@ -1,11 +0,0 @@ -_data['Occupation']; - } - - /** - * @param string $value - * - * @return Employee - * - * @deprecated - */ - public function setOccupation($value) - { - $this->propertyUpdated('Occupation', $value); - $this->_data['Occupation'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/PayrollAU/Employee/TaxDeclaration.php b/src/XeroPHP/Models/PayrollAU/Employee/TaxDeclaration.php index 7aadaa6a..f3a9bdd7 100644 --- a/src/XeroPHP/Models/PayrollAU/Employee/TaxDeclaration.php +++ b/src/XeroPHP/Models/PayrollAU/Employee/TaxDeclaration.php @@ -60,14 +60,6 @@ class TaxDeclaration extends Remote\Model * @property bool HasSFSSDebt */ - /** - * This property has been removed from the Xero API. - * - * @property bool HasTSLDebt - * - * @deprecated - */ - /** * If employee has trade support loan. e.g true or false. * @@ -403,31 +395,6 @@ public function setHasSFSSDebt($value) return $this; } - /** - * @return bool - * - * @deprecated - */ - public function getHasTSLDebt() - { - return $this->_data['HasTSLDebt']; - } - - /** - * @param bool $value - * - * @return TaxDeclaration - * - * @deprecated - */ - public function setHasTSLDebt($value) - { - $this->propertyUpdated('HasTSLDebt', $value); - $this->_data['HasTSLDebt'] = $value; - - return $this; - } - /** * @return bool */ diff --git a/src/XeroPHP/Models/PayrollAU/PayItem/EarningsRate.php b/src/XeroPHP/Models/PayrollAU/PayItem/EarningsRate.php index 29ed2ac0..87506247 100644 --- a/src/XeroPHP/Models/PayrollAU/PayItem/EarningsRate.php +++ b/src/XeroPHP/Models/PayrollAU/PayItem/EarningsRate.php @@ -150,11 +150,6 @@ class EarningsRate extends Remote\Model const EARNINGSTYPE_WORKERSCOMPENSATION = 'WORKERSCOMPENSATION'; - /** - * @deprecated this Earning Type is no longer used - */ - const EARNINGSTYPE_FIXED = 'FIXED'; - /** * The rate's Rate Type * @@ -273,7 +268,7 @@ public function getName() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setName($value) { @@ -294,7 +289,7 @@ public function getAccountCode() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setAccountCode($value) { @@ -315,7 +310,7 @@ public function getTypeOfUnits() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setTypeOfUnit($value) { @@ -336,7 +331,7 @@ public function getIsExemptFromTax() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setIsExemptFromTax($value) { @@ -357,7 +352,7 @@ public function getIsExemptFromSuper() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setIsExemptFromSuper($value) { @@ -378,7 +373,7 @@ public function getAllowanceType() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setAllowanceType($value) { @@ -399,7 +394,7 @@ public function getEarningsType() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setEarningsType($value) { @@ -420,7 +415,7 @@ public function getEarningsRateID() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setEarningsRateID($value) { @@ -441,7 +436,7 @@ public function getRateType() /** * @param string $value * - * @return EarningsRate + * @return self */ public function setRateType($value) { @@ -462,7 +457,7 @@ public function getRatePerUnit() /** * @param float $value * - * @return EarningsRate + * @return self */ public function setRatePerUnit($value) { @@ -483,7 +478,7 @@ public function getMultiplier() /** * @param float $value * - * @return EarningsRate + * @return self */ public function setMultiplier($value) { @@ -504,7 +499,7 @@ public function getAccrueLeave() /** * @param bool $value * - * @return EarningsRate + * @return self */ public function setAccrueLeave($value) { @@ -525,7 +520,7 @@ public function getAmount() /** * @param float $value * - * @return EarningsRate + * @return self */ public function setAmount($value) { @@ -546,7 +541,7 @@ public function getCurrentRecord() /** * @param bool $value * - * @return EarningsRate + * @return self */ public function setCurrentRecord($value) { @@ -567,7 +562,7 @@ public function getEmploymentTerminationPaymentType() /** * @param string $value * - * @return EarningRate + * @return self */ public function setEmploymentTerminationPaymentType($value) { @@ -588,7 +583,7 @@ public function getAllowanceCategory() /** * @param string $value * - * @return EarningRate + * @return self */ public function setAllowanceCategory($value) { diff --git a/src/XeroPHP/Models/PayrollAU/Payslip/TimesheetEarningsLine.php b/src/XeroPHP/Models/PayrollAU/Payslip/TimesheetEarningsLine.php index feb9bb35..08d20f90 100644 --- a/src/XeroPHP/Models/PayrollAU/Payslip/TimesheetEarningsLine.php +++ b/src/XeroPHP/Models/PayrollAU/Payslip/TimesheetEarningsLine.php @@ -140,31 +140,6 @@ public function setRatePerUnit($value) return $this; } - /** - * @return Amount - * - * @deprecated - */ - public function getAmount() - { - return $this->_data['Amount']; - } - - /** - * @param float $value - * - * @return TimesheetEarningsLine - * - * @deprecated - */ - public function setAmount($value) - { - $this->propertyUpdated('Amount', $value); - $this->_data['Amount'] = $value; - - return $this; - } - /** * @return float */ diff --git a/src/XeroPHP/Models/PayrollAU/Setting/Account.php b/src/XeroPHP/Models/PayrollAU/Setting/Account.php index c6481b2b..6941d891 100644 --- a/src/XeroPHP/Models/PayrollAU/Setting/Account.php +++ b/src/XeroPHP/Models/PayrollAU/Setting/Account.php @@ -93,9 +93,9 @@ public static function getProperties() { return [ 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Type' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], - 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Type' => [false, self::PROPERTY_TYPE_ENUM, null, false, false], + 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], ]; } @@ -112,12 +112,7 @@ public function getAccountID() return $this->_data['AccountID']; } - /** - * @param string $value - * - * @return Account - */ - public function setAccountID($value) + public function setAccountID(string $value): static { $this->propertyUpdated('AccountID', $value); $this->_data['AccountID'] = $value; @@ -125,20 +120,12 @@ public function setAccountID($value) return $this; } - /** - * @return string - */ - public function getType() + public function getType(): string { return $this->_data['Type']; } - /** - * @param string $value - * - * @return Account - */ - public function setType($value) + public function setType(string $value): static { $this->propertyUpdated('Type', $value); $this->_data['Type'] = $value; @@ -146,20 +133,12 @@ public function setType($value) return $this; } - /** - * @return string - */ - public function getCode() + public function getCode(): string { return $this->_data['Code']; } - /** - * @param string $value - * - * @return Account - */ - public function setCode($value) + public function setCode(string $value): static { $this->propertyUpdated('Code', $value); $this->_data['Code'] = $value; @@ -167,20 +146,12 @@ public function setCode($value) return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->_data['Name']; } - /** - * @param string $value - * - * @return Account - */ - public function setName($value) + public function setName(string $value): static { $this->propertyUpdated('Name', $value); $this->_data['Name'] = $value; diff --git a/src/XeroPHP/Models/PayrollAU/SuperFund.php b/src/XeroPHP/Models/PayrollAU/SuperFund.php index 6abb11ab..d143ca19 100644 --- a/src/XeroPHP/Models/PayrollAU/SuperFund.php +++ b/src/XeroPHP/Models/PayrollAU/SuperFund.php @@ -304,31 +304,6 @@ public function setEmployerNumber($value) return $this; } - /** - * @return string - * - * @deprecated - */ - public function getSPIN() - { - return $this->_data['SPIN']; - } - - /** - * @param string $value - * - * @return SuperFund - * - * @deprecated - */ - public function setSPIN($value) - { - $this->propertyUpdated('SPIN', $value); - $this->_data['SPIN'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/PayrollAU/SuperFund/SuperFund.php b/src/XeroPHP/Models/PayrollAU/SuperFund/SuperFund.php index 1192ced8..3c3dd4d7 100644 --- a/src/XeroPHP/Models/PayrollAU/SuperFund/SuperFund.php +++ b/src/XeroPHP/Models/PayrollAU/SuperFund/SuperFund.php @@ -61,15 +61,6 @@ class SuperFund extends Remote\Model * @property string EmployerNumber */ - /** - * The SPIN of the Regulated SuperFund. This field has been deprecated. It will only be present for - * legacy superfunds. New superfunds will not have a SPIN value. The USI field should be used instead - * of SPIN. - * - * @property string SPIN - * - * @deprecated - */ const TYPE_REGULATED = 'REGULATED'; const TYPE_SMSF = 'SMSF'; @@ -342,29 +333,4 @@ public function setEmployerNumber($value) return $this; } - - /** - * @return string - * - * @deprecated - */ - public function getSPIN() - { - return $this->_data['SPIN']; - } - - /** - * @param string $value - * - * @return SuperFund - * - * @deprecated - */ - public function setSPIN($value) - { - $this->propertyUpdated('SPIN', $value); - $this->_data['SPIN'] = $value; - - return $this; - } } diff --git a/src/XeroPHP/Models/PayrollAU/SuperFundProduct.php b/src/XeroPHP/Models/PayrollAU/SuperFundProduct.php index a2f2296f..796d7a56 100644 --- a/src/XeroPHP/Models/PayrollAU/SuperFundProduct.php +++ b/src/XeroPHP/Models/PayrollAU/SuperFundProduct.php @@ -18,15 +18,6 @@ class SuperFundProduct extends Remote\Model * @property string USI */ - /** - * The SPIN of the Regulated SuperFund. (e.g NML0117AU) This field has been deprecated. New superfunds - * will not have a SPIN value. The USI field should be used instead of SPIN. - * - * @property string SPIN - * - * @deprecated - */ - /** * The name of the Regulated SuperFund. * @@ -150,31 +141,6 @@ public function setUSI($value) return $this; } - /** - * @return string - * - * @deprecated - */ - public function getSPIN() - { - return $this->_data['SPIN']; - } - - /** - * @param string $value - * - * @return SuperFundProduct - * - * @deprecated - */ - public function setSPIN($value) - { - $this->propertyUpdated('SPIN', $value); - $this->_data['SPIN'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/PayrollUK/Timesheet.php b/src/XeroPHP/Models/PayrollUK/Timesheet.php index ada14089..0c7bb062 100644 --- a/src/XeroPHP/Models/PayrollUK/Timesheet.php +++ b/src/XeroPHP/Models/PayrollUK/Timesheet.php @@ -1,16 +1,17 @@ [false, self::PROPERTY_TYPE_STRING, null, false, false], 'totalHours' => [false, self::PROPERTY_TYPE_FLOAT, null, false, false], 'updatedDateUTC' => [false, self::PROPERTY_TYPE_DATE, '\\DateTimeInterface', false, false], - 'lines' => [false, self::PROPERTY_TYPE_OBJECT, Line::class, true, true] + 'lines' => [false, self::PROPERTY_TYPE_OBJECT, Line::class, true, true], ]; } @@ -108,17 +109,17 @@ public static function getProperties() */ public function getPayrollCalendarID() { - return $this->_data[ 'payrollCalendarID' ]; + return $this->_data['payrollCalendarID']; } /** - * @param string $value + * @param string $value * @return $this */ public function setPayrollCalendarID(string $value) { $this->propertyUpdated('payrollCalendarID', $value); - $this->_data[ 'payrollCalendarID' ] = $value; + $this->_data['payrollCalendarID'] = $value; return $this; } @@ -128,17 +129,17 @@ public function setPayrollCalendarID(string $value) */ public function getEmployeeID() { - return $this->_data[ 'employeeID' ]; + return $this->_data['employeeID']; } /** - * @param string $value + * @param string $value * @return $this */ public function setEmployeeID(string $value) { $this->propertyUpdated('employeeID', $value); - $this->_data[ 'employeeID' ] = $value; + $this->_data['employeeID'] = $value; return $this; } @@ -148,7 +149,7 @@ public function setEmployeeID(string $value) */ public function getStartDate() { - return $this->_data[ 'startDate' ]; + return $this->_data['startDate']; } /** @@ -158,7 +159,7 @@ public function getStartDate() public function setStartDate($value) { $this->propertyUpdated('startDate', $value); - $this->_data[ 'startDate' ] = $value; + $this->_data['startDate'] = $value; return $this; } @@ -168,7 +169,7 @@ public function setStartDate($value) */ public function getEndDate() { - return $this->_data[ 'endDate' ]; + return $this->_data['endDate']; } /** @@ -178,7 +179,7 @@ public function getEndDate() public function setEndDate($value) { $this->propertyUpdated('endDate', $value); - $this->_data[ 'endDate' ] = $value; + $this->_data['endDate'] = $value; return $this; } @@ -188,34 +189,34 @@ public function setEndDate($value) */ public function getLines() { - return $this->_data[ 'lines' ]; + return $this->_data['lines']; } /** - * @param Line $value + * @param Line $value * @return $this */ public function addLine(Line $value) { $this->propertyUpdated('lines', $value); - if (!isset($this->_data[ 'lines' ])) { - $this->_data[ 'lines' ] = new Remote\Collection; + if (!isset($this->_data['lines'])) { + $this->_data['lines'] = new Remote\Collection; } - $this->_data[ 'lines' ][] = $value; + $this->_data['lines'][] = $value; return $this; } /** - * @param Remote\Collection $value + * @param Remote\Collection $value * @return $this */ public function setLines(Remote\Collection $value) { $this->propertyUpdated('lines', $value); - $this->_data[ 'lines' ] = $collectionOfLines; + $this->_data['lines'] = $value; return $this; } @@ -233,7 +234,7 @@ public function getID() */ public function getTimesheetID() { - return $this->_data[ 'timesheetID' ]; + return $this->_data['timesheetID']; } /** @@ -241,7 +242,7 @@ public function getTimesheetID() */ public function getStatus() { - return $this->_data[ 'status' ]; + return $this->_data['status']; } /** @@ -249,7 +250,7 @@ public function getStatus() */ public function getTotalHours() { - return $this->_data[ 'totalHours' ]; + return $this->_data['totalHours']; } /** @@ -257,6 +258,6 @@ public function getTotalHours() */ public function getUpdatedDateUTC() { - return $this->_data[ 'updatedDateUTC' ]; + return $this->_data['updatedDateUTC']; } } diff --git a/src/XeroPHP/Models/PayrollUS/Employee/OpeningBalance.php b/src/XeroPHP/Models/PayrollUS/Employee/OpeningBalance.php index 1ef5a140..c3c46618 100644 --- a/src/XeroPHP/Models/PayrollUS/Employee/OpeningBalance.php +++ b/src/XeroPHP/Models/PayrollUS/Employee/OpeningBalance.php @@ -64,14 +64,6 @@ class OpeningBalance extends Remote\Model * @property string ReimbursementTypeID */ - /** - * This property has been removed from the Xero API. - * - * @property string EmployeeID - * - * @deprecated - */ - /** * Get the resource uri of the class (Contacts) etc. * @@ -352,29 +344,4 @@ public function setReimbursementTypeID($value) return $this; } - - /** - * @return string - * - * @deprecated - */ - public function getEmployeeID() - { - return $this->_data['EmployeeID']; - } - - /** - * @param string $value - * - * @return OpeningBalance - * - * @deprecated - */ - public function setEmployeeID($value) - { - $this->propertyUpdated('EmployeeID', $value); - $this->_data['EmployeeID'] = $value; - - return $this; - } } diff --git a/src/XeroPHP/Models/PayrollUS/Employee/SalaryAndWage.php b/src/XeroPHP/Models/PayrollUS/Employee/SalaryAndWage.php index 86bf3521..7491631c 100644 --- a/src/XeroPHP/Models/PayrollUS/Employee/SalaryAndWage.php +++ b/src/XeroPHP/Models/PayrollUS/Employee/SalaryAndWage.php @@ -6,14 +6,6 @@ class SalaryAndWage extends Remote\Model { - /** - * This property has been removed from the Xero API. - * - * @property string SalaryAndWageID - * - * @deprecated - */ - /** * Xero unique identifier for SalaryAndWage item. e.g c56b19ef-75bf-45e8-98a4-e699a96609f7. * @@ -134,31 +126,6 @@ public static function isPageable() return false; } - /** - * @return string - * - * @deprecated - */ - public function getSalaryAndWageID() - { - return $this->_data['SalaryAndWageID']; - } - - /** - * @param string $value - * - * @return SalaryAndWage - * - * @deprecated - */ - public function setSalaryAndWageID($value) - { - $this->propertyUpdated('SalaryAndWageID', $value); - $this->_data['SalaryAndWageID'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/PayrollUS/PayItem/EarningsType.php b/src/XeroPHP/Models/PayrollUS/PayItem/EarningsType.php index 48a55ec7..19bff555 100644 --- a/src/XeroPHP/Models/PayrollUS/PayItem/EarningsType.php +++ b/src/XeroPHP/Models/PayrollUS/PayItem/EarningsType.php @@ -12,14 +12,6 @@ class EarningsType extends Remote\Model * @property EarningsType EarningsType */ - /** - * This property has been removed from the Xero API. - * - * @property string DisplayName - * - * @deprecated - */ - /** * See Accounts. * @@ -44,14 +36,6 @@ class EarningsType extends Remote\Model * @property string TypeOfUnits */ - /** - * This property has been removed from the Xero API. - * - * @property string EarningsRateID - * - * @deprecated - */ - /** * Xero identifier. * @@ -218,31 +202,6 @@ public function setEarningsType(self $value) return $this; } - /** - * @return string - * - * @deprecated - */ - public function getDisplayName() - { - return $this->_data['DisplayName']; - } - - /** - * @param string $value - * - * @return EarningsType - * - * @deprecated - */ - public function setDisplayName($value) - { - $this->propertyUpdated('DisplayName', $value); - $this->_data['DisplayName'] = $value; - - return $this; - } - /** * @return string */ @@ -327,31 +286,6 @@ public function setTypeOfUnit($value) return $this; } - /** - * @return string - * - * @deprecated - */ - public function getEarningsRateID() - { - return $this->_data['EarningsRateID']; - } - - /** - * @param string $value - * - * @return EarningsType - * - * @deprecated - */ - public function setEarningsRateID($value) - { - $this->propertyUpdated('EarningsRateID', $value); - $this->_data['EarningsRateID'] = $value; - - return $this; - } - /** * @return string */ diff --git a/src/XeroPHP/Models/PayrollUS/Setting/Account.php b/src/XeroPHP/Models/PayrollUS/Setting/Account.php index c3f23389..1a8386ab 100644 --- a/src/XeroPHP/Models/PayrollUS/Setting/Account.php +++ b/src/XeroPHP/Models/PayrollUS/Setting/Account.php @@ -93,9 +93,9 @@ public static function getProperties() { return [ 'AccountID' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Type' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], - 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Type' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Code' => [false, self::PROPERTY_TYPE_STRING, null, false, false], + 'Name' => [false, self::PROPERTY_TYPE_STRING, null, false, false], ]; } @@ -112,12 +112,7 @@ public function getAccountID() return $this->_data['AccountID']; } - /** - * @param string $value - * - * @return Account - */ - public function setAccountID($value) + public function setAccountID(string $value): static { $this->propertyUpdated('AccountID', $value); $this->_data['AccountID'] = $value; @@ -125,20 +120,12 @@ public function setAccountID($value) return $this; } - /** - * @return string - */ - public function getType() + public function getType(): string { return $this->_data['Type']; } - /** - * @param string $value - * - * @return Account - */ - public function setType($value) + public function setType(string $value): static { $this->propertyUpdated('Type', $value); $this->_data['Type'] = $value; @@ -146,20 +133,12 @@ public function setType($value) return $this; } - /** - * @return string - */ - public function getCode() + public function getCode(): string { return $this->_data['Code']; } - /** - * @param string $value - * - * @return Account - */ - public function setCode($value) + public function setCode(string $value): static { $this->propertyUpdated('Code', $value); $this->_data['Code'] = $value; @@ -167,20 +146,12 @@ public function setCode($value) return $this; } - /** - * @return string - */ - public function getName() + public function getName(): string { return $this->_data['Name']; } - /** - * @param string $value - * - * @return Account - */ - public function setName($value) + public function setName(string $value): static { $this->propertyUpdated('Name', $value); $this->_data['Name'] = $value; diff --git a/src/XeroPHP/Models/SubscriptionItem.php b/src/XeroPHP/Models/SubscriptionItem.php index 7d8857c0..38900e53 100644 --- a/src/XeroPHP/Models/SubscriptionItem.php +++ b/src/XeroPHP/Models/SubscriptionItem.php @@ -88,7 +88,7 @@ public function getStartDate() */ public function getStatus() { - return $this->data['status']; + return $this->_data['status']; } /** diff --git a/src/XeroPHP/Remote/Model.php b/src/XeroPHP/Remote/Model.php index 68ba2ac0..ff23fd96 100644 --- a/src/XeroPHP/Remote/Model.php +++ b/src/XeroPHP/Remote/Model.php @@ -2,8 +2,9 @@ namespace XeroPHP\Remote; -use XeroPHP\Helpers; +use PHPUnit\Runner\Exception; use XeroPHP\Application; +use XeroPHP\Helpers; use XeroPHP\Remote\Exception\RequiredFieldException; /** @@ -44,17 +45,13 @@ abstract class Model implements ObjectInterface, \JsonSerializable, \ArrayAccess /** * Container to the actual properties of the object. - * - * @var array */ - protected $_data; + protected array $_data; /** * Holds a record of which properties have been changed. - * - * @var array */ - protected $_dirty; + protected array $_dirty; /** * Holds a list of objects that hold child references to this one. @@ -66,16 +63,14 @@ abstract class Model implements ObjectInterface, \JsonSerializable, \ArrayAccess /** * Holds a ref to the application that was used to load the object, * enables shorthand $object->save();. - * - * @var Application|null */ - protected $_application; + protected ?Application $_application; public function __construct(Application $application = null) { - $this->_application = $application; - $this->_dirty = []; - $this->_data = []; + $this->_application = $application; + $this->_dirty = []; + $this->_data = []; $this->_associated_objects = []; } @@ -88,7 +83,7 @@ public static function make(Application $application = null) * This should be compulsory in the constructor in the future, * but will have to be like this for BC until the next major version. * - * @param Application $application + * @param Application $application * * @return $this */ @@ -112,7 +107,7 @@ protected function getApplication() /** * If there have been any properties changed since load. * - * @param null $property + * @param null $property * * @return bool */ @@ -142,7 +137,7 @@ public function setDirty($property) /** * Manually set a property as clean. * - * @param null $property + * @param null $property * * @return self */ @@ -176,7 +171,7 @@ public function getGUID() } /** - * @param string $guid + * @param string $guid * * @return $this */ @@ -197,22 +192,22 @@ public function setGUID($guid) public function fromStringArray($input_array, $replace_data = false) { foreach (static::getProperties() as $property => $meta) { - $type = $meta[self::KEY_TYPE]; + $type = $meta[self::KEY_TYPE]; $php_type = $meta[self::KEY_PHP_TYPE]; - $isArray = $meta[self::KEY_IS_ARRAY]; + $isArray = $meta[self::KEY_IS_ARRAY]; //If set and NOT replace data, continue - if (! $replace_data && isset($this->_data[$property])) { + if (!$replace_data && isset($this->_data[$property])) { continue; } - if (! isset($input_array[$property])) { + if (!isset($input_array[$property])) { $this->_data[$property] = null; continue; } - if ($isArray && ! is_array($input_array[$property])) { + if ($isArray && !is_array($input_array[$property])) { $this->_data[$property] = null; continue; @@ -247,7 +242,7 @@ public function fromStringArray($input_array, $replace_data = false) /** * Convert the object into an array, and any non-primitives to string. * - * @param mixed $dirty_only + * @param mixed $dirty_only * * @return array */ @@ -255,12 +250,12 @@ public function toStringArray($dirty_only = false) { $out = []; foreach (static::getProperties() as $property => $meta) { - if (! isset($this->_data[$property])) { + if (!isset($this->_data[$property])) { continue; } //if we only want the dirty props, stop here - if ($dirty_only && ! isset($this->_dirty[$property]) && $property !== static::getGUIDProperty()) { + if ($dirty_only && !isset($this->_dirty[$property]) && $property !== static::getGUIDProperty()) { continue; } @@ -317,7 +312,7 @@ public static function castToString($type, $value) return ''; default: if (is_scalar($value)) { - return (string) $value; + return (string)$value; } return ''; @@ -331,7 +326,7 @@ public static function castToString($type, $value) * @param $value * @param $php_type * - * @return bool|\DateTimeInterface|float|int|string + * @return bool|\DateTimeInterface|float|int|string|Model */ public static function castFromString($type, $value, $php_type) { @@ -341,10 +336,10 @@ public static function castFromString($type, $value, $php_type) switch ($type) { case self::PROPERTY_TYPE_INT: - return (int) $value; + return (int)$value; case self::PROPERTY_TYPE_FLOAT: - return (float) $value; + return (float)$value; case self::PROPERTY_TYPE_BOOLEAN: return in_array(strtolower($value), ['true', '1', 'yes'], true); @@ -353,7 +348,7 @@ public static function castFromString($type, $value, $php_type) case self::PROPERTY_TYPE_TIMESTAMP: $timezone = new \DateTimeZone('UTC'); - // no break + // no break case self::PROPERTY_TYPE_DATE: if (preg_match('/Date\\((?[0-9\\+\\.]+)\\)/', $value, $matches)) { //to catch stupid .net date serialisation $value = $matches['timestamp']; @@ -371,21 +366,21 @@ public static function castFromString($type, $value, $php_type) default: if (is_scalar($value)) { - return (string) $value; + return (string)$value; } - return (object) $value; + return (object)$value; } } /** * Validate the object and (optionally) the child objects recursively. * - * @param bool $check_children + * @param bool $check_children * + * @return bool * @throws Exception * - * @return bool */ public function validate($check_children = true) { @@ -394,8 +389,8 @@ public function validate($check_children = true) $mandatory = $meta[self::KEY_MANDATORY]; //If it's got a GUID, it's already going to be valid almost all cases - if (! $this->hasGUID() && $mandatory) { - if (! isset($this->_data[$property]) || empty($this->_data[$property])) { + if (!$this->hasGUID() && $mandatory) { + if (!isset($this->_data[$property]) || empty($this->_data[$property])) { $class = get_class($this); throw new RequiredFieldException( $class, @@ -431,14 +426,14 @@ public function validate($check_children = true) /** * Shorthand save an object if it is instantiated with app context. * + * @return Response|null * @throws Exception * - * @return Response|null */ public function save() { if ($this->_application === null) { - throw new Exception( + throw new \Exception( '->save() is only available on objects that have an injected application context.' ); } @@ -449,14 +444,13 @@ public function save() /** * Shorthand delete an object if it is instantiated with app context. * - * @throws Exception - * - * @return Response + * @return Model + * @throws Exception|\XeroPHP\Exception */ public function delete() { if ($this->_application === null) { - throw new Exception( + throw new \Exception( '->delete() is only available on objects that have an injected application context.' ); } @@ -464,23 +458,15 @@ public function delete() return $this->_application->delete($this); } - /** - * @param string $property - * @param Model $object - */ - public function addAssociatedObject($property, self $object) + public function addAssociatedObject(string $property, self $object) { $this->_associated_objects[$property] = $object; } /** * Magic method for testing if properties exist. - * - * @param $property - * - * @return bool */ - public function __isset($property) + public function __isset(string $property): bool { return isset($this->_data[$property]); } @@ -488,11 +474,9 @@ public function __isset($property) /** * Magic getter for accessing properties directly. * - * @param $property - * * @return mixed */ - public function __get($property) + public function __get(string $property) { $getter = sprintf('get%s', $property); @@ -500,7 +484,13 @@ public function __get($property) return $this->$getter(); } + if (isset($this->getProperties()[$property])) { + return $this->_data[$property] ?? null; + } + trigger_error(sprintf("Undefined property %s::$%s.\n", __CLASS__, $property)); + + return null; } /** @@ -509,7 +499,7 @@ public function __get($property) * @param $property * @param $value * - * @return mixed + * @return self */ public function __set($property, $value) { @@ -519,12 +509,21 @@ public function __set($property, $value) return $this->$setter($value); } + if (isset($this->getProperties()[$property])) { + $this->propertyUpdated($property, $value); + $this->_data[$property] = $value; + + return $this; + } + trigger_error(sprintf("Undefined property %s::$%s.\n", __CLASS__, $property)); + + return null; } protected function propertyUpdated($property, $value) { - $currentValue = isset($this->_data[$property]) ? $this->_data[$property] : null; + $currentValue = $this->_data[$property] ?? null; if ($currentValue !== $value) { //If this object can update itself, set its own dirty flag, otherwise, set its parent's. @@ -564,7 +563,7 @@ public function jsonSerialize() } /** - * @param mixed $offset + * @param mixed $offset * * @return bool */ @@ -575,7 +574,7 @@ public function offsetExists($offset) } /** - * @param mixed $offset + * @param mixed $offset * * @return mixed */ @@ -586,8 +585,8 @@ public function offsetGet($offset) } /** - * @param mixed $offset - * @param mixed $value + * @param mixed $offset + * @param mixed $value * * @return mixed */ @@ -598,11 +597,20 @@ public function offsetSet($offset, $value) } /** - * @param mixed $offset + * @param mixed $offset */ #[\ReturnTypeWillChange] public function offsetUnset($offset) { unset($this->_data[$offset]); } + + public function __call($name, $arguments) + { + if (preg_match('/(get|set)(.*)/', $name, $matches)) { + return $this->{'__' . $matches[1]}($matches[2], ($arguments[0] ?? null)); + } + + throw new \Exception('Method does not exist: ' . $name . ' for class: ' . self::class); + } } diff --git a/src/XeroPHP/Remote/Object.php b/src/XeroPHP/Remote/Object.php deleted file mode 100644 index 56b543af..00000000 --- a/src/XeroPHP/Remote/Object.php +++ /dev/null @@ -1,10 +0,0 @@ -app = $app; - $this->where = []; - $this->order = null; - $this->modifiedAfter = null; - $this->page = null; - $this->pageSize = null; - $this->offset = null; + $this->app = $app; + $this->where = []; + $this->order = null; + $this->modifiedAfter = null; + $this->page = null; + $this->pageSize = null; + $this->offset = null; $this->includeArchived = false; - $this->createdByMyApp = false; - $this->params = []; - $this->response = null; + $this->createdByMyApp = false; + $this->params = []; + $this->response = null; } /** - * @param string $class + * @param string $class * * @return $this */ @@ -104,8 +115,8 @@ public function andWhere() } /** - * @param string $operator - * @param array $args + * @param string $operator + * @param array $args * * @return $this */ @@ -154,8 +165,8 @@ public function getWhere() } /** - * @param string $order - * @param string $direction + * @param string $order + * @param string $direction * * @return $this */ @@ -167,7 +178,7 @@ public function orderBy($order, $direction = self::ORDER_ASC) } /** - * @param \DateTimeInterface|null $modifiedAfter + * @param \DateTimeInterface|null $modifiedAfter * * @return $this */ @@ -183,7 +194,7 @@ public function modifiedAfter(\DateTimeInterface $modifiedAfter = null) } /** - * @param DateTime $fromDate + * @param DateTime $fromDate * * @return $this */ @@ -195,7 +206,7 @@ public function fromDate(DateTime $fromDate) } /** - * @param DateTime $toDate + * @param DateTime $toDate * * @return $this */ @@ -207,7 +218,7 @@ public function toDate(DateTime $toDate) } /** - * @param DateTime $date + * @param DateTime $date * * @return $this */ @@ -219,11 +230,11 @@ public function date(DateTime $date) } /** - * @param int $page + * @param int $page * + * @return $this * @throws Exception * - * @return $this */ public function page($page = 1) { @@ -231,21 +242,21 @@ public function page($page = 1) * @var ObjectInterface */ $from_class = $this->from_class; - if (! $from_class::isPageable()) { + if (!$from_class::isPageable()) { throw new Exception(sprintf('%s does not support paging.', $from_class)); } - $this->page = (int) $page; + $this->page = (int)$page; return $this; } /** - * @param int $pageSize + * @param int $pageSize * + * @return $this * @throws Exception * - * @return $this */ public function pageSize($pageSize = 100) { @@ -253,61 +264,71 @@ public function pageSize($pageSize = 100) * @var ObjectInterface */ $from_class = $this->from_class; - if (! $from_class::isPageable()) { + if (!$from_class::isPageable()) { throw new Exception(sprintf('%s does not support paging.', $from_class)); } - $this->pageSize = (int) $pageSize; + $this->pageSize = (int)$pageSize; return $this; } /** - * @param int $offset + * @param int $offset * * @return $this */ public function offset($offset = 0) { - $this->offset = (int) $offset; + $this->offset = (int)$offset; return $this; } public function includeArchived($includeArchived = true) { - $this->includeArchived = (bool) $includeArchived; + $this->includeArchived = (bool)$includeArchived; return $this; } public function createdByMyApp($createdByMyApp = true) { - $this->createdByMyApp = (bool) $createdByMyApp; + $this->createdByMyApp = (bool)$createdByMyApp; return $this; } public function setParameter($key, $value) { - $this->params[(string) $key] = (string) $value; + $this->params[(string)$key] = (string)$value; return $this; } /** - * @return Collection + * @throws Exception + * @throws BadRequestException + * @throws ForbiddenException + * @throws InternalErrorException + * @throws NotAvailableException + * @throws NotFoundException + * @throws NotImplementedException + * @throws OrganisationOfflineException + * @throws RateLimitExceededException + * @throws ReportPermissionMissingException + * @throws UnauthorizedException */ - public function execute() + public function execute(): Collection { - /** - * @var ObjectInterface - */ + /** @var ObjectInterface $from_class */ $from_class = $this->from_class; + $url = new URL( $this->app, $from_class::getResourceURI(), $from_class::getAPIStem() ); + $request = new Request($this->app, $url, Request::METHOD_GET); // Add params @@ -318,7 +339,7 @@ public function execute() // Concatenate where statements $where = $this->getWhere(); - if (! empty($where)) { + if (!empty($where)) { $request->setParameter('where', $where); } @@ -395,12 +416,4 @@ public function getFrom() { return $this->from_class; } - - /** - * @return Response|null - */ - public function getResponse() - { - return $this->response; - } } diff --git a/src/XeroPHP/Remote/Request.php b/src/XeroPHP/Remote/Request.php index 33382cc6..1c3a971c 100644 --- a/src/XeroPHP/Remote/Request.php +++ b/src/XeroPHP/Remote/Request.php @@ -5,7 +5,6 @@ use GuzzleHttp\Psr7\Request as PsrRequest; use GuzzleHttp\Psr7\Uri; use XeroPHP\Application; -use XeroPHP\Remote\Exception\RateLimitExceededException; class Request { @@ -54,30 +53,23 @@ class Request /** * Request constructor. - * @param Application $app - * @param URL $url - * @param string $method + * @param Application $app + * @param URL $url + * @param string $method * @throws Exception * @throws \XeroPHP\Exception */ public function __construct(Application $app, URL $url, $method = self::METHOD_GET) { - $this->app = $app; - $this->url = $url; - $this->headers = []; + $this->app = $app; + $this->url = $url; + $this->headers = []; $this->parameters = []; - switch ($method) { - case self::METHOD_GET: - case self::METHOD_PUT: - case self::METHOD_POST: - case self::METHOD_DELETE: - $this->method = $method; - - break; - default: - throw new Exception("Invalid request method [{$method}]"); - } + $this->method = match ($method) { + self::METHOD_GET, self::METHOD_PUT, self::METHOD_POST, self::METHOD_DELETE => $method, + default => throw new Exception("Invalid request method [{$method}]"), + }; //Default to XML so you get the xsi:type attribute in the root node. $this->setHeader(self::HEADER_ACCEPT, $app->getConfigOption('xero', 'default_content_type')); @@ -112,14 +104,14 @@ public function send() } catch (\GuzzleHttp\Exception\BadResponseException $e) { $guzzleResponse = $e->getResponse(); } - - if($guzzleResponse->hasHeader('X-AppMinLimit-Remaining')){ + + if ($guzzleResponse->hasHeader('X-AppMinLimit-Remaining')) { $this->app->updateAppRateLimit( $guzzleResponse->getHeader('X-AppMinLimit-Remaining')[0] ); } - - if($guzzleResponse->hasHeader('X-DayLimit-Remaining')){ + + if ($guzzleResponse->hasHeader('X-DayLimit-Remaining')) { $this->app->updateTenantRateLimits( $guzzleResponse->getHeader('X-DayLimit-Remaining')[0], $guzzleResponse->getHeader('X-MinLimit-Remaining')[0], diff --git a/src/XeroPHP/Remote/Response.php b/src/XeroPHP/Remote/Response.php index 932a726f..9c1ca40d 100644 --- a/src/XeroPHP/Remote/Response.php +++ b/src/XeroPHP/Remote/Response.php @@ -105,7 +105,7 @@ public function parse() switch ($this->status) { case self::STATUS_BAD_REQUEST: //This catches actual app errors - if (isset($this->root_error) && !empty($this->root_error)) { + if (!empty($this->root_error)) { $message = sprintf('%s (%s)', $this->root_error['message'], implode(', ', $this->element_errors)); $message .= $this->parseBadRequest(); diff --git a/src/XeroPHP/Remote/URL.php b/src/XeroPHP/Remote/URL.php index 9f3279e4..76877f35 100644 --- a/src/XeroPHP/Remote/URL.php +++ b/src/XeroPHP/Remote/URL.php @@ -52,7 +52,7 @@ public function __construct(Application $app, $endpoint, $api = null) { //Handle full URLs and pull them back apart. //Annoying internal references are http??? and absolute. - if (strpos($endpoint, 'http') === 0) { + if (str_starts_with($endpoint, 'http')) { if (preg_match('@^http(s)?://[^/]+/(?[^/]+)/(?[^/]+)/(?.+)$@i', $endpoint, $matches)) { $endpoint = $matches['endpoint']; $api = $matches['api']; @@ -72,26 +72,13 @@ public function __construct(Application $app, $endpoint, $api = null) //Check here that the URI hasn't been set by one of the OAuth methods and handle as normal if (!isset($this->path)) { - switch ($api) { - case self::API_CORE: - $version = $xero_config['core_version']; - - break; - case self::API_PAYROLL: - $version = $xero_config['payroll_version']; - - break; - case self::API_FILE: - $version = $xero_config['file_version']; - - break; - case self::API_PRACTICE_MANAGER: - $version = $xero_config['practice_manager_version']; - - break; - default: - throw new Exception('Invalid API passed to XeroPHP\\URL::__construct(). Must be XeroPHP\\URL::API_*'); - } + $version = match ($api) { + self::API_CORE => $xero_config['core_version'], + self::API_PAYROLL => $xero_config['payroll_version'], + self::API_FILE => $xero_config['file_version'], + self::API_PRACTICE_MANAGER => $xero_config['practice_manager_version'], + default => throw new Exception('Invalid API passed to XeroPHP\\URL::__construct(). Must be XeroPHP\\URL::API_*'), + }; $this->path = sprintf('%s/%s/%s', $api, $version, $this->endpoint); } diff --git a/src/XeroPHP/Webhook/Event.php b/src/XeroPHP/Webhook/Event.php index 2f1c5173..e3a79127 100644 --- a/src/XeroPHP/Webhook/Event.php +++ b/src/XeroPHP/Webhook/Event.php @@ -2,67 +2,42 @@ namespace XeroPHP\Webhook; +use XeroPHP\Exception; use XeroPHP\Remote\Exception\RequiredFieldException; use XeroPHP\Remote\Request; use XeroPHP\Remote\URL; +use XeroPHP\Webhook; /** * Represents a single event within a webhook. */ class Event { - /** - * @var \XeroPHP\Webhook - */ - private $webhook; + private \XeroPHP\Webhook $webhook; - /** - * @var string - */ - private $resourceUrl; + private string $resourceUrl; - /** - * @var string - */ - private $resourceId; + private string $resourceId; - /** - * @var string - */ - private $eventDateUtc; + private string $eventDateUtc; - /** - * @var string - */ - private $eventType; + private string $eventType; - /** - * @var string - */ - private $eventCategory; + private string $eventCategory; - /** - * @var string - */ - private $tenantId; + private string $tenantId; - /** - * @var string - */ - private $tenantType; + private string $tenantType; /** * Validates the event payload is correctly formatted. * - * @param \XeroPHP\Webhook $webhook - * @param array $event event details - * * @throws \XeroPHP\Exception if the provided payload is malformed */ - public function __construct($webhook, $event) + public function __construct(Webhook $webhook, array $event) { $this->webhook = $webhook; - $fields = [ + $fields = [ 'resourceUrl', 'resourceId', 'eventDateUtc', @@ -75,9 +50,9 @@ public function __construct($webhook, $event) foreach ($fields as $required) { if (!isset($event[$required])) { throw new RequiredFieldException( - get_class($this), - $required, - "The event payload was malformed; missing required field {$required}" + get_class($this), + $required, + "The event payload was malformed; missing required field $required" ); } @@ -85,68 +60,57 @@ public function __construct($webhook, $event) } } - /** - * @return \XeroPHP\Webhook - */ - public function getWebhook() + public function getWebhook(): \XeroPHP\Webhook { return $this->webhook; } /** - * @return string direct Xero URL to fetch the resource + * Direct Xero URL to fetch the resource */ - public function getResourceUrl() + public function getResourceUrl(): string { return $this->resourceUrl; } /** - * @return string the GUID of the resource + * The GUID of the resource */ - public function getResourceId() + public function getResourceId(): string { return $this->resourceId; } /** - * @return string date and time of the event in UTC format + * date and time of the event in UTC format */ - public function getEventDateUtc() + public function getEventDateUtc(): string { return $this->eventDateUtc; } /** * Returns the event date. - * - * @return \DateTime */ - public function getEventDate() + public function getEventDate(): \DateTime { return new \DateTime($this->eventDateUtc); } - /** - * @return string event type - */ - public function getEventType() + public function getEventType(): string { return $this->eventType; } - /** - * @return string event category - */ - public function getEventCategory() + public function getEventCategory(): string { return $this->eventCategory; } /** - * @return string the library class to use when fetching the referenced resource + * return the library class to use when fetching the referenced resource */ - public function getEventClass() + public function getEventClass(): string { if ($this->getEventCategory() === 'INVOICE') { return \XeroPHP\Models\Accounting\Invoice::class; @@ -157,20 +121,16 @@ public function getEventClass() if ($this->getEventCategory() === 'SUBSCRIPTION') { return \XeroPHP\Models\Subscription::class; } + + throw new Exception('Webhook Event Category Not Recognized: ' . $this->getEventCategory()); } - /** - * @return string - */ - public function getTenantId() + public function getTenantId(): string { return $this->tenantId; } - /** - * @return string - */ - public function getTenantType() + public function getTenantType(): string { return $this->tenantType; } @@ -178,7 +138,7 @@ public function getTenantType() /** * Fetches the resource and, if possible, loads it into it's respective model class. * - * @param \XeroPHP\Application $application an optional application instance to use to retrieve the remote resource. + * @param \XeroPHP\Application $application an optional application instance to use to retrieve the remote resource. * Useful if you have separate instances with different oauth tokens based on the tenant * * @return array|\XeroPHP\Remote\Model If the event category is known, returns the model, otherwise, returns the resource as an array @@ -190,7 +150,7 @@ public function getResource($application = null) $application = $this->getWebhook()->getApplication(); } - $url = new URL($application, $this->getResourceUrl()); + $url = new URL($application, $this->getResourceUrl()); $request = new Request($application, $url, Request::METHOD_GET); $request->send(); diff --git a/tests/Remote/Model/AccountTest.php b/tests/Remote/Model/AccountTest.php new file mode 100644 index 00000000..6a7af465 --- /dev/null +++ b/tests/Remote/Model/AccountTest.php @@ -0,0 +1,24 @@ +setCode('TESTCODE'); + $this->assertEquals('TESTCODE', $account->getCode()); + } +} diff --git a/tests/Webhook/EventTest.php b/tests/Webhook/EventTest.php index da143bbe..ce5886c5 100644 --- a/tests/Webhook/EventTest.php +++ b/tests/Webhook/EventTest.php @@ -3,9 +3,10 @@ namespace XeroPHP\Tests\Webhook; use PHPUnit\Framework\TestCase; +use XeroPHP\Exception; +use XeroPHP\Remote\Exception\RequiredFieldException; use XeroPHP\Webhook; use XeroPHP\Application; -use XeroPHP\Application\PrivateApplication; class EventTest extends TestCase { @@ -24,15 +25,13 @@ public function setUp(): void ]); } - /** - * @expectedException \XeroPHP\Exception - */ public function testMalformedPayload() { + $this->expectException(RequiredFieldException::class); + $payload = '{"events":[{"resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"INVOICE","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"}],"firstEventSequence": 2,"lastEventSequence": 3, "entropy": "GATSEZXWIBPBRNQOTMOH"}'; $webhook = new Webhook($this->application, $payload); - foreach ($webhook->getEvents() as $evt) { - } + $webhook->getEvents(); } public function testGetWebhook() @@ -107,22 +106,24 @@ public function testGetEventCategory() public function testGetEventClass() { - $payload = '{"events":[{"resourceUrl":"https://api.xero.com/api.xro/2.0/Invoices/44aa0707-f718-4f1c-8d53-f2da9ca59533","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"INVOICE","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"},{"resourceUrl":"https://api.xero.com/api.xro/2.0/Invoices/44aa0707-f718-4f1c-8d53-f2da9ca59533","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"CONTACT","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"},{"resourceUrl":"https://api.xero.com/api.xro/2.0/Subscriptions/44aa0707-f718-4f1c-8d53-f2da9ca59534","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59534","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"CREATE","eventCategory":"SUBSCRIPTION","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"},{"resourceUrl":"https://api.xero.com/api.xro/2.0/Invoices/44aa0707-f718-4f1c-8d53-f2da9ca59533","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"INVOICE","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"}],"firstEventSequence": 2,"lastEventSequence": 3, "entropy": "GATSEZXWIBPBRNQOTMOH"}'; + $payload = '{"events":[{"resourceUrl":"https://api.xero.com/api.xro/2.0/Invoices/44aa0707-f718-4f1c-8d53-f2da9ca59533","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"INVALID","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"},{"resourceUrl":"https://api.xero.com/api.xro/2.0/Invoices/44aa0707-f718-4f1c-8d53-f2da9ca59533","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"CONTACT","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"},{"resourceUrl":"https://api.xero.com/api.xro/2.0/Subscriptions/44aa0707-f718-4f1c-8d53-f2da9ca59534","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59534","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"CREATE","eventCategory":"SUBSCRIPTION","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"},{"resourceUrl":"https://api.xero.com/api.xro/2.0/Invoices/44aa0707-f718-4f1c-8d53-f2da9ca59533","resourceId":"44aa0707-f718-4f1c-8d53-f2da9ca59533","eventDateUtc":"2018-02-09T09:18:28.917Z","eventType":"UPDATE","eventCategory":"INVOICE","tenantId":"e629a03c-7ffe-4913-bd94-ff2fdb36a702","tenantType":"ORGANISATION"}],"firstEventSequence": 2,"lastEventSequence": 3, "entropy": "GATSEZXWIBPBRNQOTMOH"}'; $webhook = new Webhook($this->application, $payload); $events = $webhook->getEvents(); - $evt = array_pop($events); - $this->assertNull($evt->getEventClass()); + $evt = array_shift($events); + $this->expectException(Exception::class); - $evt = array_pop($events); - $this->assertSame(\XeroPHP\Models\Accounting\Contact::class, $evt->getEventClass()); + $evt->getEventClass(); - $evt = array_pop($events); - $this->assertSame(\XeroPHP\Models\Accounting\Invoice::class, $evt->getEventClass()); + $evt = array_shift($events); + $this->assertSame(\XeroPHP\Models\Accounting\Contact::class, $evt->getEventClass()); - $evt = array_pop($events); + $evt = array_shift($events); $this->assertSame(\XeroPHP\Models\Subscription::class, $evt->getEventClass()); + + $evt = array_shift($events); + $this->assertSame(\XeroPHP\Models\Accounting\Invoice::class, $evt->getEventClass()); } public function testGetTenantId() diff --git a/tests/WebhookTest.php b/tests/WebhookTest.php index 8752255f..8a3e25f0 100644 --- a/tests/WebhookTest.php +++ b/tests/WebhookTest.php @@ -4,7 +4,7 @@ use PHPUnit\Framework\TestCase; use XeroPHP\Application; -use XeroPHP\Application\PrivateApplication; +use XeroPHP\Exception; use XeroPHP\Webhook; use XeroPHP\Webhook\Event; @@ -25,22 +25,22 @@ public function setUp(): void ]); } - /** - * @expectedException \XeroPHP\Exception - */ public function testMalformedPayload() { + $this->expectException(Exception::class); + $payload = 'not valid json'; - $webhook = new Webhook($this->application, $payload); + + new Webhook($this->application, $payload); } - /** - * @expectedException \XeroPHP\Exception - */ public function testPayloadMissingKeys() { + $this->expectException(Exception::class); + $payload = '{}'; - $webhook = new Webhook($this->application, $payload); + + new Webhook($this->application, $payload); } /**