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
6 changes: 3 additions & 3 deletions .github/workflows/static.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ on:
pull_request:
paths: &paths
- 'src/**'
- 'psalm.xml'
- 'phpstan.neon'
- 'composer.json'
- '.github/workflows/static.yml'
push:
Expand All @@ -19,8 +19,8 @@ concurrency:
cancel-in-progress: true

jobs:
psalm:
uses: yiisoft/actions/.github/workflows/psalm.yml@master
phpstan:
uses: yiisoft/actions/.github/workflows/phpstan.yml@master
with:
os: >-
['ubuntu-latest']
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 1.1.3 under development

- Chg #90: Replace Psalm with PHPStan (@vjik)
- Enh #85: Explicitly import functions and constants in "use" section (@vjik)

## 1.1.2 December 06, 2025
Expand Down
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
[![Code Coverage](https://codecov.io/gh/yiisoft/translator-message-php/branch/master/graph/badge.svg)](https://codecov.io/gh/yiisoft/translator-message-php)
[![Mutation testing badge](https://img.shields.io/endpoint?style=flat&url=https%3A%2F%2Fbadge-api.stryker-mutator.io%2Fgithub.com%2Fyiisoft%2Ftranslator-message-php%2Fmaster)](https://dashboard.stryker-mutator.io/reports/github.com/yiisoft/translator-message-php/master)
[![static analysis](https://github.com/yiisoft/translator-message-php/workflows/static%20analysis/badge.svg)](https://github.com/yiisoft/translator-message-php/actions?query=workflow%3A%22static+analysis%22)
[![type-coverage](https://shepherd.dev/github/yiisoft/translator-message-php/coverage.svg)](https://shepherd.dev/github/yiisoft/translator-message-php)

The package provides message storage backend based on PHP arrays to be used with [`yiisoft/translator`](https://github.com/yiisoft/translator) package.

Expand Down
2 changes: 2 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"require-dev": {
"bamarni/composer-bin-plugin": "^1.9.1",
"friendsofphp/php-cs-fixer": "^3.95",
"phpstan/phpstan": "^2.3",
"phpunit/phpunit": "^9.6.22",
"rector/rector": "^2.0.10",
"shipmonk/composer-dependency-analyser": "^1.8",
Expand Down Expand Up @@ -68,6 +69,7 @@
"scripts": {
"cs-fix": "php-cs-fixer fix",
"dependency-analyser": "composer-dependency-analyser",
"phpstan": "phpstan",
"rector": "rector",
"test": "phpunit --testdox --no-interaction",
"test-watch": "phpunit-watcher watch"
Expand Down
4 changes: 2 additions & 2 deletions docs/internals.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ The package tests are checked with [Infection](https://infection.github.io/) mut

## Static analysis

The code is statically analyzed with [Psalm](https://psalm.dev/). To run static analysis:
The code is statically analyzed with [PHPStan](https://phpstan.org/). To run static analysis:

```shell
./vendor/bin/psalm
./vendor/bin/phpstan
```

## Code style
Expand Down
5 changes: 5 additions & 0 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parameters:
level: max
paths:
- src
treatPhpDocTypesAsCertain: false
17 changes: 0 additions & 17 deletions psalm.xml

This file was deleted.

14 changes: 6 additions & 8 deletions src/MessageSource.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
final class MessageSource implements MessageReaderInterface, MessageWriterInterface
{
/**
* @psalm-var array<string, array<string, array<string, string>>>
* @var array<string, array<string, array<string, string>>>
*/
private array $messages = [];

Expand All @@ -45,13 +45,13 @@
foreach ($messages as &$message) {
$message = ['message' => $message];
}
/** @psalm-var array<string, array<string, string>> $messages */
/** @var array<string, array<string, string>> $messages */

return $messages;
}

/**
* @psalm-param array<string, array<string, string>> $messages
* @param array<string, array<string, string>> $messages
*/
public function write(string $category, string $locale, array $messages): void
{
Expand All @@ -64,14 +64,14 @@
}
}

private function getFilePath(string $category, string $locale, bool $withCreateDir = false): string

Check warning on line 67 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "FalseValue": @@ @@ throw new RuntimeException('Can not write to ' . $path); } } - private function getFilePath(string $category, string $locale, bool $withCreateDir = false): string + private function getFilePath(string $category, string $locale, bool $withCreateDir = true): string { if ($locale !== '' && !preg_match('/^[a-z0-9_-]+$/i', $locale)) { throw new InvalidArgumentException(sprintf('Invalid locale code: "%s".', $locale));
{
if ($locale !== '' && !preg_match('/^[a-z0-9_-]+$/i', $locale)) {

Check warning on line 69 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "PregMatchRemoveDollar": @@ @@ } private function getFilePath(string $category, string $locale, bool $withCreateDir = false): string { - if ($locale !== '' && !preg_match('/^[a-z0-9_-]+$/i', $locale)) { + if ($locale !== '' && !preg_match('/^[a-z0-9_-]+/i', $locale)) { throw new InvalidArgumentException(sprintf('Invalid locale code: "%s".', $locale)); } $filePath = $this->path . DIRECTORY_SEPARATOR . $locale;
throw new InvalidArgumentException(sprintf('Invalid locale code: "%s".', $locale));
}

$filePath = $this->path . DIRECTORY_SEPARATOR . $locale;
if ($withCreateDir && !file_exists($filePath) && !mkdir($filePath, 0775, true) && !is_dir($filePath)) {

Check warning on line 74 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "IncrementInteger": @@ @@ throw new InvalidArgumentException(sprintf('Invalid locale code: "%s".', $locale)); } $filePath = $this->path . DIRECTORY_SEPARATOR . $locale; - if ($withCreateDir && !file_exists($filePath) && !mkdir($filePath, 0775, true) && !is_dir($filePath)) { + if ($withCreateDir && !file_exists($filePath) && !mkdir($filePath, 510, true) && !is_dir($filePath)) { throw new RuntimeException(sprintf('Directory "%s" was not created', $filePath)); } $filePath .= DIRECTORY_SEPARATOR . $category . '.php';

Check warning on line 74 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "DecrementInteger": @@ @@ throw new InvalidArgumentException(sprintf('Invalid locale code: "%s".', $locale)); } $filePath = $this->path . DIRECTORY_SEPARATOR . $locale; - if ($withCreateDir && !file_exists($filePath) && !mkdir($filePath, 0775, true) && !is_dir($filePath)) { + if ($withCreateDir && !file_exists($filePath) && !mkdir($filePath, 508, true) && !is_dir($filePath)) { throw new RuntimeException(sprintf('Directory "%s" was not created', $filePath)); } $filePath .= DIRECTORY_SEPARATOR . $category . '.php';

Check warning on line 74 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "LogicalAnd": @@ @@ throw new InvalidArgumentException(sprintf('Invalid locale code: "%s".', $locale)); } $filePath = $this->path . DIRECTORY_SEPARATOR . $locale; - if ($withCreateDir && !file_exists($filePath) && !mkdir($filePath, 0775, true) && !is_dir($filePath)) { + if (($withCreateDir || !file_exists($filePath)) && !mkdir($filePath, 0775, true) && !is_dir($filePath)) { throw new RuntimeException(sprintf('Directory "%s" was not created', $filePath)); } $filePath .= DIRECTORY_SEPARATOR . $category . '.php';
throw new RuntimeException(sprintf('Directory "%s" was not created', $filePath));
}
$filePath .= DIRECTORY_SEPARATOR . $category . '.php';
Expand All @@ -89,7 +89,7 @@
if (!is_array($messages)) {
throw new RuntimeException('Invalid file format: ' . $path);
}
/** @psalm-var array<string, string> $messages */
/** @var array<string, string> $messages */
} else {
$messages = [];
}
Expand All @@ -98,7 +98,7 @@
}

/**
* @psalm-param array<string, array<string, string>> $messages
* @param array<string, array<string, string>> $messages
*/
private function generateMessagesFileContent(array $messages): string
{
Expand All @@ -115,7 +115,7 @@
}

/**
* @psalm-param array<string, array<string, string>> $messages
* @param array<string, array<string, string>> $messages
*/
private function messagesToCode(array $messages): string
{
Expand All @@ -125,21 +125,19 @@
throw new InvalidArgumentException("Message is not valid for ID \"$messageId\". \"message\" key is missing.");
}

/** @psalm-suppress DocblockTypeContradiction */
if (!is_string($messageData['message'])) {
throw new InvalidArgumentException("Message is not a string for ID \"$messageId\".");
}

if (array_key_exists('comment', $messageData)) {
/** @psalm-suppress DocblockTypeContradiction */
if (!is_string($messageData['comment'])) {
throw new InvalidArgumentException("Message comment is not a string for ID \"$messageId\".");
}

$code .= "\n" . ' /* ' . $messageData['comment'] . ' */';

Check warning on line 137 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ if (!is_string($messageData['comment'])) { throw new InvalidArgumentException("Message comment is not a string for ID \"{$messageId}\"."); } - $code .= "\n" . ' /* ' . $messageData['comment'] . ' */'; + $code .= "\n" . ' /* ' . ' */'; } $code .= "\n" . ' '; $code .= var_export($messageId, true);

Check warning on line 137 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ if (!is_string($messageData['comment'])) { throw new InvalidArgumentException("Message comment is not a string for ID \"{$messageId}\"."); } - $code .= "\n" . ' /* ' . $messageData['comment'] . ' */'; + $code .= ' /* ' . $messageData['comment'] . ' */'; } $code .= "\n" . ' '; $code .= var_export($messageId, true);

Check warning on line 137 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ if (!is_string($messageData['comment'])) { throw new InvalidArgumentException("Message comment is not a string for ID \"{$messageId}\"."); } - $code .= "\n" . ' /* ' . $messageData['comment'] . ' */'; + $code .= ' /* ' . "\n" . $messageData['comment'] . ' */'; } $code .= "\n" . ' '; $code .= var_export($messageId, true);
}

$code .= "\n" . ' ';

Check warning on line 140 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "ConcatOperandRemoval": @@ @@ } $code .= "\n" . ' /* ' . $messageData['comment'] . ' */'; } - $code .= "\n" . ' '; + $code .= ' '; $code .= var_export($messageId, true); $code .= ' => '; $code .= var_export($messageData['message'], true);

Check warning on line 140 in src/MessageSource.php

View workflow job for this annotation

GitHub Actions / mutation / PHP 8.5-ubuntu-latest

Escaped Mutant for Mutator "Concat": @@ @@ } $code .= "\n" . ' /* ' . $messageData['comment'] . ' */'; } - $code .= "\n" . ' '; + $code .= ' ' . "\n"; $code .= var_export($messageId, true); $code .= ' => '; $code .= var_export($messageData['message'], true);
$code .= var_export($messageId, true);
$code .= ' => ';
$code .= var_export($messageData['message'], true);
Expand Down
5 changes: 0 additions & 5 deletions tools/psalm/composer.json

This file was deleted.