Skip to content

Commit 7e46010

Browse files
authored
strict_types=1 (#10)
* strict_types=1 * Finalize classes * Fixes doc types
1 parent 4f2ff50 commit 7e46010

24 files changed

+105
-37
lines changed

.gitattributes

+10
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,14 @@
1111
# @link https://github.com/JBZoo/Http-Client
1212
#
1313

14+
/.phan export-ignore
15+
/build export-ignore
16+
/tests export-ignore
17+
/.editorconfig export-ignore
18+
/.gitattributes export-ignore
19+
/.gitignore export-ignore
20+
/.travis.yml export-ignore
21+
/phpunit.xml.dist export-ignore
22+
/Makefile export-ignore
23+
1424
* text eol=lf

.phan/config.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
$default = include __DIR__ . '/../vendor/jbzoo/codestyle/src/phan/default.php';
1719

1820
return array_merge($default, [

.travis.yml

+8
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,14 @@ php:
1919
- 7.2
2020
- 7.3
2121
- 7.4
22+
- 8.0
23+
- nightly
24+
25+
jobs:
26+
fast_finish: true
27+
allow_failures:
28+
- php: 8.0
29+
- php: nightly
2230

2331
env:
2432
matrix:

README.md

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# JBZoo / Http-Client
22

3-
[![Build Status](https://travis-ci.org/JBZoo/Http-Client.svg)](https://travis-ci.org/JBZoo/Http-Client) [![Coverage Status](https://coveralls.io/repos/JBZoo/Http-Client/badge.svg)](https://coveralls.io/github/JBZoo/Http-Client) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Http-Client/coverage.svg)](https://shepherd.dev/github/JBZoo/Http-Client)
3+
[![Build Status](https://travis-ci.org/JBZoo/Http-Client.svg)](https://travis-ci.org/JBZoo/Http-Client) [![Coverage Status](https://coveralls.io/repos/JBZoo/Http-Client/badge.svg)](https://coveralls.io/github/JBZoo/Http-Client) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Http-Client/coverage.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![PHP Strict Types](https://img.shields.io/badge/strict__types-%3D1-brightgreen)](https://www.php.net/manual/en/language.types.declarations.php#language.types.declarations.strict)
44
[![Stable Version](https://poser.pugx.org/jbzoo/http-client/version)](https://packagist.org/packages/jbzoo/http-client) [![Latest Unstable Version](https://poser.pugx.org/jbzoo/http-client/v/unstable)](https://packagist.org/packages/jbzoo/http-client) [![Dependents](https://poser.pugx.org/jbzoo/http-client/dependents)](https://packagist.org/packages/jbzoo/http-client/dependents?order_by=downloads) [![GitHub Issues](https://img.shields.io/github/issues/jbzoo/http-client)](https://github.com/JBZoo/Http-Client/issues) [![Total Downloads](https://poser.pugx.org/jbzoo/http-client/downloads)](https://packagist.org/packages/jbzoo/http-client/stats) [![GitHub License](https://img.shields.io/github/license/jbzoo/http-client)](https://github.com/JBZoo/Http-Client/blob/master/LICENSE)
55

66

@@ -10,7 +10,7 @@ Just make HTTP requests in one line and don't care about terrible syntax of Guzz
1010

1111
## Install
1212
```sh
13-
composer require guzzlehttp/guzzle --no-update # Recomended, but not required
13+
composer require guzzlehttp/guzzle --no-update # Recommended, but not required
1414
composer require jbzoo/http-client
1515
```
1616

@@ -32,7 +32,7 @@ $httpClient = new HttpClient([
3232
'verify' => false, // Check cert for SSL
3333
'exceptions' => false, // Show exceptions for statuses 4xx and 5xx
3434
'allow_redirects' => true, // Show real 3xx-header or result?
35-
'max_redirects' => 10, // How much to reirect?
35+
'max_redirects' => 10, // How much to redirect?
3636
'user_agent' => "It's me", // Custom UserAgent
3737
]);
3838

@@ -70,7 +70,10 @@ $value = $json->find('key.nested', 'default', 'trim');
7070

7171

7272
## Asynchronous requests (curl_multi_* for parallels)
73+
7374
```php
75+
use JBZoo\HttpClient\HttpClient;
76+
7477
$httpClient = new HttpClient();
7578

7679
$results = $httpClient->multiRequest(array(

composer.json

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
"php" : ">=7.2",
1818
"ext-json" : "*",
1919

20-
"jbzoo/data" : "^4.1.3",
21-
"jbzoo/utils" : "^4.2.3",
20+
"jbzoo/data" : "^4.2.0",
21+
"jbzoo/utils" : "^4.3.0",
2222
"guzzlehttp/promises" : ">=1.4.0"
2323
},
2424

2525
"require-dev" : {
26-
"jbzoo/toolbox-dev" : "^2.6.2",
27-
"jbzoo/event" : "^3.0.3",
26+
"jbzoo/toolbox-dev" : "^2.10.0",
27+
"jbzoo/event" : "^3.1.0",
2828
"rmccue/requests" : "^1.7.0",
2929
"guzzlehttp/guzzle" : ">=6.5.5"
3030
},

src/Driver/AbstractDriver.php

+2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient\Driver;
1719

1820
use JBZoo\HttpClient\Request;

src/Driver/Auto.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient\Driver;
1719

1820
use GuzzleHttp\Client;
@@ -23,7 +25,7 @@
2325
* Class Auto
2426
* @package JBZoo\HttpClient\Driver
2527
*/
26-
class Auto extends AbstractDriver
28+
final class Auto extends AbstractDriver
2729
{
2830
/**
2931
* @inheritDoc

src/Driver/Guzzle.php

+7-5
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient\Driver;
1719

1820
use GuzzleHttp\Client;
@@ -25,7 +27,7 @@
2527
* Class Guzzle
2628
* @package JBZoo\HttpClient\Driver
2729
*/
28-
class Guzzle extends AbstractDriver
30+
final class Guzzle extends AbstractDriver
2931
{
3032
/**
3133
* @inheritDoc
@@ -97,7 +99,7 @@ public function multiRequest(array $requestList): array
9799
* @param string|array|null $args
98100
* @return array
99101
*/
100-
protected static function getDriverOptions(Options $options, array $headers, string $method, $args): array
102+
private static function getDriverOptions(Options $options, array $headers, string $method, $args): array
101103
{
102104
$headers['User-Agent'] = $options->getUserAgent('Guzzle');
103105

@@ -127,11 +129,11 @@ protected static function getDriverOptions(Options $options, array $headers, str
127129

128130
/**
129131
* @param Options $options
130-
* @return array|bool
132+
* @return array|null
131133
*/
132-
protected static function getAllowRedirects(Options $options)
134+
private static function getAllowRedirects(Options $options): ?array
133135
{
134-
$allowRedirects = false;
136+
$allowRedirects = null;
135137

136138
if ($options->isAllowRedirects()) {
137139
$allowRedirects = [

src/Driver/Rmccue.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient\Driver;
1719

1820
use JBZoo\HttpClient\Exception;
@@ -26,7 +28,7 @@
2628
* Class Rmccue
2729
* @package JBZoo\HttpClient\Driver
2830
*/
29-
class Rmccue extends AbstractDriver
31+
final class Rmccue extends AbstractDriver
3032
{
3133
private const INVALID_CODE_LINE = HttpCodes::BAD_REQUEST;
3234

@@ -39,7 +41,7 @@ public function request(Request $request): Response
3941

4042
/**
4143
* @psalm-suppress PossiblyInvalidArgument
42-
* @phan-suppress PhanPartialTypeMismatchArgument
44+
* @phan-suppress PhanPartialTypeMismatchArgument
4345
*/
4446
$httpResult = Requests::request(
4547
$request->getUri(),
@@ -95,7 +97,7 @@ public function multiRequest(array $requestList): array
9597
* @param Options $options
9698
* @return array
9799
*/
98-
protected static function getDriverOptions(Options $options): array
100+
private static function getDriverOptions(Options $options): array
99101
{
100102
return [
101103
'timeout' => $options->getTimeout(),

src/Exception.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient;
1719

1820
use JBZoo\Event\EventManager;
@@ -21,7 +23,7 @@
2123
* Class Exception
2224
* @package JBZoo\HttpClient
2325
*/
24-
class Exception extends \RuntimeException
26+
final class Exception extends \RuntimeException
2527
{
2628
/**
2729
* Exception constructor.

src/HttpClient.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient;
1719

1820
use JBZoo\Event\EventManager;
@@ -22,7 +24,7 @@
2224
* Class HttpClient
2325
* @package JBZoo\HttpClient
2426
*/
25-
class HttpClient
27+
final class HttpClient
2628
{
2729
/**
2830
* @var Options
@@ -152,7 +154,7 @@ protected function getDriver(): AbstractDriver
152154
* @param EventManager $eManager
153155
* @return $this
154156
*/
155-
public function setEventManager(EventManager $eManager)
157+
public function setEventManager(EventManager $eManager): self
156158
{
157159
$this->eManager = $eManager;
158160
return $this;
@@ -162,9 +164,9 @@ public function setEventManager(EventManager $eManager)
162164
* @param string $eventName
163165
* @param array $context
164166
* @param \Closure|null $callback
165-
* @return int|string
167+
* @return int
166168
*/
167-
public function trigger(string $eventName, array $context = [], ?\Closure $callback = null)
169+
public function trigger(string $eventName, array $context = [], ?\Closure $callback = null): int
168170
{
169171
if (!$this->eManager) {
170172
return 0;

src/HttpCodes.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient;
1719

1820
/**
1921
* Class HttpCodes
2022
* @package JBZoo\HttpClient
2123
*/
22-
class HttpCodes
24+
final class HttpCodes
2325
{
2426
/**
2527
* @var string[]

src/Options.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient;
1719

1820
use JBZoo\Data\Data;
@@ -24,7 +26,7 @@
2426
* Class Options
2527
* @package JBZoo\HttpClient
2628
*/
27-
class Options
29+
final class Options
2830
{
2931
public const DEFAULT_DRIVER = 'Guzzle';
3032
public const DEFAULT_TIMEOUT = 10;

src/Request.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient;
1719

1820
use JBZoo\Utils\Url;
@@ -21,7 +23,7 @@
2123
* Class Request
2224
* @package JBZoo\HttpClient
2325
*/
24-
class Request
26+
final class Request
2527
{
2628
public const GET = 'GET';
2729
public const HEAD = 'HEAD';

src/Response.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\HttpClient;
1719

1820
use JBZoo\Data\JSON;
@@ -27,7 +29,7 @@
2729
* @property string $body
2830
* @property float|null $time
2931
*/
30-
class Response
32+
final class Response
3133
{
3234
/**
3335
* @var int
@@ -157,7 +159,7 @@ public function getXml(): JSON
157159
* @param string $name
158160
* @return array|string|float|int|string[]|null
159161
*/
160-
public function __get($name)
162+
public function __get(string $name)
161163
{
162164
if ('code' === $name) {
163165
return $this->getCode();

tests/AbstractDriverTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\PHPUnit;
1719

1820
use JBZoo\HttpClient\HttpClient;
@@ -97,7 +99,7 @@ public function testAllMethods()
9799
}
98100

99101
isSame(200, $result->getCode(), $message);
100-
isContain('application/json', $result->getHeader('Content-Type'), $message);
102+
isContain('application/json', $result->getHeader('Content-Type'), false, $message);
101103
isSame($method, $body->find('queryString.method'), $message);
102104
isSame($method, $body->find('method'), $message);
103105

tests/DriverGuzzleTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\PHPUnit;
1719

1820
/**
1921
* Class RmccueDriverTest
2022
* @package JBZoo\PHPUnit
2123
*/
22-
class DriverGuzzleTest extends AbstractDriverTest
24+
final class DriverGuzzleTest extends AbstractDriverTest
2325
{
2426
protected $driver = 'Guzzle';
2527
}

tests/DriverRmccueTest.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@
1313
* @link https://github.com/JBZoo/Http-Client
1414
*/
1515

16+
declare(strict_types=1);
17+
1618
namespace JBZoo\PHPUnit;
1719

1820
/**
1921
* Class DriverRmccueTest
2022
* @package JBZoo\PHPUnit
2123
*/
22-
class DriverRmccueTest extends AbstractDriverTest
24+
final class DriverRmccueTest extends AbstractDriverTest
2325
{
2426
protected $driver = 'Rmccue';
2527
}

0 commit comments

Comments
 (0)