Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix CS #4542

Merged
merged 1 commit into from
Jan 19, 2025
Merged

Fix CS #4542

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
2 changes: 1 addition & 1 deletion extra/cache-extra/Tests/IntegrationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public function getExtensions()
protected function getRuntimeLoaders()
{
return [
new class() implements RuntimeLoaderInterface {
new class implements RuntimeLoaderInterface {
public function load(string $class): ?object
{
return CacheRuntime::class === $class ? new CacheRuntime(new ArrayAdapter()) : null;
Expand Down
2 changes: 1 addition & 1 deletion extra/markdown-extra/Tests/FunctionalTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function testMarkdown(string $template, string $expected)
=====
Great!
EOF
EOF,
]));
$twig->addExtension(new MarkdownExtension());
$twig->addRuntimeLoader(new class($class) implements RuntimeLoaderInterface {
Expand Down
2 changes: 1 addition & 1 deletion src/Extension/AbstractExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public function getLastModified(): int
$lastModified = filemtime($filename);

// Track modifications of the runtime class if it exists and follows the naming convention
if (str_ends_with($filename, 'Extension.php') && is_file($filename = substr($filename, 0, -13) . 'Runtime.php')) {
if (str_ends_with($filename, 'Extension.php') && is_file($filename = substr($filename, 0, -13).'Runtime.php')) {
$lastModified = max($lastModified, filemtime($filename));
}

Expand Down
2 changes: 1 addition & 1 deletion src/Extension/CoreExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -917,7 +917,7 @@ public static function keys($array): array
}

/**
* Invokes a callable
* Invokes a callable.
*
* @internal
*/
Expand Down
2 changes: 1 addition & 1 deletion src/Lexer.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ class Lexer
(?<DNUM>(?&LNUM)(?:(?&FRAC))?) # Decimal number 123_456.456
)(?:(?&DNUM)(?:(?&EXPONENT))?) # 123_456.456E+10
/Ax';

public const REGEX_DQ_STRING_DELIM = '/"/A';
public const REGEX_DQ_STRING_PART = '/[^#"\\\\]*(?:(?:\\\\.|#(?!\{))[^#"\\\\]*)*/As';
public const REGEX_INLINE_COMMENT = '/#[^\n]*/A';
Expand Down
3 changes: 2 additions & 1 deletion src/Template.php
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ protected function loadTemplate($template, $templateName = null, $line = null, $

/**
* @internal
*
* @return $this
*/
public function unwrap(): self
Expand Down Expand Up @@ -492,7 +493,7 @@ protected function hasMacro(string $name, array $context): bool
return $parent->hasMacro($name, $context);
}

protected function getTemplateForMacro(string $name, array $context, int $line, Source $source): Template
protected function getTemplateForMacro(string $name, array $context, int $line, Source $source): self
{
if (method_exists($this, $name)) {
return $this;
Expand Down
4 changes: 2 additions & 2 deletions tests/DeprecatedCallableInfoTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function testTriggerDeprecation($expected, DeprecatedCallableInfo $info)
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}

return false;
});

Expand Down Expand Up @@ -62,7 +62,7 @@ public function testTriggerDeprecationWithoutFileOrLine()
if (\E_USER_DEPRECATED === $type) {
$deprecations[] = $msg;
}

return false;
});

Expand Down
4 changes: 2 additions & 2 deletions tests/EnvironmentTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public function testExtensionsAreNotInitializedWhenRenderingACompiledTemplate()

// force compilation
$twig = new Environment($loader = new ArrayLoader(['index' => '{{ foo }}']), $options);
$twig->addExtension($extension = new class() extends AbstractExtension {
$twig->addExtension($extension = new class extends AbstractExtension {
public bool $throw = false;

public function getFilters(): array
Expand Down Expand Up @@ -475,7 +475,7 @@ protected function getMockLoader($templateName, $templateContent)
public function testResettingGlobals()
{
$twig = new Environment(new ArrayLoader(['index' => '']));
$twig->addExtension(new class() extends AbstractExtension implements GlobalsInterface {
$twig->addExtension(new class extends AbstractExtension implements GlobalsInterface {
public function getGlobals(): array
{
return [
Expand Down
10 changes: 5 additions & 5 deletions tests/ErrorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testTwigExceptionGuessWithMissingVarAndArrayLoader()
{% block foo %}
{{ foo.bar }}
{% endblock %}
EOHTML
EOHTML,
]);

$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);
Expand Down Expand Up @@ -70,7 +70,7 @@ public function testTwigExceptionGuessWithExceptionAndArrayLoader()
{% block foo %}
{{ foo.bar }}
{% endblock %}
EOHTML
EOHTML,
]);
$twig = new Environment($loader, ['strict_variables' => true, 'debug' => true, 'cache' => false]);

Expand Down Expand Up @@ -163,7 +163,7 @@ public function testTwigArrayFilterThrowsRuntimeExceptions()
{% for n in variable|filter(x => x > 3) %}
This list contains {{n}}.
{% endfor %}
EOHTML
EOHTML,
]);

$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
Expand All @@ -190,7 +190,7 @@ public function testTwigArrayMapThrowsRuntimeExceptions()
{% for n in variable|map(x => x * 3) %}
{{- n -}}
{% endfor %}
EOHTML
EOHTML,
]);

$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
Expand All @@ -215,7 +215,7 @@ public function testTwigArrayReduceThrowsRuntimeExceptions()
'reduce-null.html' => <<<EOHTML
{# We expect a runtime error if `variable` is not traversable #}
{{ variable|reduce((carry, x) => carry + x) }}
EOHTML
EOHTML,
]);

$twig = new Environment($loader, ['debug' => true, 'cache' => false]);
Expand Down
10 changes: 5 additions & 5 deletions tests/ExpressionParserTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ public function testUnknownTestWithoutSuggestions()
public function testCompiledCodeForDynamicTest()
{
$env = new Environment(new ArrayLoader(['index' => '{{ "a" is foo_foo_bar_bar }}']), ['cache' => false, 'autoescape' => false]);
$env->addExtension(new class() extends AbstractExtension {
$env->addExtension(new class extends AbstractExtension {
public function getTests()
{
return [
Expand All @@ -423,7 +423,7 @@ public function getTests()
public function testCompiledCodeForDynamicFunction()
{
$env = new Environment(new ArrayLoader(['index' => '{{ foo_foo_bar_bar("a") }}']), ['cache' => false, 'autoescape' => false]);
$env->addExtension(new class() extends AbstractExtension {
$env->addExtension(new class extends AbstractExtension {
public function getFunctions()
{
return [
Expand All @@ -438,7 +438,7 @@ public function getFunctions()
public function testCompiledCodeForDynamicFilter()
{
$env = new Environment(new ArrayLoader(['index' => '{{ "a"|foo_foo_bar_bar }}']), ['cache' => false, 'autoescape' => false]);
$env->addExtension(new class() extends AbstractExtension {
$env->addExtension(new class extends AbstractExtension {
public function getFilters()
{
return [
Expand Down Expand Up @@ -569,10 +569,10 @@ public function testTwoWordTestPrecedence()
public function testUnaryPrecedenceChange()
{
$env = new Environment(new ArrayLoader(), ['cache' => false, 'autoescape' => false]);
$env->addExtension(new class () extends AbstractExtension {
$env->addExtension(new class extends AbstractExtension {
public function getOperators()
{
$class = new class (new ConstantExpression('foo', 1), 1) extends AbstractUnary {
$class = new class(new ConstantExpression('foo', 1), 1) extends AbstractUnary {
public function operator(Compiler $compiler): Compiler
{
return $compiler->raw('!');
Expand Down
2 changes: 1 addition & 1 deletion tests/Extension/CoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public static function provideCycleInvalidCases()
{
return [
'empty' => [[]],
'non-countable' => [new class() extends \ArrayObject {
'non-countable' => [new class extends \ArrayObject {
}],
];
}
Expand Down
6 changes: 3 additions & 3 deletions tests/Extension/SandboxTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -565,7 +565,7 @@ protected function getEnvironment($sandboxed, $options, $templates, $tags = [],

public function testSandboxSourcePolicyEnableReturningFalse()
{
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface {
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class implements \Twig\Sandbox\SourcePolicyInterface {
public function enableSandbox(Source $source): bool
{
return '1_basic' != $source->getName();
Expand All @@ -576,7 +576,7 @@ public function enableSandbox(Source $source): bool

public function testSandboxSourcePolicyEnableReturningTrue()
{
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface {
$twig = $this->getEnvironment(false, [], self::$templates, [], [], [], [], [], new class implements \Twig\Sandbox\SourcePolicyInterface {
public function enableSandbox(Source $source): bool
{
return '1_basic' === $source->getName();
Expand All @@ -588,7 +588,7 @@ public function enableSandbox(Source $source): bool

public function testSandboxSourcePolicyFalseDoesntOverrideOtherEnables()
{
$twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], [], new class() implements \Twig\Sandbox\SourcePolicyInterface {
$twig = $this->getEnvironment(true, [], self::$templates, [], [], [], [], [], new class implements \Twig\Sandbox\SourcePolicyInterface {
public function enableSandbox(Source $source): bool
{
return false;
Expand Down
2 changes: 1 addition & 1 deletion tests/Node/Expression/FilterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ protected static function createEnvironment(): Environment

private static function createExtension(): AbstractExtension
{
return new class() extends AbstractExtension {
return new class extends AbstractExtension {
public function getFilters(): array
{
return [
Expand Down
Loading