Skip to content

Commit 3b3a91c

Browse files
committed
Refactor for php 8
1 parent 88a1e4f commit 3b3a91c

File tree

8 files changed

+37
-59
lines changed

8 files changed

+37
-59
lines changed

.github/workflows/build.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ jobs:
55
runs-on: ubuntu-latest
66
strategy:
77
matrix:
8-
php-versions: [ '7.3', '7.4', '8.0' ]
8+
php-versions: [ '8.0', '8.1' ]
99
name: Testing on PHP ${{ matrix.php-versions }}
1010
steps:
1111
- name: Checkout
@@ -19,4 +19,6 @@ jobs:
1919
- name: Install dependencies
2020
run: composer install --quiet --no-ansi --no-interaction --no-scripts --no-progress
2121
- name: Run tests
22+
env:
23+
COLISSIMO_ID: ${{ secrets.COLISSIMO_ID }}
2224
run: composer test

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,4 @@
33
.DS_Store
44
composer.lock
55
.phpunit.result.cache
6+
/phpunit.xml

LICENSE.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
The MIT License (MIT)
22

3-
Copyright (c) 2016 hedii
3+
Copyright (c) Hedi Chaibi (hedii)
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
@@ -9,13 +9,13 @@ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
99
copies of the Software, and to permit persons to whom the Software is
1010
furnished to do so, subject to the following conditions:
1111

12-
The above copyright notice and this permission notice shall be included in all
13-
copies or substantial portions of the Software.
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
1414

1515
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1616
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1717
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,
20-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21-
SOFTWARE.
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
A php package to track Colissimo (La Poste) parcels
55

66
### Requirements
7-
- PHP 7.3, 7.4 or 8.0
7+
- PHP >=8.0
88
- Curl PHP Extension
99
- Json PHP Extension
1010

@@ -251,9 +251,14 @@ array(4) {
251251
}
252252
````
253253

254-
### Run tests
254+
### Testing
255+
256+
Update the id in `phpunit.xml` file and run:
255257

256258
````bash
257259
composer test
258260
````
259-
You may need to update the id in */tests/ColissimoApiTest.php* because the id is only valid for 90 days.
261+
262+
## License
263+
264+
colissimo-api is released under the MIT Licence. See the bundled [LICENSE](https://github.com/hedii/colissimo-api/blob/master/LICENSE.md) file for details.

composer.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,13 @@
1717
"email": "contact@hedichaibi.com"
1818
},
1919
"require": {
20-
"php": "^7.3|^8.0",
20+
"php": "^8.0",
2121
"ext-curl": "*",
2222
"ext-json": "*",
23-
"guzzlehttp/guzzle": "^6.5|7.0.1"
23+
"guzzlehttp/guzzle": "^7.0.1"
2424
},
2525
"require-dev": {
26-
"phpunit/phpunit": "^9.3.3"
26+
"phpunit/phpunit": "^9.5.10"
2727
},
2828
"autoload": {
2929
"psr-4": {

phpunit.xml renamed to phpunit.xml.dist

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,7 @@
77
<directory suffix="Test.php">./tests/</directory>
88
</testsuite>
99
</testsuites>
10+
<php>
11+
<!--<env name="COLISSIMO_ID" value="your_colissimo_id_here"/>-->
12+
</php>
1013
</phpunit>

src/ColissimoApi.php

Lines changed: 8 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,42 +2,28 @@
22

33
namespace Hedii\ColissimoApi;
44

5-
use Exception;
65
use GuzzleHttp\Client;
76
use GuzzleHttp\Cookie\SetCookie;
87
use GuzzleHttp\Exception\ClientException;
98
use GuzzleHttp\Exception\RequestException;
9+
use Throwable;
1010

1111
class ColissimoApi
1212
{
13-
/**
14-
* The http client instance.
15-
*
16-
* @var \GuzzleHttp\Client
17-
*/
18-
private $client;
13+
private Client $client;
1914

20-
/**
21-
* ColissimoApi constructor.
22-
*
23-
* @param int $connectionTimeout
24-
* @param int $timeout
25-
* @param bool $verify
26-
*/
2715
public function __construct(int $connectionTimeout = 10, int $timeout = 30, bool $verify = false)
2816
{
2917
$this->client = new Client([
3018
'connect_timeout' => $connectionTimeout,
3119
'timeout' => $timeout,
32-
'verify' => $verify
20+
'verify' => $verify,
3321
]);
3422
}
3523

3624
/**
3725
* Get the colissimo status.
3826
*
39-
* @param string $id
40-
* @return array
4127
* @throws \Hedii\ColissimoApi\ColissimoApiException
4228
*/
4329
public function get(string $id): array
@@ -49,11 +35,11 @@ public function get(string $id): array
4935
'Accept' => 'application/json',
5036
'referer' => "https://www.laposte.fr/outils/suivre-vos-envois?code={$id}",
5137
'Origin' => 'https://www.laposte.fr',
52-
'Authorization' => "Bearer {$this->getToken($id)}"
53-
]
38+
'Authorization' => "Bearer {$this->getToken($id)}",
39+
],
5440
]);
5541

56-
return json_decode($response->getBody()->getContents(), true);
42+
return json_decode($response->getBody()->getContents(), associative: true);
5743
} catch (ClientException $exception) {
5844
throw new ColissimoApiException(
5945
$exception->getResponse()->getReasonPhrase(),
@@ -72,16 +58,15 @@ public function get(string $id): array
7258
: $exception->getMessage()
7359
);
7460
}
75-
} catch (Exception $exception) {
61+
} catch (Throwable $exception) {
7662
throw new ColissimoApiException($exception->getMessage(), 1, $exception);
7763
}
7864
}
7965

8066
/**
8167
* Get the JWT token.
8268
*
83-
* @param string $id
84-
* @return string
69+
* @throws \GuzzleHttp\Exception\GuzzleException
8570
*/
8671
private function getToken(string $id): string
8772
{

tests/ColissimoApiTest.php

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -8,34 +8,16 @@
88

99
class ColissimoApiTest extends TestCase
1010
{
11-
/**
12-
* A valid colissimo id.
13-
*
14-
* @var string
15-
*/
16-
private $id = '9L27129283299';
17-
18-
/**
19-
* An invalid colissimo id.
20-
*
21-
* @var string
22-
*/
23-
private $invalidId = 'x9V01144112123';
24-
25-
/**
26-
* A ColissimoApi instance.
27-
*
28-
* @var \Hedii\ColissimoApi\ColissimoApi
29-
*/
30-
private $colissimo;
31-
32-
/**
33-
* This method is called before each test.
34-
*/
11+
private string $invalidId = 'x9V01144112123';
12+
13+
private ColissimoApi $colissimo;
14+
3515
public function setUp(): void
3616
{
3717
parent::setUp();
3818

19+
$this->id = getenv('COLISSIMO_ID');
20+
3921
$this->colissimo = new ColissimoApi();
4022
}
4123

0 commit comments

Comments
 (0)