From 338fd64dae96497718ec55052af9faf1402115b1 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 20 Dec 2023 18:41:25 +0300 Subject: [PATCH 1/5] fix CS --- .gitignore | 2 ++ composer.json | 3 +- src/Command/UpdateDatabaseCommand.php | 10 +++--- src/DependencyInjection/Configuration.php | 40 +++++++++++------------ src/Reader/ReaderFactory.php | 2 +- 5 files changed, 30 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 40e6641..8605a57 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,5 @@ phpunit.xml composer.lock .php_cs.cache .phpunit.result.cache +.php-cs-fixer.cache + diff --git a/composer.json b/composer.json index 4e9d4a4..6d88a14 100644 --- a/composer.json +++ b/composer.json @@ -29,7 +29,8 @@ "require-dev": { "phpunit/phpunit": "~7.0|~8.0|~9.0", "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12" + "phpstan/phpstan-phpunit": "^0.12", + "friendsofphp/php-cs-fixer": "^3.41" }, "suggest": { "splitbrain/php-archive": "Greatly reduces memory usage for the geoip2:update command" diff --git a/src/Command/UpdateDatabaseCommand.php b/src/Command/UpdateDatabaseCommand.php index af41481..e3ad51f 100644 --- a/src/Command/UpdateDatabaseCommand.php +++ b/src/Command/UpdateDatabaseCommand.php @@ -57,7 +57,7 @@ protected function configure(): void $databases_help .= sprintf(' * %s'.PHP_EOL, $name); } - [$first, $second, ] = array_keys($this->databases); + [$first, $second] = array_keys($this->databases); $help .= <<databases[$database]) || - !array_key_exists('path', $this->databases[$database]) || - !is_string($this->databases[$database]['url']) || - !is_string($this->databases[$database]['path']) + if (!array_key_exists('url', $this->databases[$database]) + || !array_key_exists('path', $this->databases[$database]) + || !is_string($this->databases[$database]['url']) + || !is_string($this->databases[$database]['path']) ) { throw new \InvalidArgumentException(sprintf('Invalid "%s" database config.', $database)); } diff --git a/src/DependencyInjection/Configuration.php b/src/DependencyInjection/Configuration.php index 36e145d..80cd13e 100644 --- a/src/DependencyInjection/Configuration.php +++ b/src/DependencyInjection/Configuration.php @@ -192,10 +192,10 @@ private function normalizeDefaultDatabase(NodeDefinition $root_node): void ->beforeNormalization() ->ifTrue(static function ($v): bool { return - is_array($v) && - !array_key_exists('default_database', $v) && - !empty($v['databases']) && - is_array($v['databases']); + is_array($v) + && !array_key_exists('default_database', $v) + && !empty($v['databases']) + && is_array($v['databases']); }) ->then(static function (array $v): array { $keys = array_keys($v['databases']); @@ -268,10 +268,10 @@ private function validateAvailableDefaultDatabase(NodeDefinition $root_node): vo ->validate() ->ifTrue(static function ($v): bool { return - is_array($v) && - array_key_exists('default_database', $v) && - !empty($v['databases']) && - !array_key_exists($v['default_database'], $v['databases']); + is_array($v) + && array_key_exists('default_database', $v) + && !empty($v['databases']) + && !array_key_exists($v['default_database'], $v['databases']); }) ->then(static function (array $v): array { $databases = implode('", "', array_keys($v['databases'])); @@ -292,10 +292,10 @@ private function allowGlobalLicense(NodeDefinition $root_node): void ->beforeNormalization() ->ifTrue(static function ($v): bool { return - is_array($v) && - array_key_exists('license', $v) && - array_key_exists('databases', $v) && - is_array($v['databases']); + is_array($v) + && array_key_exists('license', $v) + && array_key_exists('databases', $v) + && is_array($v['databases']); }) ->then(static function (array $v): array { foreach ($v['databases'] as $name => $database) { @@ -320,10 +320,10 @@ private function allowGlobalLocales(NodeDefinition $root_node): void ->beforeNormalization() ->ifTrue(static function ($v): bool { return - is_array($v) && - array_key_exists('locales', $v) && - array_key_exists('databases', $v) && - is_array($v['databases']); + is_array($v) + && array_key_exists('locales', $v) + && array_key_exists('databases', $v) + && is_array($v['databases']); }) ->then(static function (array $v): array { foreach ($v['databases'] as $name => $database) { @@ -386,10 +386,10 @@ private function normalizeUrl(NodeDefinition $database_node): void ->beforeNormalization() ->ifTrue(static function ($v): bool { return - is_array($v) && - !array_key_exists('url', $v) && - array_key_exists('license', $v) && - array_key_exists('edition', $v); + is_array($v) + && !array_key_exists('url', $v) + && array_key_exists('license', $v) + && array_key_exists('edition', $v); }) ->then(static function (array $v): array { $v['url'] = sprintf(self::URL, urlencode($v['edition']), urlencode($v['license'])); diff --git a/src/Reader/ReaderFactory.php b/src/Reader/ReaderFactory.php index 107d29c..067bdbc 100644 --- a/src/Reader/ReaderFactory.php +++ b/src/Reader/ReaderFactory.php @@ -41,7 +41,7 @@ public function __construct(array $databases, string $reader_class = Reader::cla * * @return Reader */ - public function create(string $database, ?array $locales = null): Reader + public function create(string $database, array $locales = null): Reader { if (!array_key_exists($database, $this->databases)) { $databases = implode('", "', array_keys($this->databases)); From cf6c2f61f002c57281a24bb174c9d8ab7d870108 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 20 Dec 2023 18:51:52 +0300 Subject: [PATCH 2/5] change version of friendsofphp/php-cs-fixer ^3.41 => ^3.0.0 --- composer.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/composer.json b/composer.json index 6d88a14..0571020 100644 --- a/composer.json +++ b/composer.json @@ -30,7 +30,7 @@ "phpunit/phpunit": "~7.0|~8.0|~9.0", "phpstan/phpstan": "^0.12", "phpstan/phpstan-phpunit": "^0.12", - "friendsofphp/php-cs-fixer": "^3.41" + "friendsofphp/php-cs-fixer": "^3.0.0" }, "suggest": { "splitbrain/php-archive": "Greatly reduces memory usage for the geoip2:update command" From ee0085798ebab9647b3baedf61b7b0793662b004 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 20 Dec 2023 18:52:22 +0300 Subject: [PATCH 3/5] use local php-cs-fixer in workflows --- .github/workflows/qa.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index 0b4b81f..c6a531f 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -19,7 +19,7 @@ jobs: with: php-version: 7.4 coverage: none - tools: composer:v2, cs2pr, php-cs-fixer + tools: composer:v2, cs2pr - name: Install Composer dependencies (highest) uses: 'ramsey/composer-install@v1' @@ -27,4 +27,4 @@ jobs: dependency-versions: 'highest' - name: Run PHP-CS-Fixer - run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr + run: ./vender/bin/php-cs-fixer fix --dry-run --format checkstyle | cs2pr From c72de1415d53b8cd0a4d7d4744e12c4fb83aa180 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 20 Dec 2023 18:55:51 +0300 Subject: [PATCH 4/5] Revert "use local php-cs-fixer in workflows" This reverts commit ee0085798ebab9647b3baedf61b7b0793662b004. --- .github/workflows/qa.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/qa.yaml b/.github/workflows/qa.yaml index c6a531f..0b4b81f 100644 --- a/.github/workflows/qa.yaml +++ b/.github/workflows/qa.yaml @@ -19,7 +19,7 @@ jobs: with: php-version: 7.4 coverage: none - tools: composer:v2, cs2pr + tools: composer:v2, cs2pr, php-cs-fixer - name: Install Composer dependencies (highest) uses: 'ramsey/composer-install@v1' @@ -27,4 +27,4 @@ jobs: dependency-versions: 'highest' - name: Run PHP-CS-Fixer - run: ./vender/bin/php-cs-fixer fix --dry-run --format checkstyle | cs2pr + run: php-cs-fixer fix --dry-run --format checkstyle | cs2pr From 47082e261145232c68518a958243dcdcea55ca98 Mon Sep 17 00:00:00 2001 From: Peter Gribanov Date: Wed, 20 Dec 2023 18:56:25 +0300 Subject: [PATCH 5/5] not require friendsofphp/php-cs-fixer --- composer.json | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/composer.json b/composer.json index 0571020..4e9d4a4 100644 --- a/composer.json +++ b/composer.json @@ -29,8 +29,7 @@ "require-dev": { "phpunit/phpunit": "~7.0|~8.0|~9.0", "phpstan/phpstan": "^0.12", - "phpstan/phpstan-phpunit": "^0.12", - "friendsofphp/php-cs-fixer": "^3.0.0" + "phpstan/phpstan-phpunit": "^0.12" }, "suggest": { "splitbrain/php-archive": "Greatly reduces memory usage for the geoip2:update command"