Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Guzzle 7.x is supported now #13

Merged
merged 5 commits into from
Sep 9, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ jobs: # Docs: <https://git.io/JvxXE>
run: composer update --prefer-dist --no-suggest --ansi

- name: Show most important packages versions
run: composer info | grep -e phpunit -e phpstan
run: composer info | grep -e phpunit/phpunit -e phpstan/phpstan -e guzzlehttp/guzzle

- name: Execute tests
if: matrix.coverage != 'yes'
Expand Down
5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@ All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog][keepachangelog] and this project adheres to [Semantic Versioning][semver].

## UNRELEASED
## v3.4.0

### Changed

- Guzzle 7 (`guzzlehttp/guzzle`) is supported now
- Dependency `tarampampam/wrappers-php` version `~2.0` is supported
- Code annotations is more strict
- CI completely moved from "Travis CI" to "Github Actions" _(travis builds disabled)_
- Minimal required PHP version now is `7.2`

Expand Down
6 changes: 3 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
FROM php:7.2.5-alpine
FROM php:7.3.5-alpine

ENV \
COMPOSER_ALLOW_SUPERUSER="1" \
COMPOSER_HOME="/tmp/composer"

COPY --from=composer:1.10.7 /usr/bin/composer /usr/bin/composer
COPY --from=composer:1.10.10 /usr/bin/composer /usr/bin/composer

RUN set -x \
&& apk add --no-cache binutils git \
&& apk add --no-cache --virtual .build-deps autoconf pkgconf make g++ gcc 1>/dev/null \
# install xdebug (for testing with code coverage), but do not enable it
&& pecl install xdebug-2.9.1 1>/dev/null \
&& pecl install xdebug-2.9.6 1>/dev/null \
&& apk del .build-deps \
&& mkdir /src ${COMPOSER_HOME} \
&& composer global require 'hirak/prestissimo' --no-interaction --no-suggest --prefer-dist \
Expand Down
19 changes: 8 additions & 11 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@
# Makefile readme (ru): <http://linux.yaroslavl.ru/docs/prog/gnu_make_3-79_russian_manual.html>
# Makefile readme (en): <https://www.gnu.org/software/make/manual/html_node/index.html#SEC_Contents>

dc_bin := $(shell command -v docker-compose 2> /dev/null)

SHELL = /bin/sh
RUN_APP_ARGS = --rm --user "$(shell id -u):$(shell id -g)" app
RUN_APP_ARGS = --rm --user "$(shell id -u):$(shell id -g)"

.PHONY : help build latest install lowest test test-cover shell clean
.DEFAULT_GOAL : help
Expand All @@ -16,26 +14,25 @@ help: ## Show this help
@awk 'BEGIN {FS = ":.*?## "} /^[a-zA-Z_-]+:.*?## / {printf " \033[32m%-14s\033[0m %s\n", $$1, $$2}' $(MAKEFILE_LIST)

build: ## Build docker images, required for current package environment
$(dc_bin) build
docker-compose build

latest: clean ## Install latest php dependencies
$(dc_bin) run $(RUN_APP_ARGS) composer update -n --ansi --no-suggest --prefer-dist --prefer-stable
docker-compose run $(RUN_APP_ARGS) app composer update -n --ansi --no-suggest --prefer-dist --prefer-stable

install: clean ## Install regular php dependencies
$(dc_bin) run $(RUN_APP_ARGS) composer update -n --prefer-dist --no-interaction --no-suggest
docker-compose run $(RUN_APP_ARGS) app composer update -n --prefer-dist --no-interaction --no-suggest

lowest: clean ## Install lowest php dependencies
$(dc_bin) run $(RUN_APP_ARGS) composer update -n --ansi --no-suggest --prefer-dist --prefer-lowest
docker-compose run $(RUN_APP_ARGS) app composer update -n --ansi --no-suggest --prefer-dist --prefer-lowest

test: ## Execute php tests and linters
$(dc_bin) run $(RUN_APP_ARGS) composer test
docker-compose run $(RUN_APP_ARGS) app composer test

test-cover: ## Execute php tests with coverage
$(dc_bin) run --rm --user "0:0" app sh -c 'docker-php-ext-enable xdebug && su $(shell whoami) -s /bin/sh -c "composer phpunit-cover"'
docker-compose run --rm --user "0:0" app sh -c 'docker-php-ext-enable xdebug && su $(shell whoami) -s /bin/sh -c "composer phpunit-cover"'

shell: ## Start shell into container with php
$(dc_bin) run -e "PS1=\[\033[1;32m\]\[\033[1;36m\][\u@docker] \[\033[1;34m\]\w\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]" \
$(RUN_APP_ARGS) sh
docker-compose run $(RUN_APP_ARGS) app sh

clean: ## Remove all dependencies and unimportant files
-rm -Rf ./composer.lock ./vendor ./coverage
13 changes: 7 additions & 6 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@
"php": "^7.2",
"ext-curl": "*",
"ext-json": "*",
"guzzlehttp/guzzle": "^6.0",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.0 || ~7.0",
"ocramius/package-versions": "^1.2",
"tarampampam/wrappers-php": "^1.5"
"tarampampam/wrappers-php": "^1.5 || ~2.0"
},
"require-dev": {
"fzaninotto/faker": "^1.9.1",
"mockery/mockery": "^1.3",
"phpstan/phpstan": "^0.12.1",
"phpunit/phpunit": "^7.5",
"tarampampam/guzzle-url-mock": "^1.1",
"vlucas/phpdotenv": "^3.4"
"phpstan/phpstan": "~0.12",
"phpunit/phpunit": "^8.5.4",
"tarampampam/guzzle-url-mock": "^1.3",
"vlucas/phpdotenv": "^3.4 || ^4.0 || ^5.0"
},
"autoload": {
"psr-4": {
Expand Down
2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ services:
build:
context: .
dockerfile: Dockerfile
environment:
PS1: '\[\033[1;32m\]\[\033[1;36m\][\u@docker] \[\033[1;34m\]\w\[\033[0;35m\] \[\033[1;36m\]# \[\033[0m\]'
volumes:
- /etc/passwd:/etc/passwd:ro
- /etc/group:/etc/group:ro
Expand Down
2 changes: 0 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,3 @@ parameters:
- src/Responses/*Response.php
- src/Responses/Entities/*.php
- src/Exceptions/*Exception.php
checkGenericClassInNonGenericObjectType: false
checkMissingIterableValueType: false
15 changes: 10 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
use Psr\Http\Message\ResponseInterface;
use Avtocod\B2BApi\Responses\UserResponse;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Exception\TransferException;
use Avtocod\B2BApi\Responses\DevPingResponse;
use Avtocod\B2BApi\Responses\DevTokenResponse;
use GuzzleHttp\RequestOptions as GuzzleOptions;
Expand Down Expand Up @@ -313,8 +314,8 @@ public function userReportRefresh(string $report_uid, ?array $options = []): Use
}

/**
* @param RequestInterface $request
* @param array $options
* @param RequestInterface $request
* @param array<string, mixed> $options
*
* @throws BadRequestException
*
Expand All @@ -336,10 +337,14 @@ protected function doRequest(RequestInterface $request, array $options = []): Re
try {
$started_at = \microtime(true);
$response = $this->guzzle->send($request, $options);
} catch (RequestException $e) {
} catch (TransferException $e) {
$this->dispatchEvent(new Events\RequestFailedEvent(
$exception_request = $e->getRequest(),
$exception_response = $e->getResponse()
$exception_request = $e instanceof RequestException
? $e->getRequest()
: $request,
$exception_response = $e instanceof RequestException
? $e->getResponse()
: null
));

throw new BadRequestException($exception_request, $exception_response, null, null, $e);
Expand Down
23 changes: 12 additions & 11 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ interface ClientInterface
/**
* Test connection.
*
* @param string $value Any string value (server must returns it back)
* @param string|null $value Any string value (server must returns it back)
*
* @throws BadRequestException
* @throws BadResponseException
Expand Down Expand Up @@ -146,14 +146,15 @@ public function userReport(string $report_uid,
/**
* Make report.
*
* @param string $report_type_uid Unique report type ID (e.g.: `some_report_uid` or `some_report_uid@domain`)
* @param string $type Request type (e.g.: `VIN`, `GRZ`, `STS`, `PTS`, `CHASSIS`, `BODY`, etc.)
* @param string $value Request body (e.g.: `Z94CB41AAGR323020` (VIN-code), `А111АА177` (GRZ-code))
* @param array|null $options Additional request options
* @param bool|null $is_force Force update report, if it already was generated previously
* @param string|null $on_update Call (using `post` method) when report content updated
* @param string|null $on_complete Call (using `post` method) when report generation completed
* @param array|null $data Additional request data
* @param string $report_type_uid Unique report type ID (e.g.: `some_report_uid` or
* `some_report_uid@domain`)
* @param string $type Request type (e.g.: `VIN`, `GRZ`, `STS`, `PTS`, `CHASSIS`, etc.)
* @param string $value Request body (e.g.: `Z94CB41AAGR323020` (VIN), `А111АА177` (GRZ))
* @param array<mixed>|null $options Additional request options
* @param bool|null $is_force Force update report, if it already was generated previously
* @param string|null $on_update Call (using `post` method) when report content updated
* @param string|null $on_complete Call (using `post` method) when report generation completed
* @param array<mixed>|null $data Additional request data
*
* @throws BadRequestException
* @throws BadResponseException
Expand All @@ -172,8 +173,8 @@ public function userReportMake(string $report_type_uid,
/**
* Refresh existing report.
*
* @param string $report_uid Report unique ID (e.g.: `some_report_uid_YV1KS9614S107357Y@domain`)
* @param array|null $options Additional request options
* @param string $report_uid Report unique ID (e.g.: `some_report_uid_YV1KS9614S107357Y@domain`)
* @param array<mixed>|null $options Additional request options
*
* @throws BadRequestException
* @throws BadResponseException
Expand Down
8 changes: 4 additions & 4 deletions src/Events/BeforeRequestSendingEvent.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ final class BeforeRequestSendingEvent
private $request;

/**
* @var array
* @var array<string, mixed>
*/
private $options;

/**
* Create a new event instance.
*
* @param RequestInterface $request
* @param array $options
* @param RequestInterface $request
* @param array<string, mixed> $options
*/
public function __construct(RequestInterface $request, array $options)
{
Expand All @@ -39,7 +39,7 @@ public function getRequest(): RequestInterface
}

/**
* @return array
* @return array<string, mixed>
*/
public function getOptions(): array
{
Expand Down
4 changes: 3 additions & 1 deletion src/Responses/Entities/Balance.php
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ public function __construct(string $report_type_uid,
}

/**
* {@inheritdoc}
* @param array<string, mixed> $data
*
* @return self
*/
public static function fromArray(array $data): self
{
Expand Down
2 changes: 1 addition & 1 deletion src/Responses/Entities/CanCreateSelfFromArrayInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ interface CanCreateSelfFromArrayInterface
/**
* Create self using array of data.
*
* @param array $data
* @param array<mixed> $data
*
* @return self|$this
*/
Expand Down
4 changes: 3 additions & 1 deletion src/Responses/Entities/CleanOptions.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ public function __construct(?int $process_response, ?int $process_request, ?int
}

/**
* {@inheritdoc}
* @param array<string, int|null> $data
*
* @return self
*/
public static function fromArray(array $data): self
{
Expand Down
40 changes: 21 additions & 19 deletions src/Responses/Entities/Domain.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class Domain implements CanCreateSelfFromArrayInterface
protected $state;

/**
* @var string[]|null
* @var array<string>|null
*/
protected $roles;

/**
* @var string[]
* @var array<string>
*/
protected $tags;

Expand Down Expand Up @@ -82,20 +82,20 @@ class Domain implements CanCreateSelfFromArrayInterface
/**
* Create a new domain instance.
*
* @param string $uid Unique domain ID (e.g. `test`)
* @param string $comment Domain comment
* @param string $name Human-readable domain name
* @param string $state Domain state (e.g.: `DRAFT`, `ACTIVE`, `BANNED`)
* @param string[]|null $roles Domain roles (optional)
* @param string[] $tags Additional domain tags
* @param DateTime $created_at Domain created at
* @param string $created_by Domain creator
* @param DateTime $updated_at Last changes was made at
* @param string $updated_by Last changes was made by
* @param DateTime $active_from Active from
* @param DateTime $active_to Active to
* @param int|null $id Internal database identifier (optional, only for administrators)
* @param bool|null $deleted Is deleted flag (optional, only for administrators)
* @param string $uid Unique domain ID (e.g. `test`)
* @param string $comment Domain comment
* @param string $name Human-readable domain name
* @param string $state Domain state (e.g.: `DRAFT`, `ACTIVE`, `BANNED`)
* @param array<string>|null $roles Domain roles (optional)
* @param array<string> $tags Additional domain tags
* @param DateTime $created_at Domain created at
* @param string $created_by Domain creator
* @param DateTime $updated_at Last changes was made at
* @param string $updated_by Last changes was made by
* @param DateTime $active_from Active from
* @param DateTime $active_to Active to
* @param int|null $id Internal database identifier (optional, only for administrators)
* @param bool|null $deleted Is deleted flag (optional, only for administrators)
*/
public function __construct(string $uid,
string $comment,
Expand Down Expand Up @@ -129,7 +129,9 @@ public function __construct(string $uid,
}

/**
* {@inheritdoc}
* @param array<string, mixed> $data
*
* @return self
*/
public static function fromArray(array $data): self
{
Expand Down Expand Up @@ -196,7 +198,7 @@ public function getState(): string
/**
* Get domain roles.
*
* @return string[]|null
* @return array<string>|null
*/
public function getRoles(): ?array
{
Expand All @@ -206,7 +208,7 @@ public function getRoles(): ?array
/**
* Get additional domain tags.
*
* @return array
* @return array<string>
*/
public function getTags(): array
{
Expand Down
Loading