Skip to content

Commit

Permalink
Upgrade Guzzle
Browse files Browse the repository at this point in the history
  • Loading branch information
Sébastien Nikolaou committed May 25, 2023
1 parent c703709 commit 0d8d266
Show file tree
Hide file tree
Showing 13 changed files with 80 additions and 139 deletions.
8 changes: 1 addition & 7 deletions .github/workflows/tests-php7.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ jobs:
strategy:
fail-fast: true
matrix:
php: [7.4, 7.3, 7.2, 7.1]
php: [7.4, 7.3, 7.2]
laravel: [^8.0, ^7.0, ^6.0, 5.8.*, 5.7.*, 5.6.*, 5.5.*]
include:
- laravel: ^8.0
Expand All @@ -38,12 +38,6 @@ jobs:
exclude:
- laravel: ^8.0
php: 7.2
- laravel: ^8.0
php: 7.1
- laravel: ^7.0
php: 7.1
- laravel: ^6.0
php: 7.1
- laravel: 5.7.*
php: 7.4
- laravel: 5.6.*
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

All notable changes to `artisan-cloudflare` will be documented in this file.

## 2.5.0 - 2023-05-25

- Remove support for Guzzle 6.x
- Remove support for PHP 7.1

## 2.4.7 - 2023-02-01

- Add support for Laravel 10 [#22](https://github.com/sebdesign/artisan-cloudflare/pull/22)
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@
}
],
"require": {
"php": "^7.1|^8.0",
"guzzlehttp/guzzle": "^6.0|^7.0",
"php": "^7.2.5|^8.0",
"guzzlehttp/guzzle": "^7.0",
"illuminate/console": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0",
"illuminate/support": "^5.5|^6.0|^7.0|^8.0|^9.0|^10.0"
},
Expand Down
38 changes: 11 additions & 27 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
use GuzzleHttp\Client as GuzzleClient;
use GuzzleHttp\Exception\ClientException;
use GuzzleHttp\Exception\RequestException;
use GuzzleHttp\Promise;
use GuzzleHttp\Promise\Each;
use GuzzleHttp\Promise\PromiseInterface;
use Illuminate\Support\Collection;
use Psr\Http\Message\ResponseInterface;
use Psr\Log\LoggerInterface;
Expand All @@ -29,9 +30,6 @@ class Client

/**
* Constructor.
*
* @param \GuzzleHttp\Client $client
* @param \Psr\Log\LoggerInterface $logger
*/
public function __construct(GuzzleClient $client, LoggerInterface $logger)
{
Expand All @@ -50,7 +48,7 @@ public function __construct(GuzzleClient $client, LoggerInterface $logger)
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $zones
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
public function purge($zones)
public function purge(Collection $zones): Collection
{
return $zones->map(function (Zone $zone, $identifier) {
return $this->delete($identifier, $zone);
Expand All @@ -59,12 +57,7 @@ public function purge($zones)
})->wait();
}

/**
* @param string $identifier
* @param \Sebdesign\ArtisanCloudflare\Zone $zone
* @return \GuzzleHttp\Promise\PromiseInterface
*/
protected function delete($identifier, Zone $zone)
protected function delete(string $identifier, Zone $zone): PromiseInterface
{
return $this->client->deleteAsync("zones/{$identifier}/purge_cache", [
\GuzzleHttp\RequestOptions::JSON => $zone,
Expand All @@ -78,13 +71,12 @@ protected function delete($identifier, Zone $zone)
* The returned promise is fulfilled with a collection of results.
*
* @param \Illuminate\Support\Collection<string,\GuzzleHttp\Promise\PromiseInterface> $promises
* @return \GuzzleHttp\Promise\PromiseInterface
*/
protected function settle(Collection $promises)
protected function settle(Collection $promises): PromiseInterface
{
$results = new Collection();

return Promise\each(
return Each::of(
$promises->getIterator(),
$this->onFulfilled($results),
$this->onRejected($results)
Expand All @@ -99,7 +91,7 @@ protected function settle(Collection $promises)
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $results
* @return \Closure
*/
protected function onFulfilled($results)
protected function onFulfilled(Collection $results)
{
/*
* @param \Psr\Http\Message\ResponseInterface $response
Expand All @@ -117,7 +109,7 @@ protected function onFulfilled($results)
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $results
* @return \Closure
*/
protected function onRejected($results)
protected function onRejected(Collection $results)
{
/*
* @param \GuzzleHttp\Exception\RequestException $reason
Expand All @@ -136,11 +128,8 @@ protected function onRejected($results)

/**
* Transform a request exception into a result object.
*
* @param \GuzzleHttp\Exception\RequestException $e
* @return \Sebdesign\ArtisanCloudflare\Zone
*/
protected function handleException(RequestException $e)
protected function handleException(RequestException $e): Zone
{
if ($e->hasResponse()) {
/** @var \Psr\Http\Message\ResponseInterface $response */
Expand Down Expand Up @@ -168,21 +157,16 @@ protected function handleException(RequestException $e)

/**
* Transform the response body into a result object.
*
* @param \Psr\Http\Message\ResponseInterface $response
* @return \Sebdesign\ArtisanCloudflare\Zone
*/
protected function getBody(ResponseInterface $response)
protected function getBody(ResponseInterface $response): Zone
{
return new Zone(json_decode($response->getBody(), true));
}

/**
* Get the Guzzle client.
*
* @return \GuzzleHttp\ClientInterface
*/
public function getClient()
public function getClient(): GuzzleClient
{
return $this->client;
}
Expand Down
20 changes: 7 additions & 13 deletions src/Commands/Cache/Purge.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,6 @@ class Purge extends Command

/**
* Purge constructor.
*
* @param array $zones
*/
public function __construct(array $zones)
{
Expand Down Expand Up @@ -98,7 +96,7 @@ public function handle(Client $client)
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $zones
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
private function applyParameters($zones)
private function applyParameters(Collection $zones): Collection
{
$defaults = array_filter([
'files' => $this->option('file'),
Expand All @@ -121,7 +119,7 @@ private function applyParameters($zones)
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $zones
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
private function purge($zones)
private function purge(Collection $zones): Collection
{
$results = $this->client->purge($zones);

Expand All @@ -135,7 +133,7 @@ private function purge($zones)
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $results
* @return void
*/
private function displayResults($zones, $results)
private function displayResults(Collection $zones, Collection $results): void
{
$headers = ['Status', 'Zone', 'Files', 'Tags', 'Hosts', 'Errors'];

Expand Down Expand Up @@ -192,11 +190,8 @@ private function displayResults($zones, $results)

/**
* Format an array into a multiline string.
*
* @param array $items
* @return string
*/
private function formatItems(array $items)
private function formatItems(array $items): string
{
return implode("\n", $items);
}
Expand All @@ -207,7 +202,7 @@ private function formatItems(array $items)
* @param array[] $errors
* @return string[]
*/
private function formatErrors(array $errors)
private function formatErrors(array $errors): array
{
return array_map(function (array $error) {
if (isset($error['code'])) {
Expand All @@ -223,7 +218,7 @@ private function formatErrors(array $errors)
*
* @return \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone>
*/
private function getZones()
private function getZones(): Collection
{
if (! $zone = $this->argument('zone')) {
return $this->zones;
Expand All @@ -244,9 +239,8 @@ private function getZones()
* Return 1 if all successes are false, otherwise return 0.
*
* @param \Illuminate\Support\Collection<string,\Sebdesign\ArtisanCloudflare\Zone> $results
* @return int
*/
private function getExitCode($results)
private function getExitCode(Collection $results): int
{
return (int) $results->filter(function (Zone $zone) {
return $zone->get('success');
Expand Down
12 changes: 6 additions & 6 deletions src/ServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ServiceProvider extends IlluminateServiceProvider
/**
* Bootstrap the application services.
*/
public function boot()
public function boot(): void
{
if ($this->app->runningInConsole()) {
$this->publishes([
Expand All @@ -20,7 +20,7 @@ public function boot()
}
}

public function register()
public function register(): void
{
$this->mergeConfigFrom(__DIR__.'/../config/cloudflare.php', 'cloudflare');

Expand All @@ -29,7 +29,7 @@ public function register()
$this->registerMacros();
}

protected function registerClient()
protected function registerClient(): void
{
$this->app->bind(Client::class, function () {
return new Client(
Expand All @@ -39,7 +39,7 @@ protected function registerClient()
});
}

protected function bootGuzzleClient()
protected function bootGuzzleClient(): GuzzleClient
{
$config = $this->app['config']['cloudflare'];

Expand All @@ -56,7 +56,7 @@ protected function bootGuzzleClient()
]);
}

protected function registerCommands()
protected function registerCommands(): void
{
$this->app->bind(Commands\Cache\Purge::class, function () {
return new Commands\Cache\Purge(
Expand All @@ -69,7 +69,7 @@ protected function registerCommands()
]);
}

protected function registerMacros()
protected function registerMacros(): void
{
/*
* Transpose with keys.
Expand Down
4 changes: 2 additions & 2 deletions src/Zone.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ public function __construct(array $parameters = [])
$this->parameters = $parameters;
}

public function replace(array $parameters)
public function replace(array $parameters): void
{
$this->parameters = $parameters;
}

#[\ReturnTypeWillChange]
public function jsonSerialize()
public function jsonSerialize(): array
{
if (empty($this->parameters)) {
return ['purge_everything' => true];
Expand Down
8 changes: 3 additions & 5 deletions tests/ClientTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ class ClientTest extends TestCase

/**
* Setup the test environment.
*
* @return void
*/
public function setUp(): void
{
Expand All @@ -25,7 +23,7 @@ public function setUp(): void
/**
* @test
*/
public function it_purges_a_zone_with_success()
public function it_purges_a_zone_with_success(): void
{
// Arrange

Expand All @@ -50,7 +48,7 @@ public function it_purges_a_zone_with_success()
/**
* @test
*/
public function it_handles_client_errors()
public function it_handles_client_errors(): void
{
// Arrange

Expand Down Expand Up @@ -78,7 +76,7 @@ public function it_handles_client_errors()
/**
* @test
*/
public function it_handles_server_errors()
public function it_handles_server_errors(): void
{
// Arrange

Expand Down
6 changes: 3 additions & 3 deletions tests/CollectionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public function setUp(): void
/**
* @test
*/
public function it_transposes_a_collection()
public function it_transposes_a_collection(): void
{
// Arrange

Expand Down Expand Up @@ -68,7 +68,7 @@ public function it_transposes_a_collection()
/**
* @test
*/
public function it_inserts_a_value_between_items()
public function it_inserts_a_value_between_items(): void
{
// Arrange

Expand Down Expand Up @@ -98,7 +98,7 @@ public function it_inserts_a_value_between_items()
/**
* @test
*/
public function it_reorders_a_collection()
public function it_reorders_a_collection(): void
{
// Arrange

Expand Down
Loading

0 comments on commit 0d8d266

Please sign in to comment.