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

Remove tarampampam/wrappers-php package #27

Merged
merged 1 commit into from
Apr 1, 2021
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@ 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

### Removed

- Dependency `tarampampam/wrappers-php` because this package was deprecated and removed

## v4.0.0

### Added
Expand Down
3 changes: 1 addition & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@
"ext-json": "*",
"ext-mbstring": "*",
"guzzlehttp/guzzle": "^6.0 || ~7.0",
"ocramius/package-versions": "^1.2",
"tarampampam/wrappers-php": "^1.5 || ~2.0"
"ocramius/package-versions": "^1.2"
},
"require-dev": {
"fzaninotto/faker": "^1.9.1",
Expand Down
8 changes: 2 additions & 6 deletions src/Exceptions/BadRequestException.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

use Throwable;
use RuntimeException;
use Tarampampam\Wrappers\Json;
use Psr\Http\Message\RequestInterface;
use Psr\Http\Message\ResponseInterface;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;

class BadRequestException extends RuntimeException implements B2BApiExceptionInterface
{
Expand Down Expand Up @@ -84,9 +82,9 @@ public function getHttpResponse(): ?ResponseInterface
*/
protected function extractErrorMessageFromResponse(ResponseInterface $response): ?string
{
try {
$as_array = (array) Json::decode((string) $response->getBody());
$as_array = \json_decode((string) $response->getBody(), true);

if (\json_last_error() === \JSON_ERROR_NONE && \is_array($as_array)) {
if (isset($as_array['type'], $as_array['name'], $as_array['message'])) {
return "{$as_array['type']}: {$as_array['name']} ({$as_array['message']})";
}
Expand All @@ -102,8 +100,6 @@ protected function extractErrorMessageFromResponse(ResponseInterface $response):

return "{$type}: {$name} ({$message})";
}
} catch (JsonEncodeDecodeException $e) {
//
}

return null;
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/DevPingResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@

namespace Avtocod\B2BApi\Responses;

use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

class DevPingResponse implements ResponseInterface
Expand Down Expand Up @@ -69,10 +67,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

return new self(
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/DevTokenResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
namespace Avtocod\B2BApi\Responses;

use DateTimeImmutable;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

class DevTokenResponse implements ResponseInterface
Expand Down Expand Up @@ -131,10 +129,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

return new self(
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserBalanceResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\Balance;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -78,10 +76,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $balance_data): Balance {
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserReportMakeResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\ReportMade;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -78,10 +76,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $data): ReportMade {
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserReportRefreshResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\ReportMade;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -78,10 +76,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $data): ReportMade {
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserReportResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\Report;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -78,10 +76,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $data): Report {
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserReportTypesResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\ReportType;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -90,10 +88,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $report_type_data): ReportType {
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserReportsResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\Report;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -90,10 +88,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $report_data): Report {
Expand Down
10 changes: 4 additions & 6 deletions src/Responses/UserResponse.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,9 @@
use ArrayIterator;
use DateTimeImmutable;
use IteratorAggregate;
use Tarampampam\Wrappers\Json;
use Avtocod\B2BApi\DateTimeFactory;
use Avtocod\B2BApi\Responses\Entities\User;
use Avtocod\B2BApi\Exceptions\BadResponseException;
use Tarampampam\Wrappers\Exceptions\JsonEncodeDecodeException;
use Psr\Http\Message\ResponseInterface as HttpResponseInterface;

/**
Expand Down Expand Up @@ -78,10 +76,10 @@ public function getRawResponseContent(): string
*/
public static function fromHttpResponse(HttpResponseInterface $response): self
{
try {
$as_array = (array) Json::decode($raw_response = (string) $response->getBody());
} catch (JsonEncodeDecodeException $e) {
throw BadResponseException::wrongJson($response, $e->getMessage(), $e);
$as_array = (array) \json_decode($raw_response = (string) $response->getBody(), true);

if (\json_last_error() !== \JSON_ERROR_NONE) {
throw BadResponseException::wrongJson($response, \json_last_error_msg());
}

$as_array['data'] = \array_map(static function (array $user_data): User {
Expand Down
5 changes: 2 additions & 3 deletions tests/Unit/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
use GuzzleHttp\Psr7\Request;
use GuzzleHttp\Psr7\Response;
use PackageVersions\Versions;
use Tarampampam\Wrappers\Json;
use GuzzleHttp\Client as Guzzle;
use Avtocod\B2BApi\ClientInterface;
use Avtocod\B2BApi\DateTimeFactory;
Expand Down Expand Up @@ -1428,7 +1427,7 @@ public function testUserReportMake(): void
DateTimeFactory::createFromIso8601Zulu('2019-07-07T19:23:58.897Z'), $made->getSuggestGet()
);

$request_body = Json::decode($this->guzzle_handler->getLastRequest()->getBody()->getContents());
$request_body = \json_decode($this->guzzle_handler->getLastRequest()->getBody()->getContents(), true);

$this->assertTrue($request_body['options']['FORCE']);
$this->assertSame($type, $request_body['queryType']);
Expand Down Expand Up @@ -1502,7 +1501,7 @@ public function testUserReportMakeWithIdempotenceKey(): void
$this->assertJsonStringEqualsJsonString($raw, $response->getRawResponseContent());

// Check that we received correct 'idempotenceKey' in request body
$request_body = Json::decode($this->guzzle_handler->getLastRequest()->getBody()->getContents());
$request_body = \json_decode($this->guzzle_handler->getLastRequest()->getBody()->getContents(), true);
$this->assertSame($idempotence_key, $request_body['idempotenceKey']);
}

Expand Down