Skip to content

Commit

Permalink
feat: applied latest cs rules
Browse files Browse the repository at this point in the history
  • Loading branch information
shavounet committed Oct 26, 2023
1 parent 5c79813 commit f61b4bc
Show file tree
Hide file tree
Showing 23 changed files with 73 additions and 27 deletions.
2 changes: 2 additions & 0 deletions src/Cache/CacheInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Cache;

/**
Expand Down
10 changes: 6 additions & 4 deletions src/Cache/InMemory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Cache;

/**
Expand All @@ -12,8 +14,8 @@ class InMemory implements CacheInterface

public function has($key)
{
if (array_key_exists($key, $this->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);
Expand All @@ -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)
Expand All @@ -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));
}

Expand Down
2 changes: 2 additions & 0 deletions src/DataCollector/GuzzleHttpDataCollector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\DataCollector;

use GuzzleHttp\ClientInterface as GuzzleHttpClient;
Expand Down
18 changes: 10 additions & 8 deletions src/DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\DependencyInjection;

use Symfony\Component\Config\Definition\Builder\TreeBuilder;
Expand Down Expand Up @@ -51,23 +53,23 @@ public function getConfigTreeBuilder(): TreeBuilder
->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()
->end()
->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()
->end()
->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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand All @@ -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()
Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/GuzzleHttpPass.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down
14 changes: 8 additions & 6 deletions src/DependencyInjection/M6WebGuzzleHttpExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\DependencyInjection;

use Symfony\Component\Config\FileLocator;
Expand Down Expand Up @@ -50,7 +52,7 @@ protected function loadClient(ContainerBuilder $container, string $clientId, arr
{
// clear empty arrays
foreach ($config as $key => $item) {
if (is_array($item) && count($item) == 0) {
if (\is_array($item) && \count($item) == 0) {
unset($config[$key]);
}
}
Expand Down Expand Up @@ -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);
}

Expand All @@ -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;
Expand Down Expand Up @@ -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']));
}
Expand Down Expand Up @@ -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;
}

Expand Down
2 changes: 2 additions & 0 deletions src/DependencyInjection/MiddlewarePass.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\DependencyInjection;

use Symfony\Component\DependencyInjection\Compiler\CompilerPassInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/EventDispatcher/AbstractGuzzleCacheEvent.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher;

use Psr\Http\Message\RequestInterface;
Expand Down
2 changes: 2 additions & 0 deletions src/EventDispatcher/AbstractGuzzleHttpEvent.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\EventDispatcher;

use GuzzleHttp\Psr7\Request;
Expand Down
16 changes: 9 additions & 7 deletions src/Handler/CacheTrait.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Handler;

use GuzzleHttp\Promise\FulfilledPromise;
Expand Down Expand Up @@ -75,7 +77,7 @@ protected static function getKey(RequestInterface $request)
array_keys($request->getHeaders()),
function ($header) use ($vary) {
return 0 !== stripos($header, 'x-')
|| array_key_exists($header, $vary)
|| \array_key_exists($header, $vary)
;
}
)
Expand All @@ -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]);
}
}

Expand Down Expand Up @@ -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;
}
}
Expand All @@ -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));
}

Expand Down Expand Up @@ -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);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion src/Handler/CurlFactory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Handler;

use GuzzleHttp\Handler\CurlFactory as GuzzleCurlFactory;
Expand All @@ -16,7 +18,7 @@ class CurlFactory extends GuzzleCurlFactory
{
public function release(EasyHandle $easy): void
{
if (!is_null($easy->response)) {
if (!\is_null($easy->response)) {
$easy->response->curlInfo = curl_getinfo($easy->handle);
}

Expand Down
2 changes: 2 additions & 0 deletions src/Handler/CurlHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Handler;

use GuzzleHttp\Handler\CurlHandler as GuzzleCurlHandler;
Expand Down
2 changes: 2 additions & 0 deletions src/Handler/CurlMultiHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Handler;

use GuzzleHttp\Handler\CurlMultiHandler as GuzzleCurlMultiHandler;
Expand Down
2 changes: 2 additions & 0 deletions src/M6WebGuzzleHttpBundle.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle;

use M6Web\Bundle\GuzzleHttpBundle\DependencyInjection\GuzzleHttpPass;
Expand Down
2 changes: 2 additions & 0 deletions src/Middleware/EventDispatcherMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Middleware;

use GuzzleHttp\HandlerStack;
Expand Down
2 changes: 2 additions & 0 deletions src/Middleware/HostForwarderMiddleware.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Middleware;

use GuzzleHttp\HandlerStack;
Expand Down
2 changes: 2 additions & 0 deletions src/Middleware/MiddlewareInterface.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\Middleware;

use GuzzleHttp\HandlerStack;
Expand Down
2 changes: 2 additions & 0 deletions tests/Units/Cache/InMemory.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\tests\Units\Cache;

class InMemory extends \atoum
Expand Down
4 changes: 3 additions & 1 deletion tests/Units/DependencyInjection/M6WebGuzzleHttpExtension.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\tests\Units\DependencyInjection;

use GuzzleHttp\Promise;
Expand Down Expand Up @@ -614,7 +616,7 @@ protected function getContainerForConfiguration($fixtureName, ContainerBuilder $
{
$extension = new TestedClass();

if (is_null($container)) {
if (\is_null($container)) {
$container = $this->getContainerBuilder();
}

Expand Down
2 changes: 2 additions & 0 deletions tests/Units/Handler/CurlMultiHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\tests\Units\Handler;

use GuzzleHttp\Psr7\Request;
Expand Down
2 changes: 2 additions & 0 deletions tests/Units/Handler/FakeCurlMultiHandler.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?php

declare(strict_types=1);

namespace M6Web\Bundle\GuzzleHttpBundle\tests\Units\Handler;

use GuzzleHttp\Psr7\Request;
Expand Down
Loading

0 comments on commit f61b4bc

Please sign in to comment.