From f61b4bc11718a3220eb11b60d551f75a52629bef Mon Sep 17 00:00:00 2001 From: Valentin Clavreul Date: Fri, 13 Oct 2023 10:03:43 +0200 Subject: [PATCH] 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 @@