Skip to content

Commit

Permalink
Bump phpmyadmin/coding-standard version to 4.0
Browse files Browse the repository at this point in the history
Signed-off-by: Maurício Meneghini Fauth <[email protected]>
  • Loading branch information
MauricioFauth committed Sep 13, 2023
1 parent b3be03d commit f37b41c
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 102 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
"twig/twig": "^3.7"
},
"require-dev": {
"phpmyadmin/coding-standard": "^3.0.0",
"phpmyadmin/coding-standard": "^4.0",
"phpmyadmin/motranslator": "^5.2",
"phpstan/phpstan": "^1.9.4",
"phpunit/phpunit": "^9.6"
Expand Down
5 changes: 1 addition & 4 deletions phpcs.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@
<file>src</file>
<file>test</file>

<rule ref="PhpMyAdmin">
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingNativeTypeHint"/>
<exclude name="SlevomatCodingStandard.TypeHints.ReturnTypeHint.MissingTraversableTypeHintSpecification"/>
</rule>
<rule ref="PhpMyAdmin"/>

<rule ref="SlevomatCodingStandard.ControlStructures.RequireSingleLineCondition"/>
<rule ref="SlevomatCodingStandard.Functions.RequireSingleLineCall"/>
Expand Down
2 changes: 1 addition & 1 deletion src/I18nExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function getName()
* @param string $message The message to translate
* @param string|null $domain The GetText domain
*/
public function translate(string $message, ?string $domain = null): string
public function translate(string $message, string|null $domain = null): string
{
/* If we don't have a domain, assume we're just using the default */
if ($domain === null) {
Expand Down
30 changes: 12 additions & 18 deletions src/Node/TransNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,41 +40,33 @@ class TransNode extends Node
{
/**
* The label for gettext notes to be exported
*
* @var string
*/
public static $notesLabel = '// notes: ';
public static string $notesLabel = '// notes: ';

/**
* Enable MoTranslator functions
*
* @var bool
*/
public static $enableMoTranslator = false;
public static bool $enableMoTranslator = false;

/**
* Enable calls to addDebugInfo
*
* @var bool
*/
public static $enableAddDebugInfo = false;
public static bool $enableAddDebugInfo = false;

/**
* Enables context functions usage
*
* @var bool
*/
public static $hasContextFunctions = false;
public static bool $hasContextFunctions = false;

public function __construct(
Node $body,
?Node $plural,
?AbstractExpression $count,
?Node $context = null,
?Node $notes = null,
?Node $domain = null,
Node|null $plural,
AbstractExpression|null $count,
Node|null $context = null,
Node|null $notes = null,
Node|null $domain = null,
int $lineno = 0,
?string $tag = null
string|null $tag = null,
) {
$nodes = ['body' => $body];
if ($count !== null) {
Expand Down Expand Up @@ -220,6 +212,8 @@ public function compile(Compiler $compiler)

/**
* Keep this method protected instead of private some implementations may use it
*
* @psalm-return array{Node, list<NameExpression>}
*/
protected function compileString(Node $body): array
{
Expand Down
22 changes: 7 additions & 15 deletions src/TokenParser/TransTokenParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

use PhpMyAdmin\Twig\Extensions\Node\TransNode;
use Twig\Error\SyntaxError;
use Twig\Node\Expression\AbstractExpression;
use Twig\Node\Expression\NameExpression;
use Twig\Node\Node;
use Twig\Node\PrintNode;
Expand Down Expand Up @@ -44,6 +45,7 @@ public function parse(Token $token)
return new TransNode($body, $plural, $count, $context, $notes, $domain, $lineno, $tag);
}

/** @psalm-return array{Node, Node|null, AbstractExpression|null, Node|null, Node|null, Node|null, int, string} */
protected function preParse(Token $token): array
{
$lineno = $token->getLine();
Expand Down Expand Up @@ -95,18 +97,12 @@ protected function preParse(Token $token): array
return [$body, $plural, $count, $context, $notes, $domain, $lineno, $this->getTag()];
}

/**
* @return bool
*/
public function decideForFork(Token $token)
public function decideForFork(Token $token): bool
{
return $token->test(['plural', 'context', 'notes', 'endtrans']);
}

/**
* @return bool
*/
public function decideForEnd(Token $token)
public function decideForEnd(Token $token): bool
{
return $token->test('endtrans');
}
Expand All @@ -119,12 +115,8 @@ public function getTag()
return 'trans';
}

/**
* @return void
*
* @throws SyntaxError
*/
protected function checkTransString(Node $body, int $lineno)
/** @throws SyntaxError */
protected function checkTransString(Node $body, int $lineno): void
{
foreach ($body as $i => $node) {
if (
Expand All @@ -137,7 +129,7 @@ protected function checkTransString(Node $body, int $lineno)

throw new SyntaxError(
'The text to be translated with "trans" can only contain references to simple variables.',
$lineno
$lineno,
);
}
}
Expand Down
13 changes: 4 additions & 9 deletions test/I18nExtensionMoTranslatorDebugTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\Tests\Twig\Extensions\MoTranslator\I18nExtensionDebug;
use PhpMyAdmin\Twig\Extensions\I18nExtension;
use Twig\Extension\AbstractExtension;
use Twig\Extension\ExtensionInterface;
use Twig\Test\IntegrationTestCase;

class I18nExtensionMoTranslatorDebugTest extends IntegrationTestCase
Expand All @@ -24,20 +24,15 @@ public static function setUpBeforeClass(): void
Loader::loadFunctions();
}

/**
* @return AbstractExtension[]
*/
public function getExtensions()
/** @return ExtensionInterface[] */
public function getExtensions(): array
{
return [
new I18nExtensionDebug(),
];
}

/**
* @return string
*/
public function getFixturesDir()
public function getFixturesDir(): string
{
return __DIR__ . '/Fixtures/';
}
Expand Down
13 changes: 4 additions & 9 deletions test/I18nExtensionMoTranslatorSandboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\Twig\Extensions\I18nExtension;
use Twig\Extension\AbstractExtension;
use Twig\Extension\ExtensionInterface;
use Twig\Extension\SandboxExtension;
use Twig\Sandbox\SecurityPolicy;
use Twig\Test\IntegrationTestCase;
Expand All @@ -25,10 +25,8 @@ public static function setUpBeforeClass(): void
Loader::loadFunctions();
}

/**
* @return AbstractExtension[]
*/
public function getExtensions()
/** @return ExtensionInterface[] */
public function getExtensions(): array
{
$tags = ['if', 'set', 'trans'];
$filters = ['upper', 'escape'];
Expand All @@ -43,10 +41,7 @@ public function getExtensions()
];
}

/**
* @return string
*/
public function getFixturesDir()
public function getFixturesDir(): string
{
return __DIR__ . '/FixturesWithSandbox/';
}
Expand Down
13 changes: 4 additions & 9 deletions test/I18nExtensionMoTranslatorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

use PhpMyAdmin\MoTranslator\Loader;
use PhpMyAdmin\Tests\Twig\Extensions\MoTranslator\I18nExtensionMoTranslator;
use Twig\Extension\AbstractExtension;
use Twig\Extension\ExtensionInterface;
use Twig\Test\IntegrationTestCase;

class I18nExtensionMoTranslatorTest extends IntegrationTestCase
Expand All @@ -23,20 +23,15 @@ public static function setUpBeforeClass(): void
Loader::loadFunctions();
}

/**
* @return AbstractExtension[]
*/
public function getExtensions()
/** @return ExtensionInterface[] */
public function getExtensions(): array
{
return [
new I18nExtensionMoTranslator(),
];
}

/**
* @return string
*/
public function getFixturesDir()
public function getFixturesDir(): string
{
return __DIR__ . '/Fixtures/';
}
Expand Down
13 changes: 4 additions & 9 deletions test/I18nExtensionSandboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@
namespace PhpMyAdmin\Tests\Twig\Extensions\Node;

use PhpMyAdmin\Twig\Extensions\I18nExtension;
use Twig\Extension\AbstractExtension;
use Twig\Extension\ExtensionInterface;
use Twig\Extension\SandboxExtension;
use Twig\Sandbox\SecurityPolicy;
use Twig\Test\IntegrationTestCase;

class I18nExtensionSandboxTest extends IntegrationTestCase
{
/**
* @return AbstractExtension[]
*/
public function getExtensions()
/** @return ExtensionInterface[] */
public function getExtensions(): array
{
$tags = ['if', 'set', 'trans'];
$filters = ['upper', 'escape'];
Expand All @@ -37,10 +35,7 @@ public function getExtensions()
];
}

/**
* @return string
*/
public function getFixturesDir()
public function getFixturesDir(): string
{
return __DIR__ . '/FixturesWithSandbox/';
}
Expand Down
13 changes: 4 additions & 9 deletions test/I18nExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,25 +12,20 @@
namespace PhpMyAdmin\Tests\Twig\Extensions\Node;

use PhpMyAdmin\Twig\Extensions\I18nExtension;
use Twig\Extension\AbstractExtension;
use Twig\Extension\ExtensionInterface;
use Twig\Test\IntegrationTestCase;

class I18nExtensionTest extends IntegrationTestCase
{
/**
* @return AbstractExtension[]
*/
public function getExtensions()
/** @return ExtensionInterface[] */
public function getExtensions(): array
{
return [
new I18nExtension(),
];
}

/**
* @return string
*/
public function getFixturesDir()
public function getFixturesDir(): string
{
return __DIR__ . '/Fixtures/';
}
Expand Down
16 changes: 7 additions & 9 deletions test/Node/MoTranslatorTransTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public function testFullConstructor(): void
$this->assertEquals($context, $node->getNode('context'));
}

/**
* @return array[]
*/
/** @return mixed[] */
public function getTests(): array
{
$tests = [];
Expand Down Expand Up @@ -107,7 +105,7 @@ public function getTests(): array
$node,
sprintf(
'echo strtr(_gettext("J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
$this->getVariableGetter('foo')
$this->getVariableGetter('foo'),
),
];

Expand All @@ -132,7 +130,7 @@ public function getTests(): array
. ' I have %%count%% apples", abs(12)), array("%%name%%" => %s,'
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',
$this->getVariableGetter('name'),
$this->getVariableGetter('name')
$this->getVariableGetter('name'),
),
];

Expand All @@ -149,7 +147,7 @@ public function getTests(): array
$node,
sprintf(
'echo strtr(_pgettext("The context", "J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
$this->getVariableGetter('foo')
$this->getVariableGetter('foo'),
),
];

Expand Down Expand Up @@ -177,7 +175,7 @@ public function getTests(): array
. ' I have %%count%% apples", abs(12)), array("%%name%%" => %s,'
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',
$this->getVariableGetter('name'),
$this->getVariableGetter('name')
$this->getVariableGetter('name'),
),
];

Expand All @@ -197,7 +195,7 @@ public function getTests(): array
$node,
sprintf(
'echo strtr(_dpgettext("mydomain", "The context", "J\'ai %%foo%% pommes"), array("%%foo%%" => %s, ));',
$this->getVariableGetter('foo')
$this->getVariableGetter('foo'),
),
];

Expand Down Expand Up @@ -228,7 +226,7 @@ public function getTests(): array
. ' "Hey %%name%%, I have %%count%% apples", abs(12)), array("%%name%%" => %s,'
. ' "%%name%%" => %s, "%%count%%" => abs(12), ));',
$this->getVariableGetter('name'),
$this->getVariableGetter('name')
$this->getVariableGetter('name'),
),
];

Expand Down
Loading

0 comments on commit f37b41c

Please sign in to comment.