Skip to content

Commit c431933

Browse files
- Update to php 7.4.
- Other fixes.
1 parent e2ab521 commit c431933

File tree

15 files changed

+74
-70
lines changed

15 files changed

+74
-70
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
}
2020
},
2121
"require": {
22+
"php/php": ">7.4.*",
2223
"guzzlehttp/guzzle": "^7.0",
2324
"ext-json": "*"
2425
}

src/Alias.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class Alias
1717
/**
1818
* @var \Typesence\Lib\Configuration
1919
*/
20-
private $config;
20+
private Configuration $config;
2121

2222
/**
2323
* @var string
2424
*/
25-
private $name;
25+
private string $name;
2626

2727
/**
2828
* @var \Typesence\ApiCall
2929
*/
30-
private $apiCall;
30+
private ApiCall $apiCall;
3131

3232
/**
3333
* Alias constructor.

src/Aliases.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class Aliases implements \ArrayAccess
1919
/**
2020
* @var \Typesence\Lib\Configuration
2121
*/
22-
private $config;
22+
private Configuration $config;
2323

2424
/**
2525
* @var \Typesence\ApiCall
2626
*/
27-
private $apiCall;
27+
private ApiCall $apiCall;
2828

2929
/**
3030
* @var array
3131
*/
32-
private $aliases = [];
32+
private array $aliases = [];
3333

3434
/**
3535
* Aliases constructor.
@@ -91,7 +91,6 @@ public function __get($name)
9191
return $this->aliases[$name];
9292
}
9393

94-
9594
/**
9695
* @inheritDoc
9796
*/

src/ApiCall.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,27 +31,27 @@ class ApiCall
3131
/**
3232
* @var \GuzzleHttp\Client
3333
*/
34-
private $client;
34+
private \GuzzleHttp\Client $client;
3535

3636
/**
3737
* @var \Typesence\Lib\Configuration
3838
*/
39-
private $config;
39+
private Configuration $config;
4040

4141
/**
4242
* @var array|\Typesence\Lib\Node[]
4343
*/
44-
private static $nodes;
44+
private static array $nodes;
4545

4646
/**
47-
* @var \Typesence\Lib\Node
47+
* @var \Typesence\Lib\Node|null
4848
*/
49-
private static $nearestNode;
49+
private static ?Node $nearestNode;
5050

5151
/**
5252
* @var int
5353
*/
54-
private $nodeIndex;
54+
private int $nodeIndex;
5555

5656
/**
5757
* ApiCall constructor.
@@ -182,14 +182,14 @@ private function makeRequest(string $method, string $endPoint, bool $asJson, arr
182182

183183
if (!(200 <= $statusCode && $statusCode < 300)) {
184184
$errorMessage = json_decode($response->getBody()
185-
->getContents(), true)['message'] ?? 'API error.';
185+
->getContents(), true, 512, JSON_THROW_ON_ERROR)['message'] ?? 'API error.';
186186
throw $this->getException($statusCode)
187187
->setMessage($errorMessage);
188188
}
189189

190190
return $asJson ? json_decode($response->getBody()
191-
->getContents(), true) : $response->getBody()
192-
->getContents();
191+
->getContents(), true, 512, JSON_THROW_ON_ERROR) : $response->getBody()
192+
->getContents();
193193
} catch (ClientException $exception) {
194194
if ($exception->getResponse()
195195
->getStatusCode() === 408) {

src/Client.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class Client
1717
/**
1818
* @var \Typesence\Lib\Configuration
1919
*/
20-
private $config;
20+
private Configuration $config;
2121

2222
/**
2323
* @var \Typesence\Collections
2424
*/
25-
public $collections;
25+
public Collections $collections;
2626

2727
/**
2828
* @var \Typesence\Aliases
2929
*/
30-
public $aliases;
30+
public Aliases $aliases;
3131

3232
/**
3333
* Client constructor.

src/Collection.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,27 @@ class Collection
1717
/**
1818
* @var \Typesence\Lib\Configuration
1919
*/
20-
private $config;
20+
private Configuration $config;
2121

2222
/**
2323
* @var string
2424
*/
25-
private $name;
25+
private string $name;
2626

2727
/**
2828
* @var \Typesence\ApiCall
2929
*/
30-
private $apiCall;
30+
private ApiCall $apiCall;
3131

3232
/**
3333
* @var \Typesence\Documents
3434
*/
35-
public $documents;
35+
public Documents $documents;
3636

3737
/**
3838
* @var \Typesence\Overrides
3939
*/
40-
public $overrides;
40+
public Overrides $overrides;
4141

4242
/**
4343
* Collection constructor.

src/Collections.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,17 @@ class Collections implements \ArrayAccess
1919
/**
2020
* @var \Typesence\Lib\Configuration
2121
*/
22-
private $config;
22+
private Configuration $config;
2323

2424
/**
2525
* @var \Typesence\ApiCall
2626
*/
27-
private $apiCall;
27+
private ApiCall $apiCall;
2828

2929
/**
3030
* @var array
3131
*/
32-
private $collections = [];
32+
private array $collections = [];
3333

3434
/**
3535
* Collections constructor.

src/Document.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,22 @@ class Document
1717
/**
1818
* @var \Typesence\Lib\Configuration
1919
*/
20-
private $config;
20+
private Configuration $config;
2121

2222
/**
2323
* @var string
2424
*/
25-
private $collectionName;
25+
private string $collectionName;
2626

2727
/**
28-
* @var int
28+
* @var string
2929
*/
30-
private $documentId;
30+
private string $documentId;
3131

3232
/**
3333
* @var \Typesence\ApiCall
3434
*/
35-
private $apiCall;
35+
private ApiCall $apiCall;
3636

3737
/**
3838
* Document constructor.

src/Documents.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,22 +19,22 @@ class Documents implements \ArrayAccess
1919
/**
2020
* @var \Typesence\Lib\Configuration
2121
*/
22-
private $config;
22+
private Configuration $config;
2323

2424
/**
2525
* @var string
2626
*/
27-
private $collectionName;
27+
private string $collectionName;
2828

2929
/**
3030
* @var \Typesence\ApiCall
3131
*/
32-
private $apiCall;
32+
private ApiCall $apiCall;
3333

3434
/**
3535
* @var array
3636
*/
37-
private $documents = [];
37+
private array $documents = [];
3838

3939
/**
4040
* Documents constructor.
@@ -74,13 +74,13 @@ public function create(array $document): array
7474
* @param array $documents
7575
*
7676
* @return array
77-
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException
77+
* @throws \Typesence\Exceptions\TypesenseClientError|\GuzzleHttp\Exception\GuzzleException|\JsonException
7878
*/
7979
public function createMany(array $documents): array
8080
{
81-
$res = $this->import(implode("\n", $documents));
81+
$res = $this->import(implode("\n", array_map(static fn(array $document) => json_encode($document, JSON_THROW_ON_ERROR), $documents)));
8282
return array_map(static function ($item) {
83-
return json_decode($item, true);
83+
return json_decode($item, true, 512, JSON_THROW_ON_ERROR);
8484
}, explode("\n", $res));
8585
}
8686

src/Key.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,17 +17,17 @@ class Key
1717
/**
1818
* @var \Typesence\Lib\Configuration
1919
*/
20-
private $config;
20+
private Configuration $config;
2121

2222
/**
2323
* @var \Typesence\ApiCall
2424
*/
25-
private $apiCall;
25+
private ApiCall $apiCall;
2626

2727
/**
2828
* @var string
2929
*/
30-
private $keyId;
30+
private string $keyId;
3131

3232
/**
3333
* Key constructor.

0 commit comments

Comments
 (0)