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
14 changes: 7 additions & 7 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@
"require-dev": {
"phpmyadmin/coding-standard": "^4.0",
"phpstan/extension-installer": "^1.4",
"phpstan/phpstan": "^1.12",
"phpstan/phpstan-deprecation-rules": "^1.2",
"phpstan/phpstan-phpunit": "^1.4",
"phpstan/phpstan-strict-rules": "^1.6",
"phpunit/phpunit": "^10.5",
"psalm/plugin-phpunit": "^0.18.4",
"vimeo/psalm": "^5.6"
"phpstan/phpstan": "^2.1",
"phpstan/phpstan-deprecation-rules": "^2.0",
"phpstan/phpstan-phpunit": "^2.0",
"phpstan/phpstan-strict-rules": "^2.0",
"phpunit/phpunit": "^11.5 || ^12.0",
"psalm/plugin-phpunit": "^0.19.2",
"vimeo/psalm": "^6.8"
},
"suggest": {
"ext-apcu": "Needed for ACPu-backed translation cache"
Expand Down
56 changes: 34 additions & 22 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
@@ -1,91 +1,103 @@
parameters:
ignoreErrors:
-
message: "#^Call to function assert\\(\\) with true will always evaluate to true\\.$#"
message: '#^Call to function assert\(\) with true will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/Cache/ApcuCache.php

-
message: "#^Call to function is_array\\(\\) with array\\<string, string\\> will always evaluate to true\\.$#"
message: '#^Call to function is_array\(\) with array\<string, string\> will always evaluate to true\.$#'
identifier: function.alreadyNarrowedType
count: 1
path: src/Cache/ApcuCache.php

-
message: "#^Only booleans are allowed in \\|\\|, mixed given on the right side\\.$#"
message: '#^Only booleans are allowed in \|\|, mixed given on the right side\.$#'
identifier: booleanOr.rightNotBoolean
count: 1
path: src/Cache/ApcuCache.php

-
message: "#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#"
message: '#^Construct empty\(\) is not allowed\. Use more strict comparison\.$#'
identifier: empty.notAllowed
count: 1
path: src/Loader.php

-
message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\Loader\\:\\:detectlocale\\(\\) should return string but returns mixed\\.$#"
message: '#^Method PhpMyAdmin\\MoTranslator\\Loader\:\:detectlocale\(\) should return string but returns mixed\.$#'
identifier: return.type
count: 1
path: src/Loader.php

-
message: "#^Offset 'lang' on array\\{0\\: string, lang\\: non\\-falsy\\-string, 1\\: non\\-falsy\\-string, country\\?\\: string, 2\\?\\: string, charset\\?\\: string, 3\\?\\: string, modifier\\?\\: non\\-empty\\-string, \\.\\.\\.\\} on left side of \\?\\? always exists and is not nullable\\.$#"
message: '#^Offset ''lang'' on array\{0\: string, lang\: non\-falsy\-string, 1\: non\-falsy\-string, country\?\: string, 2\?\: string, charset\?\: string, 3\?\: string, modifier\?\: non\-empty\-string, \.\.\.\} on left side of \?\? always exists and is not nullable\.$#'
identifier: nullCoalesce.offset
count: 1
path: src/Loader.php

-
message: "#^Strict comparison using \\!\\=\\= between non\\-falsy\\-string and '' will always evaluate to true\\.$#"
message: '#^Strict comparison using \!\=\= between non\-falsy\-string and '''' will always evaluate to true\.$#'
identifier: notIdentical.alwaysTrue
count: 1
path: src/Loader.php

-
message: "#^Casting to int something that's already int\\.$#"
message: '#^Casting to int something that''s already int\.$#'
identifier: cast.useless
count: 1
path: src/MoParser.php

-
message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\StringReader\\:\\:readint\\(\\) should return int but returns mixed\\.$#"
message: '#^Method PhpMyAdmin\\MoTranslator\\StringReader\:\:readint\(\) should return int but returns mixed\.$#'
identifier: return.type
count: 1
path: src/StringReader.php

-
message: "#^Method PhpMyAdmin\\\\MoTranslator\\\\StringReader\\:\\:readintarray\\(\\) should return array\\<int\\> but returns array\\.$#"
message: '#^Method PhpMyAdmin\\MoTranslator\\StringReader\:\:readintarray\(\) should return array\<int\> but returns array\.$#'
identifier: return.type
count: 1
path: src/StringReader.php

-
message: "#^Foreach overwrites \\$header with its value variable\\.$#"
message: '#^Foreach overwrites \$header with its value variable\.$#'
identifier: foreach.valueOverwrite
count: 1
path: src/Translator.php

-
message: "#^Only numeric types are allowed in \\-, int\\|null given on the left side\\.$#"
message: '#^Only numeric types are allowed in \-, int\|null given on the left side\.$#'
identifier: minus.leftNonNumeric
count: 1
path: src/Translator.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:markTestSkipped\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 1
path: tests/Cache/ApcuCacheFactoryTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:markTestSkipped\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 1
path: tests/Cache/ApcuCacheTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:markTestSkipped\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 1
path: tests/Cache/ApcuDisabledTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:isInstanceOf\\(\\)\\.$#"
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:isInstanceOf\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 1
path: tests/LoaderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\Assert\\:\\:markTestSkipped\\(\\)\\.$#"
count: 1
path: tests/LoaderTest.php

-
message: "#^Dynamic call to static method PHPUnit\\\\Framework\\\\TestCase\\:\\:once\\(\\)\\.$#"
message: '#^Dynamic call to static method PHPUnit\\Framework\\Assert\:\:markTestSkipped\(\)\.$#'
identifier: staticMethod.dynamicCall
count: 1
path: tests/LoaderTest.php
8 changes: 1 addition & 7 deletions psalm-baseline.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<files psalm-version="5.26.1@d747f6500b38ac4f7dfc5edbcae6e4b637d7add0">
<files psalm-version="6.8.7@4258dc813b28c2b03865f34a17ddf072f006b357">
<file src="src/Cache/ApcuCache.php">
<MixedAssignment>
<code><![CDATA[$cached]]></code>
Expand All @@ -12,9 +12,6 @@
</RedundantConditionGivenDocblockType>
</file>
<file src="src/Loader.php">
<MixedInferredReturnType>
<code><![CDATA[string]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$GLOBALS['lang']]]></code>
</MixedReturnStatement>
Expand All @@ -23,9 +20,6 @@
<MixedAssignment>
<code><![CDATA[$result]]></code>
</MixedAssignment>
<MixedInferredReturnType>
<code><![CDATA[int]]></code>
</MixedInferredReturnType>
<MixedReturnStatement>
<code><![CDATA[$result < 0 ? PHP_INT_MAX : $result]]></code>
<code><![CDATA[$result < 0 ? PHP_INT_MAX : $result]]></code>
Expand Down
5 changes: 5 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
findUnusedCode="false"
findUnusedBaselineEntry="true"
errorBaseline="psalm-baseline.xml"
ensureOverrideAttribute="false"
>
<projectFiles>
<directory name="src"/>
Expand All @@ -21,4 +22,8 @@
<plugins>
<pluginClass class="Psalm\PhpUnitPlugin\Plugin"/>
</plugins>

<issueHandlers>
<ClassMustBeFinal errorLevel="suppress"/>
</issueHandlers>
</psalm>
3 changes: 2 additions & 1 deletion tests/Cache/ApcuCacheFactoryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpMyAdmin\MoTranslator\Cache\ApcuCache;
use PhpMyAdmin\MoTranslator\Cache\ApcuCacheFactory;
use PhpMyAdmin\MoTranslator\MoParser;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

use function apcu_clear_cache;
Expand All @@ -16,7 +17,7 @@
use function function_exists;
use function sleep;

/** @covers \PhpMyAdmin\MoTranslator\Cache\ApcuCacheFactory */
#[CoversClass(ApcuCacheFactory::class)]
class ApcuCacheFactoryTest extends TestCase
{
protected function setUp(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Cache/ApcuCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpMyAdmin\MoTranslator\Cache\ApcuCache;
use PhpMyAdmin\MoTranslator\MoParser;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;
use ReflectionMethod;

Expand All @@ -20,7 +21,7 @@
use function implode;
use function sleep;

/** @covers \PhpMyAdmin\MoTranslator\Cache\ApcuCache */
#[CoversClass(ApcuCache::class)]
class ApcuCacheTest extends TestCase
{
protected function setUp(): void
Expand Down
3 changes: 2 additions & 1 deletion tests/Cache/InMemoryCacheTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@

use PhpMyAdmin\MoTranslator\Cache\InMemoryCache;
use PhpMyAdmin\MoTranslator\MoParser;
use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\TestCase;

/** @covers \PhpMyAdmin\MoTranslator\Cache\InMemoryCache */
#[CoversClass(InMemoryCache::class)]
class InMemoryCacheTest extends TestCase
{
public function testConstructorParsesCache(): void
Expand Down
10 changes: 4 additions & 6 deletions tests/LoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use PhpMyAdmin\MoTranslator\Cache\CacheInterface;
use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\MoTranslator\MoParser;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\MockObject\MockObject;
use PHPUnit\Framework\TestCase;

Expand All @@ -19,11 +20,8 @@
*/
class LoaderTest extends TestCase
{
/**
* @param list<string> $expected
*
* @dataProvider localeList
*/
/** @param list<string> $expected */
#[DataProvider('localeList')]
public function testListLocales(string $locale, array $expected): void
{
self::assertSame($expected, Loader::listLocales($locale));
Expand Down Expand Up @@ -154,7 +152,7 @@ public function testLocaleChange(): void
self::assertSame('Тып', $translator->gettext('Type'));
}

/** @dataProvider translatorData */
#[DataProvider('translatorData')]
public function testGetTranslator(string $domain, string $locale, string $otherdomain, string $expected): void
{
$loader = $this->getLoader($domain, $locale);
Expand Down
13 changes: 7 additions & 6 deletions tests/MoFilesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpMyAdmin\MoTranslator\Cache\InMemoryCache;
use PhpMyAdmin\MoTranslator\MoParser;
use PhpMyAdmin\MoTranslator\Translator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function basename;
Expand All @@ -18,7 +19,7 @@
*/
class MoFilesTest extends TestCase
{
/** @dataProvider provideMoFiles */
#[DataProvider('provideMoFiles')]
public function testMoFileTranslate(string $filename): void
{
$parser = $this->getTranslator($filename);
Expand All @@ -33,7 +34,7 @@ public function testMoFileTranslate(string $filename): void
);
}

/** @dataProvider provideMoFiles */
#[DataProvider('provideMoFiles')]
public function testMoFilePlurals(string $filename): void
{
$parser = $this->getTranslator($filename);
Expand All @@ -56,14 +57,14 @@ public function testMoFilePlurals(string $filename): void
self::assertSame('"%d" seconds', $parser->ngettext('"%d" second', '"%d" seconds', 10));
}

/** @dataProvider provideMoFiles */
#[DataProvider('provideMoFiles')]
public function testMoFileContext(string $filename): void
{
$parser = $this->getTranslator($filename);
self::assertSame('Tabulka', $parser->pgettext('Display format', 'Table'));
}

/** @dataProvider provideNotTranslatedFiles */
#[DataProvider('provideNotTranslatedFiles')]
public function testMoFileNotTranslated(string $filename): void
{
$parser = $this->getTranslator($filename);
Expand All @@ -88,7 +89,7 @@ public static function provideNotTranslatedFiles(): array
return self::getFiles('./tests/data/not-translated/*.mo');
}

/** @dataProvider provideErrorMoFiles */
#[DataProvider('provideErrorMoFiles')]
public function testEmptyMoFile(string $file): void
{
$parser = new MoParser($file);
Expand All @@ -103,7 +104,7 @@ public function testEmptyMoFile(string $file): void
self::assertSame('"%d" seconds', $translator->ngettext('"%d" second', '"%d" seconds', 10));
}

/** @dataProvider provideMoFiles */
#[DataProvider('provideMoFiles')]
public function testExists(string $file): void
{
$parser = $this->getTranslator($file);
Expand Down
8 changes: 4 additions & 4 deletions tests/PluralFormulaTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace PhpMyAdmin\MoTranslator\Tests;

use PhpMyAdmin\MoTranslator\Translator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

/**
Expand All @@ -14,9 +15,8 @@ class PluralFormulaTest extends TestCase
{
/**
* Test for extractPluralsForms.
*
* @dataProvider pluralExtractionData
*/
#[DataProvider('pluralExtractionData')]
public function testExtractPluralsForms(string $header, string $expected): void
{
self::assertSame(
Expand Down Expand Up @@ -56,7 +56,7 @@ public static function pluralExtractionData(): array
];
}

/** @dataProvider pluralCounts */
#[DataProvider('pluralCounts')]
public function testPluralCounts(string $expr, int $expected): void
{
self::assertSame(
Expand Down Expand Up @@ -96,7 +96,7 @@ public static function pluralCounts(): array
];
}

/** @dataProvider pluralExpressions */
#[DataProvider('pluralExpressions')]
public function testPluralExpression(string $expr, string $expected): void
{
self::assertSame(
Expand Down
7 changes: 3 additions & 4 deletions tests/PluralTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use PhpMyAdmin\MoTranslator\Cache\InMemoryCache;
use PhpMyAdmin\MoTranslator\MoParser;
use PhpMyAdmin\MoTranslator\Translator;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;

use function chr;
Expand All @@ -22,9 +23,8 @@ class PluralTest extends TestCase
*
* @param int $number Number
* @param string $expected Expected output
*
* @dataProvider providerTestNpgettext
*/
#[DataProvider('providerTestNpgettext')]
public function testNpgettext(int $number, string $expected): void
{
$parser = $this->getTranslator('');
Expand Down Expand Up @@ -88,9 +88,8 @@ public static function dataProviderPluralForms(): array
* Test for ngettext
*
* @see https://github.com/phpmyadmin/motranslator/issues/37
*
* @dataProvider dataProviderPluralForms
*/
#[DataProvider('dataProviderPluralForms')]
public function testNgettextSelectString(string $pluralForms): void
{
$parser = $this->getTranslator('');
Expand Down
Loading