From 3d0df270733d17537f8c2665b669a042d5603451 Mon Sep 17 00:00:00 2001 From: Andreas Schempp Date: Tue, 20 Aug 2024 16:42:12 +0200 Subject: [PATCH] Fix build tools --- composer-dependency-analyser.php | 9 +++++++++ composer.json | 19 +++++++++++++++++- config/services.yml | 2 -- src/Backend/CountryPreviewModule.php | 22 --------------------- src/CountryProvider.php | 8 ++++---- src/EventListener/DcaLoaderListener.php | 22 ++++++++++++++++++--- src/Migration/UppercaseCountryMigration.php | 3 +++ 7 files changed, 53 insertions(+), 32 deletions(-) create mode 100644 composer-dependency-analyser.php diff --git a/composer-dependency-analyser.php b/composer-dependency-analyser.php new file mode 100644 index 0000000..bfb47aa --- /dev/null +++ b/composer-dependency-analyser.php @@ -0,0 +1,9 @@ +ignoreErrorsOnPackage('friendsofsymfony/http-cache', [ErrorType::DEV_DEPENDENCY_IN_PROD]) +; diff --git a/composer.json b/composer.json index 5712a17..97b24f7 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,16 @@ "php": "^8.1", "contao/core-bundle": "^4.13 || ^5.0", "doctrine/dbal": "^2.11 || ^3.0", - "geoip2/geoip2": "~2.0" + "geoip2/geoip2": "~2.0", + "symfony-cmf/routing": "^2.3 || ^3.0", + "symfony/config": "^5.0 || ^6.0 || ^7.0", + "symfony/dependency-injection": "^5.0 || ^6.0 || ^7.0", + "symfony/event-dispatcher": "^5.0 || ^6.0 || ^7.0", + "symfony/http-foundation": "^5.0 || ^6.0 || ^7.0", + "symfony/http-kernel": "^5.0 || ^6.0 || ^7.0", + "symfony/routing": "^5.0 || ^6.0 || ^7.0", + "symfony/service-contracts": "^1.1 || ^2.0 || ^3.0", + "symfony/translation-contracts": "^2.3 || ^3.0" }, "require-dev": { "contao/manager-plugin": "^2.9", @@ -47,5 +56,13 @@ }, "extra": { "contao-manager-plugin": "Terminal42\\Geoip2CountryBundle\\ContaoManager\\Plugin" + }, + "config": { + "allow-plugins": { + "contao-components/installer": false, + "php-http/discovery": false, + "contao/manager-plugin": false, + "terminal42/contao-build-tools": true + } } } diff --git a/config/services.yml b/config/services.yml index 49c852e..995d15c 100644 --- a/config/services.yml +++ b/config/services.yml @@ -5,12 +5,10 @@ services: Terminal42\Geoip2CountryBundle\Backend\CountryPreviewModule: arguments: - - '@database_connection' - '@request_stack' - '@translator' - '@contao.intl.countries' - '@contao.csrf.token_manager' - - '%terminal42_geoip2_country.dca_tables%' public: true Terminal42\Geoip2CountryBundle\CountryProvider: diff --git a/src/Backend/CountryPreviewModule.php b/src/Backend/CountryPreviewModule.php index 3808eb6..3987560 100644 --- a/src/Backend/CountryPreviewModule.php +++ b/src/Backend/CountryPreviewModule.php @@ -12,7 +12,6 @@ use Contao\MaintenanceModuleInterface; use Contao\SelectMenu; use Contao\Widget; -use Doctrine\DBAL\Connection; use Symfony\Component\HttpFoundation\RequestStack; use Symfony\Contracts\Translation\TranslatorInterface; use Terminal42\Geoip2CountryBundle\CountryProvider; @@ -20,12 +19,10 @@ class CountryPreviewModule implements MaintenanceModuleInterface { public function __construct( - private readonly Connection $connection, private readonly RequestStack $requestStack, private readonly TranslatorInterface $translator, private readonly Countries $countries, private readonly ContaoCsrfTokenManager $csrfTokenManager, - private readonly array $supportedTables, ) { } @@ -61,25 +58,6 @@ public function run(): string return $template->parse(); } - private function getUsedCountries(): array - { - $queries = []; - - foreach ($this->supportedTables as $table) { - $queries[] = "SELECT geoip_countries FROM $table WHERE geoip_visibility='show' OR geoip_visibility='hide'"; - } - - $countries = $this->connection->executeQuery( - 'SELECT GROUP_CONCAT(geoip_countries) FROM ('.implode(' UNION ', $queries).') AS result', - )->fetchOne(); - - if (!$countries) { - return []; - } - - return array_values(array_filter(array_unique(explode(',', (string) $countries)))); - } - private function generateWidget(string|null $current): Widget { $widget = new SelectMenu(); diff --git a/src/CountryProvider.php b/src/CountryProvider.php index b98d7ef..baf51e0 100644 --- a/src/CountryProvider.php +++ b/src/CountryProvider.php @@ -21,13 +21,13 @@ class CountryProvider implements ResetInterface private string|null $databasePath; - private array $requestCountries = []; - /** - * @param Reader|string|null $databasePath + * @var array */ + private array $requestCountries = []; + public function __construct( - $databasePath = null, + Reader|string|null $databasePath = null, private readonly string $fallbackCountry = 'XX', ) { if ($databasePath instanceof Reader) { diff --git a/src/EventListener/DcaLoaderListener.php b/src/EventListener/DcaLoaderListener.php index 57ef453..e22d481 100644 --- a/src/EventListener/DcaLoaderListener.php +++ b/src/EventListener/DcaLoaderListener.php @@ -14,6 +14,9 @@ class DcaLoaderListener { + /** + * @param array $supportedTables + */ public function __construct( private readonly Connection $connection, private readonly TranslatorInterface $translator, @@ -186,7 +189,11 @@ private function addFlagsToTreeView(string $table): void }; } - private function callPrevious(mixed $previous, array $arguments): mixed + /** + * @param array{0: string, 1: string}|callable|null $previous + * @param array $arguments + */ + private function callPrevious(array|callable|null $previous, array $arguments): mixed { if (\is_array($previous)) { return System::importStatic($previous[0])->{$previous[1]}(...$arguments); @@ -199,6 +206,9 @@ private function callPrevious(mixed $previous, array $arguments): mixed return null; } + /** + * @param array $row + */ private function generateFlags(array $row): string { if (!$this->hasVisibility($row)) { @@ -208,14 +218,14 @@ private function generateFlags(array $row): string $countries = explode(',', (string) $row['geoip_countries']); $color = 'show' === $row['geoip_visibility'] ? '#b2f986' : '#ff89bf'; - $buffer = sprintf( + $buffer = \sprintf( '', $color, $this->getLabelForCountries($row['geoip_visibility'], $countries), ); foreach ($countries as $country) { - $buffer .= sprintf( + $buffer .= \sprintf( '', strtolower($country), ); @@ -224,11 +234,17 @@ private function generateFlags(array $row): string return $buffer.''; } + /** + * @param array $row + */ private function hasVisibility(array $row): bool { return isset($row['geoip_visibility']) && ('show' === $row['geoip_visibility'] || 'hide' === $row['geoip_visibility']); } + /** + * @param array $countries + */ private function getLabelForCountries(string $visibility, array $countries): string { return $this->translator->trans( diff --git a/src/Migration/UppercaseCountryMigration.php b/src/Migration/UppercaseCountryMigration.php index a44b334..190df08 100644 --- a/src/Migration/UppercaseCountryMigration.php +++ b/src/Migration/UppercaseCountryMigration.php @@ -10,6 +10,9 @@ class UppercaseCountryMigration extends AbstractMigration { + /** + * @param array $supportedTables + */ public function __construct( private readonly Connection $connection, private readonly array $supportedTables,