Skip to content

Commit c2fa550

Browse files
committed
Require PHP 8.2, refactor
1 parent 7600ece commit c2fa550

30 files changed

+500
-431
lines changed

LICENCE.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License
22

3-
Copyright (c) 2020 Roy de Vos Burchart
3+
Copyright (c) 2024 Roy de Vos Burchart
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal
@@ -18,4 +18,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1818
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1919
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2020
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21-
THE SOFTWARE.
21+
THE SOFTWARE.

README.md

+19-12
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
A simple PHP wrapper around [Tripleseat's API](https://support.tripleseat.com/hc/en-us/sections/200821727-Tripleseat-API).
44

5-
Requires at least PHP 7.1
5+
Requires at least PHP 8.2
66

77
Until v1 there may be backward incompatible changes with every minor version (0.x).
88

@@ -59,10 +59,15 @@ An `InvalidSite` exception will be thrown if the site is not in the list of site
5959
$mySite = $tripleseat[1];
6060

6161
// Search accounts in this site
62-
$mySite->account->search(['query' => 'tripleseat']);
62+
$mySite->account->search([
63+
'query' => 'tripleseat'
64+
]);
6365

6466
// is the same as
65-
$tripleseat->account->search(['query' => 'tripleseat', 'site_id' => 1]);
67+
$tripleseat->account->search([
68+
'query' => 'tripleseat',
69+
'site_id' => 1
70+
]);
6671
```
6772

6873
#### What does it do in the background?
@@ -87,13 +92,18 @@ $mySite = new Tripleseat([
8792
Endpoints like `site`, `location`, and `user` don't support the `site_id` parameter. They will always return the same result regardless of what site ID is passed.
8893

8994
### `all` and `search` operations
90-
When querying one of the `all` or `search` endpoints, the client will return a Generator that you can iterate through. These endpoints are paged and return 50 results per page. The client will check the `total_pages` property in the first response and make sure every page gets loaded. The next page will only get loaded once the iterator gets to that point.
95+
When querying one of the `all` or `search` endpoints, the client will return a PaginatedResponse. These endpoints are paged and return 50 results per page.
9196

92-
Call [`iterator_to_array` (?)](https://www.php.net/manual/en/function.iterator-to-array.php) to convert the Generator to an array and load all pages immediately.
97+
The PaginatedResponse class is iterable (over the results loaded in that page). It also features the following helpers:
98+
- `currentPage(): int` - gets the current page number
99+
- `totalPages(): int` - gets the total number of pages
100+
- `hasMore(): bool` - checks if the page number is below the total number of pages
101+
- `next(): ?PaginatedResponse` - get the next page (if applicable)
102+
- `results(): array` - get an array of this page's results
103+
- `all(): array` - load results from all pages into an array
104+
- `untilPage(int $page): array` - load results from current until given page into an array
93105

94-
Additionally, you may provide a `$firstPage` or `$untilPage` on these operations to change from which page on and/or until which page the data should be loaded (provided it's less than the total number of pages).
95-
96-
Note: The `site` and `location` services are not paged and do not feature the `$firstPage` or `$untilPage` arguments.
106+
Note: The `site` and `location` services are not paged.
97107

98108
```php
99109
$bookings = $tripleseat->booking->search([
@@ -104,9 +114,6 @@ $bookings = $tripleseat->booking->search([
104114
foreach($bookings as $booking) {
105115
// do something with $booking
106116
}
107-
108-
// convert from Generator to array
109-
$bookingsArray = iterator_to_array($bookings);
110117
```
111118

112119
### Other operations
@@ -186,4 +193,4 @@ You could use any [PSR-18](https://www.php-fig.org/psr/psr-18/) compatible clien
186193
```php
187194
$httpClient = // some class implementing Psr\Http\Client\ClientInterface
188195
$tripleseat = new Tripleseat($auth, $httpClient);
189-
```
196+
```

composer.json

+4-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
"license": "MIT",
55
"type": "library",
66
"require": {
7-
"php": ">=7.4",
7+
"php": "^8.2",
88
"ext-json": "*",
99
"php-http/client-implementation": "^1.0",
1010
"psr/http-factory": "^1.0",
@@ -14,10 +14,11 @@
1414
"require-dev": {
1515
"phpunit/phpunit": "^8.5",
1616
"guzzlehttp/psr7": "^1.6",
17-
"guzzlehttp/guzzle": "7.0.1",
17+
"guzzlehttp/guzzle": "^7.0",
1818
"php-http/guzzle7-adapter": "0.1.1",
1919
"http-interop/http-factory-guzzle": "^1.0",
20-
"symfony/var-dumper" : "5.2.x-dev"
20+
"symfony/var-dumper" : "5.2.x-dev",
21+
"laravel/pint": "^1.14"
2122
},
2223
"autoload": {
2324
"psr-4": {

pint.json

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"preset": "laravel",
3+
"rules": {
4+
"class_attributes_separation": {
5+
"elements": {
6+
"const": "only_if_meta"
7+
}
8+
},
9+
"concat_space": {
10+
"spacing": "one"
11+
},
12+
"elseif": false,
13+
"function_declaration": {
14+
"closure_fn_spacing": "none"
15+
},
16+
"no_extra_blank_lines": {
17+
"tokens": [
18+
"throw",
19+
"use",
20+
"extra",
21+
"return",
22+
"curly_brace_block"
23+
]
24+
},
25+
"not_operator_with_successor_space": false,
26+
"trailing_comma_in_multiline": {
27+
"elements": [
28+
"arrays",
29+
"match",
30+
"parameters"
31+
]
32+
},
33+
"type_declaration_spaces": {
34+
"elements": [
35+
"function"
36+
]
37+
},
38+
"phpdoc_align": false
39+
}
40+
}

src/Contracts/Http.php

+8-6
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
<?php namespace Tripleseat\Contracts;
1+
<?php
2+
3+
namespace Tripleseat\Contracts;
24

35
interface Http
46
{
5-
public function get(string $path, array $query = []);
7+
public function get(string $path, array $query = []): array;
68

7-
public function post(string $path, $body = null, array $query = []);
9+
public function post(string $path, ?array $body = null, array $query = []): array;
810

9-
public function put(string $path, $body = null, array $query = []);
11+
public function put(string $path, ?array $body = null, array $query = []): array;
1012

11-
public function delete(string $path, array $query = []);
12-
}
13+
public function delete(string $path, array $query = []): array;
14+
}

src/Exceptions/HttpException.php

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
1-
<?php namespace Tripleseat\Exceptions;
1+
<?php
2+
3+
namespace Tripleseat\Exceptions;
24

35
use Exception;
46

57
class HttpException extends Exception implements TripleseatException
68
{
7-
89
public $httpStatus = 0;
910
public $httpMessage = null;
1011
public $httpBody = null;
@@ -29,7 +30,7 @@ public function getMessageFromHttpBody()
2930
return $this->httpBody;
3031
}
3132

32-
public function __toString()
33+
public function __toString(): string
3334
{
3435
$base = 'Tripleseat HttpException: Http Status: ' . $this->httpStatus;
3536

@@ -39,5 +40,4 @@ public function __toString()
3940

4041
return $base;
4142
}
42-
43-
}
43+
}
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<?php namespace Tripleseat\Exceptions;
1+
<?php
2+
3+
namespace Tripleseat\Exceptions;
24

35
class InvalidArgumentException extends \InvalidArgumentException implements TripleseatException
46
{
5-
6-
}
7+
}
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<?php namespace Tripleseat\Exceptions;
1+
<?php
2+
3+
namespace Tripleseat\Exceptions;
24

35
class InvalidAuthConfiguration extends \InvalidArgumentException implements TripleseatException
46
{
5-
6-
}
7+
}

src/Exceptions/InvalidService.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?php namespace Tripleseat\Exceptions;
1+
<?php
2+
3+
namespace Tripleseat\Exceptions;
24

35
use Exception;
46

57
class InvalidService extends Exception implements TripleseatException
68
{
7-
8-
}
9+
}

src/Exceptions/InvalidSite.php

+4-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
<?php namespace Tripleseat\Exceptions;
1+
<?php
2+
3+
namespace Tripleseat\Exceptions;
24

35
use Exception;
46

57
class InvalidSite extends Exception implements TripleseatException
68
{
7-
8-
}
9+
}
+4-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
<?php namespace Tripleseat\Exceptions;
1+
<?php
2+
3+
namespace Tripleseat\Exceptions;
24

35
interface TripleseatException
46
{
5-
6-
}
7+
}

0 commit comments

Comments
 (0)