Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .github/workflows/rector-cs.yml
Original file line number Diff line number Diff line change
@@ -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'
28 changes: 0 additions & 28 deletions .github/workflows/rector.yml

This file was deleted.

4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,7 @@ composer.phar
/phpunit.phar
/phpunit.xml
/.phpunit.cache

# PHP CS Fixer
/.php-cs-fixer.cache
/.php-cs-fixer.php
21 changes: 21 additions & 0 deletions .php-cs-fixer.dist.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?php

declare(strict_types=1);

use PhpCsFixer\Finder;
use PhpCsFixer\Runner\Parallel\ParallelConfigFactory;
use Yiisoft\CodeStyle\ConfigBuilder;

$finder = (new Finder())->in([
__DIR__ . '/src',
__DIR__ . '/tests',
]);

return ConfigBuilder::build()
->setRiskyAllowed(true)
->setParallelConfig(ParallelConfigFactory::detect())
->setRules([
'@Yiisoft/Core' => true,
'@Yiisoft/Core:risky' => true,
])
->setFinder($finder);
85 changes: 0 additions & 85 deletions .styleci.yml

This file was deleted.

4 changes: 3 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -78,6 +79,7 @@
},
"scripts": {
"psalm": "psalm",
"test": "phpunit --testdox --no-interaction"
"test": "phpunit --testdox --no-interaction",
"cs-fix": "php-cs-fixer fix"
}
}
4 changes: 1 addition & 3 deletions src/DbSchemaManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -40,7 +38,7 @@
$tableRawNameSourceMessage = $quoter->getRawTableName($tableSourceMessage);
$tableRawNameMessage = $quoter->getRawTableName($tableMessage);

if ($schema->hasTable($tableRawNameSourceMessage, refresh: true)

Check warning on line 41 in src/DbSchemaManager.php

View workflow job for this annotation

GitHub Actions / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ $tableRawNameSourceMessage = $quoter->getRawTableName($tableSourceMessage); $tableRawNameMessage = $quoter->getRawTableName($tableMessage); - if ($schema->hasTable($tableRawNameSourceMessage, refresh: true) + if ($schema->hasTable($tableRawNameSourceMessage, refresh: false) && $schema->hasTable($tableRawNameMessage) ) { return;
&& $schema->hasTable($tableRawNameMessage)
) {
return;
Expand Down Expand Up @@ -68,7 +66,7 @@
$tableRawNameSourceMessage = $quoter->getRawTableName($tableSourceMessage);
$tableRawNameMessage = $quoter->getRawTableName($tableMessage);

if ($schema->hasTable($tableRawNameMessage, refresh: true)) {

Check warning on line 69 in src/DbSchemaManager.php

View workflow job for this annotation

GitHub Actions / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "TrueValue": @@ @@ $tableRawNameSourceMessage = $quoter->getRawTableName($tableSourceMessage); $tableRawNameMessage = $quoter->getRawTableName($tableMessage); - if ($schema->hasTable($tableRawNameMessage, refresh: true)) { + if ($schema->hasTable($tableRawNameMessage, refresh: false)) { // drop table `yii_message`. $this->db->createCommand()->dropTable($tableRawNameMessage)->execute(); }
// drop table `yii_message`.
$this->db->createCommand()->dropTable($tableRawNameMessage)->execute();
}
Expand Down
17 changes: 8 additions & 9 deletions src/MessageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,20 +38,19 @@

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
* @throws JsonException
* @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);
Expand Down Expand Up @@ -162,8 +161,8 @@
/** @psalm-var array<string, array<string, string>> */
return $this->cache->getOrSet(
$this->getCacheKey($category, $locale),
fn (): array => $this->readFromDb($category, $locale),
$this->cachingDuration
fn(): array => $this->readFromDb($category, $locale),
$this->cachingDuration,
);
}

Expand All @@ -185,7 +184,7 @@
->from(['ts' => $this->sourceMessageTable])
->innerJoin(
['td' => $this->messageTable],
['td.id' => new ColumnName('ts.id')]
['td.id' => new ColumnName('ts.id')],
)
->where([
'locale' => $locale,
Expand All @@ -195,7 +194,7 @@
->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'],
Expand All @@ -210,7 +209,7 @@
*/
private function getCacheKey(string $category, string $locale): string
{
$key = [self::class, $category, $locale];

Check warning on line 212 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ArrayItemRemoval": @@ @@ */ private function getCacheKey(string $category, string $locale): string { - $key = [self::class, $category, $locale]; + $key = [$category, $locale]; $jsonKey = json_encode($key, JSON_THROW_ON_ERROR); return md5($jsonKey);
$jsonKey = json_encode($key, JSON_THROW_ON_ERROR);

return md5($jsonKey);
Expand Down
3 changes: 1 addition & 2 deletions tests/Common/AbstractMessageSourceTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
);
}
}
Expand Down
2 changes: 2 additions & 0 deletions tests/Common/AbstractSQLDumpFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
use Yiisoft\Db\Exception\Exception;
use Yiisoft\Db\Exception\InvalidConfigException;

use function dirname;

/**
* @group Mssql
*/
Expand Down
2 changes: 1 addition & 1 deletion tests/bootstrap.php
Original file line number Diff line number Diff line change
Expand Up @@ -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__);
Expand Down