Skip to content

Commit 4c6a146

Browse files
authored
Merge pull request #9 from kinimodmeyer/strict-types
Implement strict_types
2 parents 45b8c29 + bf55eab commit 4c6a146

31 files changed

Lines changed: 343 additions & 1870 deletions

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
}
1616
},
1717
"require-dev": {
18-
"phpunit/phpunit": "^8",
18+
"phpunit/phpunit": "^9",
1919
"squizlabs/php_codesniffer": "3.*"
2020
},
2121
"require": {

phpcs.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,4 @@
22
<ruleset xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" name="PHP_CodeSniffer">
33
<description>The coding standard for Tradebyte SDK.</description>
44
<rule ref="PSR12" />
5-
<rule ref="Squiz.Commenting.VariableComment"/>
65
</ruleset>

src/Base/Iterator.php

Lines changed: 17 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -1,95 +1,45 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Tradebyte\Base;
46

57
use Tradebyte\Client;
6-
use Tradebyte\Order\Model\Order;
78
use XMLReader;
89

9-
/**
10-
* @package Tradebyte
11-
*/
1210
class Iterator
1311
{
14-
/**
15-
* @var XMLReader
16-
*/
17-
protected $xmlReader = null;
18-
19-
/**
20-
* @var Order
21-
*/
22-
protected $current;
23-
24-
/**
25-
* @var integer
26-
*/
27-
protected $i = 0;
28-
29-
/**
30-
* @var Client
31-
*/
32-
protected $client;
33-
34-
/**
35-
* @var string
36-
*/
37-
protected $url;
38-
39-
/**
40-
* @var mixed[]
41-
*/
42-
protected $filter;
43-
44-
/**
45-
* @var boolean
46-
*/
47-
protected $openLocalFilepath = false;
48-
49-
/**
50-
* @var boolean
51-
*/
52-
protected $isOpen = false;
53-
54-
/**
55-
* @param Client $client
56-
* @param string $url
57-
* @param mixed[] $filter
58-
*/
12+
protected ?XMLReader $xmlReader = null;
13+
14+
protected int $i = 0;
15+
16+
protected Client $client;
17+
18+
protected string $url;
19+
20+
protected array $filter;
21+
22+
protected bool $openLocalFilepath = false;
23+
24+
protected bool $isOpen = false;
25+
5926
public function __construct(Client $client, string $url, array $filter = [])
6027
{
6128
$this->client = $client;
6229
$this->url = $url;
6330
$this->filter = $filter;
6431
}
6532

66-
/**
67-
* @param boolean $openLocalFilepath
68-
*/
69-
public function setOpenLocalFilepath(bool $openLocalFilepath)
33+
public function setOpenLocalFilepath(bool $openLocalFilepath): void
7034
{
7135
$this->openLocalFilepath = $openLocalFilepath;
7236
}
7337

74-
/**
75-
* @return boolean
76-
*/
77-
public function valid(): bool
78-
{
79-
return !empty($this->current);
80-
}
81-
82-
/**
83-
* @return integer
84-
*/
8538
public function key(): int
8639
{
8740
return $this->i;
8841
}
8942

90-
/**
91-
* @return void
92-
*/
9343
public function rewind(): void
9444
{
9545
$this->i = 0;
@@ -98,17 +48,11 @@ public function rewind(): void
9848
$this->next();
9949
}
10050

101-
/**
102-
* @return boolean
103-
*/
10451
public function getIsOpen(): bool
10552
{
10653
return $this->isOpen;
10754
}
10855

109-
/**
110-
* @return void
111-
*/
11256
public function close(): void
11357
{
11458
$this->xmlReader->close();

src/Client.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
<?php
22

3-
namespace Tradebyte;
3+
declare(strict_types=1);
44

5-
use Tradebyte\Product\Tbcat;
5+
namespace Tradebyte;
66

77
/**
88
* Entry point of the library.
9-
*
10-
* @package Tradebyte
119
*/
1210
class Client
1311
{

src/Client/Rest.php

Lines changed: 16 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -1,86 +1,50 @@
11
<?php
22

3+
declare(strict_types=1);
4+
35
namespace Tradebyte\Client;
46

57
use XMLReader;
68

7-
/**
8-
* @package Tradebyte
9-
*/
109
class Rest
1110
{
12-
/**
13-
* @var integer
14-
*/
15-
private int $accountNumber;
16-
17-
/**
18-
* @var string
19-
*/
20-
private string $accountUser;
21-
22-
/**
23-
* @var string
24-
*/
25-
private string $accountPassword;
26-
27-
/**
28-
* @var string
29-
*/
11+
private ?int $accountNumber = null;
12+
13+
private ?string $accountUser = null;
14+
15+
private ?string $accountPassword = null;
16+
3017
private string $baseURL = 'https://rest.trade-server.net';
3118

32-
/**
33-
* @var string
34-
*/
3519
private string $userAgent = 'Tradebyte-SDK-PHP';
3620

37-
/**
38-
* @param integer $number
39-
*/
40-
public function setAccountNumber(int $number)
21+
public function setAccountNumber(int $number): void
4122
{
4223
$this->accountNumber = $number;
4324
}
4425

45-
/**
46-
* @param string $user
47-
*/
48-
public function setAccountUser(string $user)
26+
public function setAccountUser(string $user): void
4927
{
5028
$this->accountUser = $user;
5129
}
5230

53-
/**
54-
* @param string $password
55-
*/
56-
public function setAccountPassword(string $password)
31+
public function setAccountPassword(string $password): void
5732
{
5833
$this->accountPassword = $password;
5934
}
6035

61-
/**
62-
* @param string $baseURL
63-
*/
64-
public function setBaseURL(string $baseURL)
36+
public function setBaseURL(string $baseURL): void
6537
{
6638
$this->baseURL = $baseURL;
6739
}
6840

69-
/**
70-
* @return string
71-
*/
72-
private function getAuthHeader()
41+
private function getAuthHeader(): string
7342
{
7443
$auth = base64_encode($this->accountUser . ':' . $this->accountPassword);
7544
return 'Authorization: Basic ' . $auth;
7645
}
7746

78-
/**
79-
* @param string $url
80-
* @param array $filter
81-
* @return string
82-
*/
83-
private function getCreatedURI(string $url, array $filter = [])
47+
private function getCreatedURI(string $url, array $filter = []): string
8448
{
8549
$uri = $this->baseURL . '/' . $this->accountNumber . '/' . $url;
8650

@@ -91,21 +55,12 @@ private function getCreatedURI(string $url, array $filter = [])
9155
return $uri;
9256
}
9357

94-
/**
95-
* @param string $statusLine
96-
* @return integer
97-
*/
9858
private function getStatusCode(string $statusLine): int
9959
{
10060
preg_match('{HTTP\/\S*\s(\d{3})}', $statusLine, $match);
10161
return (int)$match[1];
10262
}
10363

104-
/**
105-
* @param string $localFilePath
106-
* @param string $url
107-
* @return string
108-
*/
10964
public function uploadFile(string $localFilePath, string $url): string
11065
{
11166
$localHandle = fopen($localFilePath, 'r');
@@ -118,18 +73,13 @@ public function uploadFile(string $localFilePath, string $url): string
11873
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
11974
curl_setopt($curl, CURLOPT_FAILONERROR, true);
12075
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3600);
121-
$response = curl_exec($curl);
76+
$response = (string)curl_exec($curl);
12277
fclose($localHandle);
12378
curl_close($curl);
12479

12580
return $response;
12681
}
12782

128-
/**
129-
* @param string $localFilePath
130-
* @param string $url
131-
* @return string
132-
*/
13383
public function postXMLFile(string $localFilePath, string $url): string
13484
{
13585
$localHandle = fopen($localFilePath, 'r');
@@ -142,19 +92,13 @@ public function postXMLFile(string $localFilePath, string $url): string
14292
curl_setopt($curl, CURLOPT_INFILESIZE, filesize($localFilePath));
14393
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
14494
curl_setopt($curl, CURLOPT_CONNECTTIMEOUT, 3600);
145-
$response = curl_exec($curl);
95+
$response = (string)curl_exec($curl);
14696
fclose($localHandle);
14797
curl_close($curl);
14898

14999
return $response;
150100
}
151101

152-
/**
153-
* @param string $localFilePath
154-
* @param string $url
155-
* @param array $filter
156-
* @return boolean
157-
*/
158102
public function downloadFile(string $localFilePath, string $url, array $filter = []): bool
159103
{
160104
$context = [
@@ -188,12 +132,6 @@ public function downloadFile(string $localFilePath, string $url, array $filter =
188132
return true;
189133
}
190134

191-
/**
192-
* @param string $filename
193-
* @param bool $useIncludePath
194-
* @param mixed[] $contextArray
195-
* @return mixed[]
196-
*/
197135
public function fileGetContents(string $filename, bool $useIncludePath, array $contextArray): array
198136
{
199137
$content = file_get_contents($filename, $useIncludePath, stream_context_create($contextArray));
@@ -204,11 +142,6 @@ public function fileGetContents(string $filename, bool $useIncludePath, array $c
204142
];
205143
}
206144

207-
/**
208-
* @param string $url
209-
* @param string $postData
210-
* @return string
211-
*/
212145
public function postXML(string $url, string $postData = ''): string
213146
{
214147
$context = [
@@ -235,11 +168,6 @@ public function postXML(string $url, string $postData = ''): string
235168
return $content;
236169
}
237170

238-
/**
239-
* @param string $url
240-
* @param mixed[] $filter
241-
* @return XMLReader
242-
*/
243171
public function getXML(string $url, array $filter = []): XMLReader
244172
{
245173
libxml_set_streams_context(stream_context_create([

0 commit comments

Comments
 (0)