Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#

name: CI
permissions:
contents: read

on:
pull_request:
Expand All @@ -19,8 +21,6 @@ on:
push:
branches:
- 'master'
schedule:
- cron: '49 */8 * * *'

env:
COLUMNS: 120
Expand All @@ -34,7 +34,7 @@ jobs:
JBZOO_COMPOSER_UPDATE_FLAGS: ${{ matrix.composer_flags }}
strategy:
matrix:
php-version: [ 8.1, 8.2, 8.3 ]
php-version: [ 8.2, 8.3, 8.4 ]
coverage: [ xdebug, none ]
composer_flags: [ "--prefer-lowest", "" ]
steps:
Expand Down Expand Up @@ -68,7 +68,7 @@ jobs:
run: make report-coveralls --no-print-directory || true

- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: PHPUnit - ${{ matrix.php-version }} - ${{ matrix.coverage }}
Expand All @@ -80,7 +80,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 8.1, 8.2, 8.3 ]
php-version: [ 8.2, 8.3, 8.4 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -102,7 +102,7 @@ jobs:
run: make codestyle --no-print-directory

- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: Linters - ${{ matrix.php-version }}
Expand All @@ -114,7 +114,7 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
php-version: [ 8.1, 8.2, 8.3 ]
php-version: [ 8.2, 8.3, 8.4 ]
steps:
- name: Checkout code
uses: actions/checkout@v3
Expand All @@ -136,7 +136,7 @@ jobs:
run: make report-all --no-print-directory

- name: Upload Artifacts
uses: actions/upload-artifact@v3
uses: actions/upload-artifact@v4
continue-on-error: true
with:
name: Reports - ${{ matrix.php-version }}
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# JBZoo / Http-Client

[![CI](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Http-Client/coverage.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![Psalm Level](https://shepherd.dev/github/JBZoo/Http-Client/level.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/http-client/badge)](https://www.codefactor.io/repository/github/jbzoo/http-client/issues)
[![CI](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml/badge.svg?branch=master)](https://github.com/JBZoo/Http-Client/actions/workflows/main.yml?query=branch%3Amaster) [![Coverage Status](https://coveralls.io/repos/github/JBZoo/Http-Client/badge.svg?branch=master)](https://coveralls.io/github/JBZoo/Http-Client?branch=master) [![Psalm Coverage](https://shepherd.dev/github/JBZoo/Http-Client/coverage.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![Psalm Level](https://shepherd.dev/github/JBZoo/Http-Client/level.svg)](https://shepherd.dev/github/JBZoo/Http-Client) [![CodeFactor](https://www.codefactor.io/repository/github/jbzoo/http-client/badge)](https://www.codefactor.io/repository/github/jbzoo/http-client/issues)
[![Stable Version](https://poser.pugx.org/jbzoo/http-client/version)](https://packagist.org/packages/jbzoo/http-client/) [![Total Downloads](https://poser.pugx.org/jbzoo/http-client/downloads)](https://packagist.org/packages/jbzoo/http-client/stats) [![Dependents](https://poser.pugx.org/jbzoo/http-client/dependents)](https://packagist.org/packages/jbzoo/http-client/dependents?order_by=downloads) [![GitHub License](https://img.shields.io/github/license/jbzoo/http-client)](https://github.com/JBZoo/Http-Client/blob/master/LICENSE)


Expand Down Expand Up @@ -78,11 +78,11 @@ $httpClient = new HttpClient();

$results = $httpClient->multiRequest(array(
'request_0' => 'http://mockbin.org/request',

'request_1' => ['http://mockbin.org/request', [
'args' => ['key' => 'value']
]],

'request_2' => ['http://mockbin.org/request', [
'method' => 'post',
'args' => ['key' => 'value'],
Expand All @@ -93,13 +93,13 @@ $results = $httpClient->multiRequest(array(
'verify' => false,
'exceptions' => false,
'allow_redirects' => true,
'max_redirects' => 10,
'max_redirects' => 10,
'user_agent' => 'JBZoo/Http-Client v1.x-dev'
]]
]);

$results['request_0']->getBody();
$results['request_1']->getBody();
$results['request_0']->getBody();
$results['request_1']->getBody();
$results['request_2']->getBody();
```

Expand Down
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
"prefer-stable" : true,

"require" : {
"php" : "^8.1",
"php" : "^8.2",
"ext-json" : "*",

"jbzoo/data" : "^7.1",
"jbzoo/utils" : "^7.1",
"jbzoo/event" : "^7.0"
"jbzoo/data" : "^7.2",
"jbzoo/utils" : "^7.3",
"jbzoo/event" : "^7.0.2"
},

"require-dev" : {
"jbzoo/toolbox-dev" : "^7.1",
"rmccue/requests" : ">=2.0.10",
"guzzlehttp/guzzle" : ">=7.5.0"
"jbzoo/toolbox-dev" : "^7.2",
"rmccue/requests" : ">=2.0.15",
"guzzlehttp/guzzle" : ">=7.10.0"
},

"suggest" : {
Expand Down
3 changes: 3 additions & 0 deletions src/Driver/Auto.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@
use JBZoo\HttpClient\Request;
use JBZoo\HttpClient\Response;

/**
* @psalm-suppress UnusedClass
*/
final class Auto extends AbstractDriver
{
public function request(Request $request): Response
Expand Down
2 changes: 1 addition & 1 deletion src/Driver/Guzzle.php
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ private static function getDriverOptions(
Options $options,
array $headers,
string $method,
null|array|string $args,
array|string|null $args,
): array {
$headers['User-Agent'] = $options->getUserAgent('Guzzle');

Expand Down
5 changes: 4 additions & 1 deletion src/HttpClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function __construct(array $options = [])

public function request(
string $url,
null|array|string $args = null,
array|string|null $args = null,
string $method = Request::DEFAULT_METHOD,
array $options = [],
): Response {
Expand Down Expand Up @@ -105,6 +105,9 @@ public function setEventManager(EventManager $eManager): self
return $this;
}

/**
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function trigger(string $eventName, array $context = [], ?\Closure $callback = null): int
{
if ($this->eManager !== null) {
Expand Down
8 changes: 4 additions & 4 deletions src/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,14 @@ final class Request
public const DEFAULT_METHOD = self::GET;

private string $url = '';
private null|array|string $args = null;
private array|string|null $args = null;
private string $method = self::GET;
private array $headers = [];
private Options $options;

public function __construct(
string $url = '',
null|array|string $args = [],
array|string|null $args = [],
string $method = self::DEFAULT_METHOD,
array $headers = [],
array|Options $options = [],
Expand All @@ -62,7 +62,7 @@ public function setUrl(string $url): self
return $this;
}

public function setArgs(null|array|string $args): self
public function setArgs(array|string|null $args): self
{
$this->args = $args;

Expand Down Expand Up @@ -114,7 +114,7 @@ public function getUri(): string
return $this->url;
}

public function getArgs(): null|array|string
public function getArgs(): array|string|null
{
return $this->method === self::GET ? null : $this->args;
}
Expand Down
19 changes: 10 additions & 9 deletions src/Response.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,18 @@
* @property string $body
* @property null|float $time
*/
class Response
final class Response
{
protected int $internalCode = 0;
protected array $internalHeaders = [];
protected ?string $internalBody = null;
protected ?JSON $parsedJsonData = null;
protected ?float $time = null;
protected ?Request $originalRequest = null;
private int $internalCode = 0;
private array $internalHeaders = [];
private ?string $internalBody = null;
private ?JSON $parsedJsonData = null;
private ?float $time = null;
private ?Request $originalRequest = null;

/**
* @return null|array|float|int|string|string[]
* @psalm-suppress PossiblyUnusedReturnValue
*/
public function __get(string $name)
{
Expand Down Expand Up @@ -124,8 +125,8 @@ public function getXml(): JSON
$xmlAsArray = Xml::dom2Array(Xml::createFromString($this->internalBody));
} catch (\Exception $exception) {
throw new Exception(
"Can't parse xml document from HTTP response. " .
"Details: {$exception->getMessage()}",
"Can't parse xml document from HTTP response. "
. "Details: {$exception->getMessage()}",
);
}

Expand Down
2 changes: 2 additions & 0 deletions tests/AbstractDriverTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ abstract class AbstractDriverTest extends PHPUnit

public function testSimple(): void
{
skip('Flaky test');
$url = 'https://run.mocky.io/v3/965f7c10-5a16-4e13-a9b9-2bcfd30a25f2';
$result = $this->getClient()->request($url);

Expand Down Expand Up @@ -171,6 +172,7 @@ public function testStatus404(): void

public function testStatus404Body(): void
{
skip('Flaky test');
$result = $this->getClient()->request('https://run.mocky.io/v3/037dd813-edd9-4cc9-bab9-9244c0b5c5ec');

isSame(404, $result->code);
Expand Down
Loading