Skip to content

Commit

Permalink
Merge pull request #8 from kinimodmeyer/php8
Browse files Browse the repository at this point in the history
add php8 support
  • Loading branch information
kinimodmeyer authored Jun 2, 2022
2 parents 8adfef5 + 6728489 commit 45b8c29
Show file tree
Hide file tree
Showing 10 changed files with 27 additions and 20 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-versions: ['7.3', '7.4']
php-versions: ['7.4.*', '8.0.*', '8.1.*']
steps:
- uses: actions/checkout@v2
- name: Setup PHP
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ SDK to handle all different ways to interact with Tradebyte API. more informatio

* credentials (username,password,account-number)
* see https://tb-io.tradebyte.org/how-to/generate-rest-api-credentials-in-tb-one/
* PHP >= 7.3
* PHP >= 7.4
* Composer
* cURL

Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"squizlabs/php_codesniffer": "3.*"
},
"require": {
"php": "^7.3",
"php": "7.4.* || 8.0.* || 8.1.*",
"ext-xmlreader": "*",
"ext-simplexml": "*",
"ext-xmlwriter": "*",
Expand Down
6 changes: 3 additions & 3 deletions src/Base/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,23 +74,23 @@ public function setOpenLocalFilepath(bool $openLocalFilepath)
/**
* @return boolean
*/
public function valid()
public function valid(): bool
{
return !empty($this->current);
}

/**
* @return integer
*/
public function key()
public function key(): int
{
return $this->i;
}

/**
* @return void
*/
public function rewind()
public function rewind(): void
{
$this->i = 0;
$this->isOpen = false;
Expand Down
19 changes: 12 additions & 7 deletions src/Client/Rest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,27 @@ class Rest
/**
* @var integer
*/
private $accountNumber;
private int $accountNumber;

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

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

/**
* @var string
*/
private $baseURL = 'https://rest.trade-server.net';
private string $baseURL = 'https://rest.trade-server.net';

/**
* @var string
*/
private string $userAgent = 'Tradebyte-SDK-PHP';

/**
* @param integer $number
Expand Down Expand Up @@ -155,7 +160,7 @@ public function downloadFile(string $localFilePath, string $url, array $filter =
$context = [
'http' => [
'header' => $this->getAuthHeader()
. "\r\n" . 'User-Agent: Tradebyte-SDK',
. "\r\n" . 'User-Agent: ' . $this->userAgent,
'ignore_errors' => true,
'time_out' => 3600,
]
Expand Down Expand Up @@ -212,7 +217,7 @@ public function postXML(string $url, string $postData = ''): string
'header' => $this->getAuthHeader()
. "\r\n" . 'Content-Type: application/xml'
. "\r\n" . 'Accept: application/xml'
. "\r\n" . 'User-Agent: Tradebyte-SDK',
. "\r\n" . 'User-Agent: ' . $this->userAgent,
'content' => $postData,
'ignore_errors' => true,
'time_out' => 3600,
Expand Down Expand Up @@ -241,7 +246,7 @@ public function getXML(string $url, array $filter = []): XMLReader
'http' => [
'header' => $this->getAuthHeader()
. "\r\n" . 'Accept: application/xml'
. "\r\n" . 'User-Agent: Tradebyte-SDK',
. "\r\n" . 'User-Agent: ' . $this->userAgent,
'ignore_errors' => true,
'time_out' => 3600,
]
Expand Down
2 changes: 1 addition & 1 deletion src/Message/Tbmessage/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function current(): Message
/**
* @return void
*/
public function next()
public function next(): void
{
while ($this->xmlReader->read()) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/Order/Tborder/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public function current(): Order
/**
* @return void
*/
public function next()
public function next(): void
{
while ($this->xmlReader->read()) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/Product/Tbcat/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function current(): Product
/**
* @return void
*/
public function next()
public function next(): void
{
while ($this->xmlReader->read()) {
if (
Expand Down
2 changes: 1 addition & 1 deletion src/Stock/Tbstock/Iterator.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public function current(): Stock
/**
* @return void
*/
public function next()
public function next(): void
{
while ($this->xmlReader->read()) {
if (
Expand Down
8 changes: 5 additions & 3 deletions tests/Message/MessageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,11 @@ public function testUpdateMessageProcessed(): void
{
$mock = $this->getMockBuilder(Client\Rest::class)
->disableOriginalConstructor()
->setMethodsExcept(['postXML', 'setAccountNumber', 'setBaseURL'])
->setMethodsExcept(['postXML', 'setAccountNumber', 'setAccountUser', 'setAccountPassword', 'setBaseURL'])
->getMock();
$mock->setAccountNumber(1234);
$mock->setAccountUser('test');
$mock->setAccountPassword('test');
$mock->setBaseURL('localhost');
$mock->expects($this->once())
->method('fileGetContents')
Expand All @@ -86,10 +88,10 @@ public function testUpdateMessageProcessed(): void
$this->equalTo([
'http' => [
'method' => 'POST',
'header' => 'Authorization: Basic Og==' . "\r\n" .
'header' => 'Authorization: Basic dGVzdDp0ZXN0' . "\r\n" .
'Content-Type: application/xml' . "\r\n" .
'Accept: application/xml' . "\r\n" .
'User-Agent: Tradebyte-SDK',
'User-Agent: Tradebyte-SDK-PHP',
'content' => '',
'ignore_errors' => true,
'time_out' => 3600
Expand Down

0 comments on commit 45b8c29

Please sign in to comment.