diff --git a/.github/workflows/rector-cs.yml b/.github/workflows/rector-cs.yml new file mode 100644 index 0000000..6424c2a --- /dev/null +++ b/.github/workflows/rector-cs.yml @@ -0,0 +1,27 @@ +name: Rector + PHP CS Fixer + +on: + pull_request_target: + paths: + - 'src/**' + - 'tests/**' + - '.github/workflows/rector-cs.yml' + - 'composer.json' + - 'rector.php' + - '.php-cs-fixer.dist.php' + +permissions: + contents: read + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + rector: + uses: yiisoft/actions/.github/workflows/rector-cs.yml@master + secrets: + token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} + with: + repository: ${{ github.event.pull_request.head.repo.full_name }} + php: '8.1' diff --git a/.github/workflows/rector.yml b/.github/workflows/rector.yml deleted file mode 100644 index 36d3355..0000000 --- a/.github/workflows/rector.yml +++ /dev/null @@ -1,28 +0,0 @@ -on: - pull_request_target: - paths-ignore: - - 'docs/**' - - 'README.md' - - 'CHANGELOG.md' - - '.gitignore' - - '.gitattributes' - - 'infection.json.dist' - - 'psalm.xml' - -name: rector - -concurrency: - group: ${{ github.workflow }}-${{ github.ref }} - cancel-in-progress: true - -jobs: - rector: - uses: yiisoft/actions/.github/workflows/rector.yml@master - secrets: - token: ${{ secrets.YIISOFT_GITHUB_TOKEN }} - with: - repository: ${{ github.event.pull_request.head.repo.full_name }} - os: >- - ['ubuntu-latest'] - php: >- - ['8.1'] diff --git a/.gitignore b/.gitignore index c913400..d3b3a3d 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,7 @@ composer.phar /phpunit.phar /phpunit.xml /.phpunit.cache + +# PHP CS Fixer +/.php-cs-fixer.cache +/.php-cs-fixer.php diff --git a/.php-cs-fixer.dist.php b/.php-cs-fixer.dist.php new file mode 100644 index 0000000..2477e66 --- /dev/null +++ b/.php-cs-fixer.dist.php @@ -0,0 +1,21 @@ +in([ + __DIR__ . '/src', + __DIR__ . '/tests', +]); + +return ConfigBuilder::build() + ->setRiskyAllowed(true) + ->setParallelConfig(ParallelConfigFactory::detect()) + ->setRules([ + '@Yiisoft/Core' => true, + '@Yiisoft/Core:risky' => true, + ]) + ->setFinder($finder); diff --git a/.styleci.yml b/.styleci.yml deleted file mode 100644 index 1ab379b..0000000 --- a/.styleci.yml +++ /dev/null @@ -1,85 +0,0 @@ -preset: psr12 -risky: true - -version: 8.1 - -finder: - exclude: - - docs - - vendor - -enabled: - - alpha_ordered_traits - - array_indentation - - array_push - - combine_consecutive_issets - - combine_consecutive_unsets - - combine_nested_dirname - - declare_strict_types - - dir_constant - - fully_qualified_strict_types - - function_to_constant - - hash_to_slash_comment - - is_null - - logical_operators - - magic_constant_casing - - magic_method_casing - - method_separation - - modernize_types_casting - - native_function_casing - - native_function_type_declaration_casing - - no_alias_functions - - no_empty_comment - - no_empty_phpdoc - - no_empty_statement - - no_extra_block_blank_lines - - no_short_bool_cast - - no_superfluous_elseif - - no_unneeded_control_parentheses - - no_unneeded_curly_braces - - no_unneeded_final_method - - no_unset_cast - - no_unused_imports - - no_unused_lambda_imports - - no_useless_else - - no_useless_return - - normalize_index_brace - - php_unit_dedicate_assert - - php_unit_dedicate_assert_internal_type - - php_unit_expectation - - php_unit_mock - - php_unit_mock_short_will_return - - php_unit_namespaced - - php_unit_no_expectation_annotation - - phpdoc_no_empty_return - - phpdoc_no_useless_inheritdoc - - phpdoc_order - - phpdoc_property - - phpdoc_scalar - - phpdoc_singular_inheritdoc - - phpdoc_trim - - phpdoc_trim_consecutive_blank_line_separation - - phpdoc_type_to_var - - phpdoc_types - - phpdoc_types_order - - print_to_echo - - regular_callable_call - - return_assignment - - self_accessor - - self_static_accessor - - set_type_to_cast - - short_array_syntax - - short_list_syntax - - simplified_if_return - - single_quote - - standardize_not_equals - - ternary_to_null_coalescing - - trailing_comma_in_multiline_array - - unalign_double_arrow - - unalign_equals - - empty_loop_body_braces - - integer_literal_case - - union_type_without_spaces - -disabled: - - function_declaration diff --git a/composer.json b/composer.json index c4ca2ca..820711b 100644 --- a/composer.json +++ b/composer.json @@ -42,6 +42,7 @@ "roave/infection-static-analysis-plugin": "^1.35", "vimeo/psalm": "^5.26.1 || ^6.14.3", "vlucas/phpdotenv": "^5.6.2", + "yiisoft/code-style": "^1.0", "yiisoft/db-mssql": "^2.0", "yiisoft/db-mysql": "^2.0", "yiisoft/db-oracle": "^2.0", @@ -78,6 +79,7 @@ }, "scripts": { "psalm": "psalm", - "test": "phpunit --testdox --no-interaction" + "test": "phpunit --testdox --no-interaction", + "cs-fix": "php-cs-fixer fix" } } diff --git a/src/DbSchemaManager.php b/src/DbSchemaManager.php index ebe5f4e..5a8c25f 100644 --- a/src/DbSchemaManager.php +++ b/src/DbSchemaManager.php @@ -17,9 +17,7 @@ */ final class DbSchemaManager { - public function __construct(private ConnectionInterface $db) - { - } + public function __construct(private ConnectionInterface $db) {} /** * Ensures that the translator tables exists in the database. diff --git a/src/MessageSource.php b/src/MessageSource.php index 16d3e66..bb83171 100644 --- a/src/MessageSource.php +++ b/src/MessageSource.php @@ -38,12 +38,11 @@ final class MessageSource implements MessageReaderInterface, MessageWriterInterf public function __construct( private ConnectionInterface $db, - private CacheInterface|null $cache = null, + private ?CacheInterface $cache = null, private string $sourceMessageTable = '{{%yii_source_message}}', private string $messageTable = '{{%yii_message}}', - private int $cachingDuration = 3600 - ) { - } + private int $cachingDuration = 3600, + ) {} /** * @throws Exception @@ -51,7 +50,7 @@ public function __construct( * @throws InvalidConfigException * @throws Throwable */ - public function getMessage(string $id, string $category, string $locale, array $parameters = []): string|null + public function getMessage(string $id, string $category, string $locale, array $parameters = []): ?string { if (!isset($this->messages[$category][$locale])) { $this->messages[$category][$locale] = $this->read($category, $locale); @@ -162,8 +161,8 @@ private function read(string $category, string $locale): array /** @psalm-var array> */ return $this->cache->getOrSet( $this->getCacheKey($category, $locale), - fn (): array => $this->readFromDb($category, $locale), - $this->cachingDuration + fn(): array => $this->readFromDb($category, $locale), + $this->cachingDuration, ); } @@ -185,7 +184,7 @@ private function readFromDb(string $category, string $locale): array ->from(['ts' => $this->sourceMessageTable]) ->innerJoin( ['td' => $this->messageTable], - ['td.id' => new ColumnName('ts.id')] + ['td.id' => new ColumnName('ts.id')], ) ->where([ 'locale' => $locale, @@ -195,7 +194,7 @@ private function readFromDb(string $category, string $locale): array ->all(); return array_map( - static fn (array $message): array => empty($message['comment']) + static fn(array $message): array => empty($message['comment']) ? ['message' => $message['translation']] : [ 'message' => $message['translation'], diff --git a/tests/Common/AbstractMessageSourceTest.php b/tests/Common/AbstractMessageSourceTest.php index eb11627..0ecc5b4 100644 --- a/tests/Common/AbstractMessageSourceTest.php +++ b/tests/Common/AbstractMessageSourceTest.php @@ -84,13 +84,12 @@ public function testMultiWrite(): void $messageSource->write($category, $locale, $data); } - foreach ($allData as $fileData) { [$category, $locale, $data] = $fileData; foreach ($data as $messageId => $messageData) { $this->assertEquals( $messageData['message'], - $messageSource->getMessage($messageId, $category, $locale) + $messageSource->getMessage($messageId, $category, $locale), ); } } diff --git a/tests/Common/AbstractSQLDumpFileTest.php b/tests/Common/AbstractSQLDumpFileTest.php index e73fed2..7e21d72 100644 --- a/tests/Common/AbstractSQLDumpFileTest.php +++ b/tests/Common/AbstractSQLDumpFileTest.php @@ -12,6 +12,8 @@ use Yiisoft\Db\Exception\Exception; use Yiisoft\Db\Exception\InvalidConfigException; +use function dirname; + /** * @group Mssql */ diff --git a/tests/bootstrap.php b/tests/bootstrap.php index 3e174c3..0fcc416 100644 --- a/tests/bootstrap.php +++ b/tests/bootstrap.php @@ -2,7 +2,7 @@ declare(strict_types=1); -require dirname(__DIR__) . '/vendor/autoload.php'; +require \dirname(__DIR__) . '/vendor/autoload.php'; if (getenv('ENVIRONMENT', local_only: true) !== 'ci') { $dotenv = Dotenv\Dotenv::createUnsafeImmutable(__DIR__);