From 5c798138d1dec53f2dde7c9963f741a653e26b7e Mon Sep 17 00:00:00 2001 From: Valentin Clavreul Date: Fri, 13 Oct 2023 09:56:57 +0200 Subject: [PATCH 1/2] feat: update all dependencies to latest supported versions --- .github/workflows/ci.yml | 6 ++--- README.md | 2 +- composer.json | 24 +++++++++---------- .../M6WebGuzzleHttpExtension.php | 4 ++-- 4 files changed, 18 insertions(+), 18 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 3dae661..20217d4 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -13,12 +13,12 @@ jobs: - run: composer install --prefer-dist --no-interaction - run: bin/php-cs-fixer fix --ansi --dry-run --using-cache=no --verbose - tests: - name: Tests + atoum-tests: + name: Atoum tests runs-on: ubuntu-20.04 strategy: matrix: - version: [ '7.4', '8.0', '8.1' ] + version: [ 8.1, 8.2 ] flags: [ '', '--prefer-lowest' ] fail-fast: false steps: diff --git a/README.md b/README.md index 3c64bfd..6167e33 100644 --- a/README.md +++ b/README.md @@ -55,7 +55,7 @@ try { 'second' => $client->getAsync('http://domain.tld/path/to/other/resource') ]; - $result = \GuzzleHttp\Promise\unwrap($promises); + $result = \GuzzleHttp\Promise\Utils::unwrap($promises); } catch(\GuzzleHttp\Exception\ConnectException $e) { // connection problem like timeout } diff --git a/composer.json b/composer.json index 8f5240b..6e13dbe 100644 --- a/composer.json +++ b/composer.json @@ -1,7 +1,7 @@ { "name": "m6web/guzzle-http-bundle", "type" : "symfony-bundle", - "description": "Symfony2 bundle on top of guzzle 6", + "description": "Symfony bundle on top of Guzzle", "keywords": ["bundle", "http", "client", "HTTP client"], "license" : "MIT", "authors": [ @@ -12,21 +12,21 @@ } ], "require": { - "php": ">=7.4", + "php": ">=8.1", "ext-curl": "*", - "guzzlehttp/guzzle": "^6.3||^7.0", - "symfony/config" : "^4.4||^5.0||^6.0", - "symfony/dependency-injection": "^4.4||^5.0||^6.0", - "symfony/event-dispatcher": "^4.4||^5.0||^6.0", - "symfony/http-kernel": "^4.4||^5.0||^6.0", - "symfony/yaml" : "^4.4||^5.0||^6.0" + "guzzlehttp/guzzle": "^7", + "symfony/config" : "^5.4||^6.0", + "symfony/dependency-injection": "^5.4||^6.0", + "symfony/event-dispatcher": "^5.4||^6.0", + "symfony/http-kernel": "^5.4||^6.0", + "symfony/yaml" : "^5.4||^6.0" }, "require-dev": { - "atoum/atoum": "4.0.3", + "atoum/atoum": "4.2.0", "atoum/stubs": "*", - "m6web/php-cs-fixer-config": "2.0.0", - "friendsofphp/php-cs-fixer": "3.34.1", - "guzzlehttp/promises": "^1" + "m6web/php-cs-fixer-config": "3.2.0", + "friendsofphp/php-cs-fixer": "3.35.1", + "guzzlehttp/promises": "^2" }, "autoload": { "psr-4": {"M6Web\\Bundle\\GuzzleHttpBundle\\": "src/"} diff --git a/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php b/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php index 97761f6..42211c4 100644 --- a/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php +++ b/tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php @@ -382,7 +382,7 @@ public function testEventDispatcherMiddleWare() 'test' => $client->getAsync('http://httpbin.org'), 'test2' => $client->getAsync('http://httpbin.org/ip'), ]) - ->and($rep = Promise\unwrap($promises)) + ->and($rep = Promise\Utils::unwrap($promises)) ->then ->mock($container->get('event_dispatcher')) ->call('dispatch') @@ -402,7 +402,7 @@ public function testEventDispatcherMultiClient() 'test' => $client->getAsync('http://httpbin.org'), 'test2' => $client->getAsync('http://httpbin.org/ip'), ]) - ->and($rep = Promise\unwrap($promises)) + ->and($rep = Promise\Utils::unwrap($promises)) ->and($client2->get('http://httpbin.org')) ->then ->mock($container->get('event_dispatcher')) From f61b4bc11718a3220eb11b60d551f75a52629bef Mon Sep 17 00:00:00 2001 From: Valentin Clavreul Date: Fri, 13 Oct 2023 10:03:43 +0200 Subject: [PATCH 2/2] feat: applied latest cs rules --- src/Cache/CacheInterface.php | 2 ++ src/Cache/InMemory.php | 10 ++++++---- src/DataCollector/GuzzleHttpDataCollector.php | 2 ++ src/DependencyInjection/Configuration.php | 18 ++++++++++-------- src/DependencyInjection/GuzzleHttpPass.php | 2 ++ .../M6WebGuzzleHttpExtension.php | 14 ++++++++------ src/DependencyInjection/MiddlewarePass.php | 2 ++ .../AbstractGuzzleCacheEvent.php | 2 ++ .../AbstractGuzzleHttpEvent.php | 2 ++ src/Handler/CacheTrait.php | 16 +++++++++------- src/Handler/CurlFactory.php | 4 +++- src/Handler/CurlHandler.php | 2 ++ src/Handler/CurlMultiHandler.php | 2 ++ src/M6WebGuzzleHttpBundle.php | 2 ++ src/Middleware/EventDispatcherMiddleware.php | 2 ++ src/Middleware/HostForwarderMiddleware.php | 2 ++ src/Middleware/MiddlewareInterface.php | 2 ++ tests/Units/Cache/InMemory.php | 2 ++ .../M6WebGuzzleHttpExtension.php | 4 +++- tests/Units/Handler/CurlMultiHandler.php | 2 ++ tests/Units/Handler/FakeCurlMultiHandler.php | 2 ++ .../Middleware/EventDispatcherMiddleware.php | 2 ++ .../Middleware/HostForwarderMiddleware.php | 2 ++ 23 files changed, 73 insertions(+), 27 deletions(-) diff --git a/src/Cache/CacheInterface.php b/src/Cache/CacheInterface.php index 4de9901..7c61904 100644 --- a/src/Cache/CacheInterface.php +++ b/src/Cache/CacheInterface.php @@ -1,5 +1,7 @@ cache)) { - if (is_null($this->ttl[$key]) || $this->ttl[$key] > microtime(true)) { + if (\array_key_exists($key, $this->cache)) { + if (\is_null($this->ttl[$key]) || $this->ttl[$key] > microtime(true)) { return true; } $this->remove($key); @@ -34,7 +36,7 @@ public function get($key) public function set($key, $value, $ttl = null) { $this->cache[$key] = $value; - $this->ttl[$key] = is_null($ttl) ? null : microtime(true) + $ttl; + $this->ttl[$key] = \is_null($ttl) ? null : microtime(true) + $ttl; } public function remove($key) @@ -48,7 +50,7 @@ public function remove($key) public function ttl($key) { if ($this->has($key)) { - if (!is_null($this->ttl[$key])) { + if (!\is_null($this->ttl[$key])) { return (int) round($this->ttl[$key] - microtime(true)); } diff --git a/src/DataCollector/GuzzleHttpDataCollector.php b/src/DataCollector/GuzzleHttpDataCollector.php index 13afa89..0fc1d2c 100644 --- a/src/DataCollector/GuzzleHttpDataCollector.php +++ b/src/DataCollector/GuzzleHttpDataCollector.php @@ -1,5 +1,7 @@ variableNode('cert') ->validate() ->ifTrue(function ($v) { - return !is_string($v) && (!is_array($v) || count($v) != 2); + return !\is_string($v) && (!\is_array($v) || \count($v) != 2); }) ->theninvalid('Requires a string or a two entries array') ->end() @@ -59,7 +61,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('debug') ->validate() ->ifTrue(function ($v) { - return !is_string($v) && !is_bool($v); + return !\is_string($v) && !\is_bool($v); }) ->theninvalid('Requires an invokable service id or a bolean value') ->end() @@ -67,7 +69,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('decode_content') ->validate() ->ifTrue(function ($v) { - return !is_string($v) && !is_bool($v); + return !\is_string($v) && !\is_bool($v); }) ->theninvalid('Requires a string or a boolean') ->end() @@ -76,7 +78,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('expect') ->validate() ->ifTrue(function ($v) { - return !is_int($v) && !is_bool($v); + return !\is_int($v) && !\is_bool($v); }) ->theninvalid('Requires an integer or a boolean') ->end() @@ -90,7 +92,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('cookies') ->validate() ->ifTrue(function ($v) { - return !is_array($v) && !is_bool($v); + return !\is_array($v) && !\is_bool($v); }) ->theninvalid('Requires an array or a boolean') ->end() @@ -113,7 +115,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('proxy') ->validate() ->ifTrue(function ($v) { - return !is_array($v) && !is_string($v); + return !\is_array($v) && !\is_string($v); }) ->theninvalid('Requires an array or a string') ->end() @@ -126,7 +128,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('ssl_key') ->validate() ->ifTrue(function ($v) { - return !is_string($v) && (!is_array($v) || count($v) != 2); + return !\is_string($v) && (!\is_array($v) || \count($v) != 2); }) ->theninvalid('Requires a string or a two entries array') ->end() @@ -136,7 +138,7 @@ public function getConfigTreeBuilder(): TreeBuilder ->variableNode('verify') ->validate() ->ifTrue(function ($v) { - return !is_string($v) && !is_bool($v); + return !\is_string($v) && !\is_bool($v); }) ->theninvalid('Requires a string or a boolean') ->end() diff --git a/src/DependencyInjection/GuzzleHttpPass.php b/src/DependencyInjection/GuzzleHttpPass.php index 427f07e..fae8f8d 100644 --- a/src/DependencyInjection/GuzzleHttpPass.php +++ b/src/DependencyInjection/GuzzleHttpPass.php @@ -1,5 +1,7 @@ $item) { - if (is_array($item) && count($item) == 0) { + if (\is_array($item) && \count($item) == 0) { unset($config[$key]); } } @@ -110,7 +112,7 @@ protected function loadClient(ContainerBuilder $container, string $clientId, arr } } // Create cookies jar if required - if (!empty($config['cookies']) && is_array($config['cookies'])) { + if (!empty($config['cookies']) && \is_array($config['cookies'])) { $config['cookies'] = $this->getCookiesJarServiceReference($container, $config['cookies'], $clientId); } @@ -126,7 +128,7 @@ protected function loadClient(ContainerBuilder $container, string $clientId, arr // Services entries foreach (['on_headers', 'on_stats'] as $key) { if (!empty($config[$key])) { - if (is_null($serviceReference = $this->getServiceReference($config[$key]))) { + if (\is_null($serviceReference = $this->getServiceReference($config[$key]))) { throw new \InvalidArgumentException(sprintf('"%s" configuration entry requires a valid service reference, "%s" given', $key, $config[$key])); } $config[$key] = $serviceReference; @@ -171,7 +173,7 @@ protected function setGuzzleProxyHandler(ContainerBuilder $container, ?string $c if (isset($config['guzzlehttp_cache'])) { if ( !isset($config['guzzlehttp_cache']['service']) - || is_null($cacheService = $this->getServiceReference($config['guzzlehttp_cache']['service'])) + || \is_null($cacheService = $this->getServiceReference($config['guzzlehttp_cache']['service'])) ) { throw new \InvalidArgumentException(sprintf('"guzzlehttp_cache.service" requires a valid service reference, "%s" given', $config['guzzlehttp_cache']['service'])); } @@ -218,11 +220,11 @@ protected function getCurlConfig(array $config) $protocols = array_map('strtolower', $config['allow_redirects']['protocols']); - if (in_array('http', $protocols)) { + if (\in_array('http', $protocols)) { $redirProtocols |= CURLPROTO_HTTP; } - if (in_array('https', $protocols)) { + if (\in_array('https', $protocols)) { $redirProtocols |= CURLPROTO_HTTPS; } diff --git a/src/DependencyInjection/MiddlewarePass.php b/src/DependencyInjection/MiddlewarePass.php index 7fb372d..37041f7 100644 --- a/src/DependencyInjection/MiddlewarePass.php +++ b/src/DependencyInjection/MiddlewarePass.php @@ -1,5 +1,7 @@ getHeaders()), function ($header) use ($vary) { return 0 !== stripos($header, 'x-') - || array_key_exists($header, $vary) + || \array_key_exists($header, $vary) ; } ) @@ -95,7 +97,7 @@ protected function getCacheTtl(Response $response) $cacheControl = $response->getHeader('Cache-Control')[0]; if (preg_match('`max-age=(\d+)`', $cacheControl, $match)) { - return intval($match[1]); + return \intval($match[1]); } } @@ -159,13 +161,13 @@ protected function getCached(RequestInterface $request) } $cacheKey = self::getKey($request); - if (is_null($cachedContent = $this->cache->get($cacheKey))) { + if (\is_null($cachedContent = $this->cache->get($cacheKey))) { return null; } $cached = unserialize($cachedContent); foreach ($cached as $value) { - if (is_null($value)) { + if (\is_null($value)) { return null; } } @@ -191,13 +193,13 @@ protected function getCached(RequestInterface $request) */ public function __invoke(RequestInterface $request, array $options): PromiseInterface { - if (is_null($this->cache)) { + if (\is_null($this->cache)) { return parent::__invoke($request, $options); } // user want to force cache reload // so we remove existing cache - if (array_key_exists('cache_force', $options)) { + if (\array_key_exists('cache_force', $options)) { $this->cache->remove(self::getKey($request)); } @@ -236,7 +238,7 @@ public function __invoke(RequestInterface $request, array $options): PromiseInte */ protected function isSupportedMethod(RequestInterface $request) { - return in_array(strtoupper($request->getMethod()), self::$methods); + return \in_array(strtoupper($request->getMethod()), self::$methods); } /** diff --git a/src/Handler/CurlFactory.php b/src/Handler/CurlFactory.php index 84edcce..bf545b8 100644 --- a/src/Handler/CurlFactory.php +++ b/src/Handler/CurlFactory.php @@ -1,5 +1,7 @@ response)) { + if (!\is_null($easy->response)) { $easy->response->curlInfo = curl_getinfo($easy->handle); } diff --git a/src/Handler/CurlHandler.php b/src/Handler/CurlHandler.php index 453d8f6..3392656 100644 --- a/src/Handler/CurlHandler.php +++ b/src/Handler/CurlHandler.php @@ -1,5 +1,7 @@ getContainerBuilder(); } diff --git a/tests/Units/Handler/CurlMultiHandler.php b/tests/Units/Handler/CurlMultiHandler.php index f6ead8b..680d08e 100644 --- a/tests/Units/Handler/CurlMultiHandler.php +++ b/tests/Units/Handler/CurlMultiHandler.php @@ -1,5 +1,7 @@