From 616fa75add34d17c68a349591ec4b37f276151a2 Mon Sep 17 00:00:00 2001 From: Thomas Jarrand Date: Wed, 21 Feb 2024 11:55:47 +0100 Subject: [PATCH] feat: Add support for Symfony 7 --- Makefile | 1 + composer.json | 18 +++++++++--------- .../Config/FilterCollection.php | 4 ++-- .../LogBridgeBundle/Config/FilterParser.php | 16 ++++++++-------- .../CompilerPass/LoggerValidationPass.php | 2 +- .../Formatter/DefaultFormatter.php | 6 +++--- .../Bundle/LogBridgeBundle/Matcher/Builder.php | 4 ++-- .../Matcher/Dumper/PhpMatcherDumper.php | 10 +++++----- .../Matcher/Status/Type/CompleteType.php | 4 ++-- 9 files changed, 33 insertions(+), 32 deletions(-) diff --git a/Makefile b/Makefile index 04e2d84..ed112b1 100644 --- a/Makefile +++ b/Makefile @@ -53,6 +53,7 @@ ${SOURCE_DIR}/vendor/composer/installed.json: $(COMPOSER) --no-interaction install --ansi --no-progress --prefer-dist .PHONY: atoum +atoum: export XDEBUG_MODE=coverage atoum: $(call printSection,TEST atoum) ${BIN_DIR}/atoum diff --git a/composer.json b/composer.json index 7fced9b..47e6ec6 100644 --- a/composer.json +++ b/composer.json @@ -9,18 +9,18 @@ "prefer-stable": true, "require": { "php": ">=8.0", - "symfony/config": "^4.4|^5.0|^6.0", - "symfony/yaml": "^4.4|^5.0|^6.0", - "symfony/routing": "^4.4|^5.0|^6.0", - "symfony/expression-language": "^4.4|^5.0|^6.0", - "symfony/security-core": "^4.4|^5.0|^6.0", - "symfony/dependency-injection": "^4.4|^5.0|^6.0", - "symfony/http-kernel": "^4.4|^5.0|^6.0" + "symfony/config": "^4.4|^5.0|^6.0|^7.0", + "symfony/yaml": "^4.4|^5.0|^6.0|^7.0", + "symfony/routing": "^4.4|^5.0|^6.0|^7.0", + "symfony/expression-language": "^4.4|^5.0|^6.0|^7.0", + "symfony/security-core": "^4.4|^5.0|^6.0|^7.0", + "symfony/dependency-injection": "^4.4|^5.0|^6.0|^7.0", + "symfony/http-kernel": "^4.4|^5.0|^6.0|^7.0" }, "require-dev": { "atoum/atoum": "^3.4|^4.0", - "m6web/php-cs-fixer-config": "^2.1", - "symfony/http-foundation": "^4.4|^5.0|^6.0", + "m6web/php-cs-fixer-config": "^3.0", + "symfony/http-foundation": "^4.4|^5.0|^6.0|^7.0", "phpstan/phpstan": "^1.7", "rector/rector": "^0.13.2" }, diff --git a/src/M6Web/Bundle/LogBridgeBundle/Config/FilterCollection.php b/src/M6Web/Bundle/LogBridgeBundle/Config/FilterCollection.php index 228d5dc..a3af26e 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Config/FilterCollection.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Config/FilterCollection.php @@ -29,7 +29,7 @@ public function __construct(array $items = []) public function add(Filter $item): FilterCollection { - if (!in_array($item->getName(), $this->keys, true)) { + if (!\in_array($item->getName(), $this->keys, true)) { $this->keys[] = $item->getName(); } @@ -106,6 +106,6 @@ public function valid(): bool public function count(): int { - return count($this->values); + return \count($this->values); } } diff --git a/src/M6Web/Bundle/LogBridgeBundle/Config/FilterParser.php b/src/M6Web/Bundle/LogBridgeBundle/Config/FilterParser.php index 9250863..c04bd49 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Config/FilterParser.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Config/FilterParser.php @@ -67,18 +67,18 @@ protected function getAllRoutes(): array public function parse(string $name, array $config): Filter { if ( - (!array_key_exists('route', $config) && !array_key_exists('routes', $config)) - || !array_key_exists('method', $config) - || !array_key_exists('status', $config) + (!\array_key_exists('route', $config) && !\array_key_exists('routes', $config)) + || !\array_key_exists('method', $config) + || !\array_key_exists('status', $config) ) { throw new ParseException(sprintf('Undefined "route(s)", "method" or "status" parameter from filter "%s"', $name)); } - if ((array_key_exists('route', $config) && $config['route'] !== null) && (array_key_exists('routes', $config) && !empty($config['routes']))) { + if ((\array_key_exists('route', $config) && $config['route'] !== null) && (\array_key_exists('routes', $config) && !empty($config['routes']))) { throw new ParseException(sprintf('You can\'t use both "route" and "routes" parameter from filter "%s"', $name)); } - if (!array_key_exists('level', $config)) { + if (!\array_key_exists('level', $config)) { $config['level'] = self::DEFAULT_LEVEL; } @@ -86,11 +86,11 @@ public function parse(string $name, array $config): Filter ->setMethod($config['method']) ->setStatus($config['status']); - if (array_key_exists('route', $config)) { + if (\array_key_exists('route', $config)) { $this->parseRoute($filter, $config['route']); } - if (array_key_exists('routes', $config)) { + if (\array_key_exists('routes', $config)) { $this->parseRoutes($filter, $config['routes'] ?? []); } @@ -146,7 +146,7 @@ protected function parseRoutes(Filter $filter, ?array $routes): void protected function parseLevel(Filter $filter, ?string $level): void { - if (!in_array($level, $this->allowedLevels, true)) { + if (!\in_array($level, $this->allowedLevels, true)) { throw new ParseException(sprintf('Invalid value "%s" from level parameter, allowed %s', $level, implode(', ', $this->allowedLevels))); } diff --git a/src/M6Web/Bundle/LogBridgeBundle/DependencyInjection/CompilerPass/LoggerValidationPass.php b/src/M6Web/Bundle/LogBridgeBundle/DependencyInjection/CompilerPass/LoggerValidationPass.php index a016651..908a5e4 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/DependencyInjection/CompilerPass/LoggerValidationPass.php +++ b/src/M6Web/Bundle/LogBridgeBundle/DependencyInjection/CompilerPass/LoggerValidationPass.php @@ -30,7 +30,7 @@ public function process(ContainerBuilder $container): void $loggerClass = $container->getParameter($loggerClassParameter); } - if (!in_array(\Psr\Log\LoggerInterface::class, class_implements($loggerClass), true)) { + if (!\in_array(\Psr\Log\LoggerInterface::class, class_implements($loggerClass), true)) { throw new \InvalidArgumentException(sprintf('Class "%s" must be implement "Psr\Log\LoggerInterface"', $loggerClass)); } } diff --git a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php index 02ad66c..dc798e5 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Formatter/DefaultFormatter.php @@ -60,7 +60,7 @@ public function getLogContent(Request $request, Response $response, array $optio $requestContent = "Request\n------------------------\n"; foreach ($requestHeaders as $name => $headerValue) { - $value = is_array($headerValue) ? $headerValue[0] : $headerValue; + $value = \is_array($headerValue) ? $headerValue[0] : $headerValue; $requestContent .= str_pad((string) $name, 20, ' ', STR_PAD_RIGHT).': '.$value."\n"; } @@ -76,9 +76,9 @@ public function getLogContent(Request $request, Response $response, array $optio $responseContent .= $response->headers->__toString(); // Render post parameters - if (array_key_exists('post_parameters', $options) + if (\array_key_exists('post_parameters', $options) && $options['post_parameters'] == true - && in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'])) { + && \in_array($request->getMethod(), ['POST', 'PUT', 'PATCH'])) { $responseContent .= "Post parameters\n"; $responseContent .= $this->formatParameters($request->request->all()); } diff --git a/src/M6Web/Bundle/LogBridgeBundle/Matcher/Builder.php b/src/M6Web/Bundle/LogBridgeBundle/Matcher/Builder.php index 40160aa..8617d69 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Matcher/Builder.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Matcher/Builder.php @@ -74,9 +74,9 @@ public function getAbsoluteCachePath(): string return sprintf('%s/%s.php', $this->getCacheDir(), $this->getMatcherClassName()); } - public function isDebug(bool $debug = null): bool + public function isDebug(?bool $debug = null): bool { - if (is_bool($debug)) { + if (\is_bool($debug)) { $this->debug = $debug; } diff --git a/src/M6Web/Bundle/LogBridgeBundle/Matcher/Dumper/PhpMatcherDumper.php b/src/M6Web/Bundle/LogBridgeBundle/Matcher/Dumper/PhpMatcherDumper.php index 25d8d12..b0f34b0 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Matcher/Dumper/PhpMatcherDumper.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Matcher/Dumper/PhpMatcherDumper.php @@ -162,14 +162,14 @@ private function generateMatchList(Configuration $configuration): string $code .= sprintf(" '%s' => [\n", $filterKey); foreach ($filter as $key => $config) { - if (is_array($config)) { + if (\is_array($config)) { $code .= sprintf(" '%s' => [", $key); - if (count($config) > 0) { + if (\count($config) > 0) { $code .= "\n"; foreach ($config as $name => $value) { - if (is_bool($value)) { + if (\is_bool($value)) { $value = $value == true ? 'true' : 'false'; } else { $value = "'".$value."'"; @@ -261,7 +261,7 @@ private function compileFilter(Filter $filter): array /** @var array $routesPrefix */ $routesPrefix = $filter->getRoutes(); /** @var string $prefix */ - $prefix = is_null($filter->getRoute()) ? 'all' : $filter->getRoute(); + $prefix = \is_null($filter->getRoute()) ? 'all' : $filter->getRoute(); $compiledKeys = isset($routesPrefix) ? $this->compileFilterRoutes($filter, $routesPrefix, $compiledKeys) : @@ -320,7 +320,7 @@ private function compileFilterStatus(?string $prefix, Filter $filter): array /** @var string[]|null $filterStatusList */ $filterStatusList = $filter->getStatus(); - if (is_null($filterStatusList)) { + if (\is_null($filterStatusList)) { $compiled[] = sprintf('%s.all', $prefix); } else { foreach ($this->parseStatus($filterStatusList) as $status) { diff --git a/src/M6Web/Bundle/LogBridgeBundle/Matcher/Status/Type/CompleteType.php b/src/M6Web/Bundle/LogBridgeBundle/Matcher/Status/Type/CompleteType.php index ea412e0..230edba 100644 --- a/src/M6Web/Bundle/LogBridgeBundle/Matcher/Status/Type/CompleteType.php +++ b/src/M6Web/Bundle/LogBridgeBundle/Matcher/Status/Type/CompleteType.php @@ -19,10 +19,10 @@ protected function getPattern(): string */ protected function transform(string $config): array { - $refStatus = substr($config, 0, strlen((string) ((int) $config - 2))); + $refStatus = substr($config, 0, \strlen((string) ((int) $config - 2))); $rangeInterval = 100; - if (strlen($refStatus) === 2) { + if (\strlen($refStatus) === 2) { $rangeInterval = 10; }