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));