Skip to content

Commit

Permalink
Switch to the new DeprecatedCallableInfo object
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 24, 2024
1 parent f634240 commit 1906c8f
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 40 deletions.
11 changes: 2 additions & 9 deletions src/Attribute/AsTwigFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Twig\Attribute;

use Twig\DeprecatedCallableInfo;
use Twig\Node\Node;
use Twig\TwigFilter;

Expand Down Expand Up @@ -64,15 +65,7 @@ public function __construct(
*/
public ?array $preservesSafety = null,

/**
* Set to true if the filter is deprecated.
*/
public bool|string $deprecated = false,

/**
* The alternative filter name to suggest when the deprecated filter is called.
*/
public ?string $alternative = null,
public ?DeprecatedCallableInfo $deprecationInfo = null,
) {
}
}
11 changes: 2 additions & 9 deletions src/Attribute/AsTwigFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Twig\Attribute;

use Twig\DeprecatedCallableInfo;
use Twig\Node\Node;
use Twig\TwigFunction;

Expand Down Expand Up @@ -51,15 +52,7 @@ public function __construct(
*/
public ?string $isSafeCallback = null,

/**
* Set to true if the function is deprecated.
*/
public bool|string $deprecated = false,

/**
* The alternative function name to suggest when the deprecated function is called.
*/
public ?string $alternative = null,
public ?DeprecatedCallableInfo $deprecationInfo = null,
) {
}
}
11 changes: 2 additions & 9 deletions src/Attribute/AsTwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

namespace Twig\Attribute;

use Twig\DeprecatedCallableInfo;
use Twig\TwigTest;

/**
Expand All @@ -36,15 +37,7 @@ public function __construct(
*/
public string $name,

/**
* Set to true if the function is deprecated.
*/
public bool|string $deprecated = false,

/**
* The alternative function name to suggest when the deprecated function is called.
*/
public ?string $alternative = null,
public ?DeprecatedCallableInfo $deprecationInfo = null,
) {
}
}
9 changes: 3 additions & 6 deletions src/Extension/AttributeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,7 @@ private function initFromAttributes()
'is_safe_callback' => $attribute->isSafeCallback,
'pre_escape' => $attribute->preEscape,
'preserves_safety' => $attribute->preservesSafety,
'deprecated' => $attribute->deprecated,
'alternative' => $attribute->alternative,
'deprecation_info' => $attribute->deprecationInfo,
]);
}

Expand All @@ -134,8 +133,7 @@ private function initFromAttributes()
'is_variadic' => $isVariadic,
'is_safe' => $attribute->isSafe,
'is_safe_callback' => $attribute->isSafeCallback,
'deprecated' => $attribute->deprecated,
'alternative' => $attribute->alternative,
'deprecation_info' => $attribute->deprecationInfo,
]);
}

Expand All @@ -150,8 +148,7 @@ private function initFromAttributes()

$tests[$name] = new TwigTest($name, [$objectOrClass, $method->getName()], [
'is_variadic' => $isVariadic,
'deprecated' => $attribute->deprecated,
'alternative' => $attribute->alternative,
'deprecation_info' => $attribute->deprecationInfo,
]);
}
}
Expand Down
10 changes: 6 additions & 4 deletions tests/Extension/AttributeExtensionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,16 @@
namespace Twig\Tests\Extension;

use PHPUnit\Framework\TestCase;
use Twig\DeprecatedCallableInfo;
use Twig\Extension\AttributeExtension;
use Twig\Tests\Extension\Fixtures\ExtensionWithAttributes;
use Twig\TwigFilter;
use Twig\TwigFunction;
use Twig\TwigTest;

/**
* @requires PHP >= 8.0
* Nested attributes are not supported in PHP 8.0.
* @requires PHP >= 8.1
*/
class AttributeExtensionTest extends TestCase
{
Expand Down Expand Up @@ -40,7 +42,7 @@ public static function provideFilters()
yield 'with env and context' => ['with_env_and_context_filter', 'withEnvAndContextFilter', ['needs_environment' => true, 'needs_context' => true]];
yield 'no argument' => ['no_arg_filter', 'noArgFilter', []];
yield 'variadic' => ['variadic_filter', 'variadicFilter', ['is_variadic' => true]];
yield 'deprecated' => ['deprecated_filter', 'deprecatedFilter', ['deprecated' => true, 'alternative' => 'bar']];
yield 'deprecated' => ['deprecated_filter', 'deprecatedFilter', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]];
yield 'pattern' => ['pattern_*_filter', 'patternFilter', []];
}

Expand Down Expand Up @@ -70,7 +72,7 @@ public static function provideFunctions()
yield 'with env and context' => ['with_env_and_context_function', 'withEnvAndContextFunction', ['needs_environment' => true, 'needs_context' => true]];
yield 'no argument' => ['no_arg_function', 'noArgFunction', []];
yield 'variadic' => ['variadic_function', 'variadicFunction', ['is_variadic' => true]];
yield 'deprecated' => ['deprecated_function', 'deprecatedFunction', ['deprecated' => true, 'alternative' => 'bar']];
yield 'deprecated' => ['deprecated_function', 'deprecatedFunction', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]];
}

/**
Expand All @@ -95,7 +97,7 @@ public static function provideTests()
{
yield 'with name' => ['foo', 'fooTest', []];
yield 'variadic' => ['variadic_test', 'variadicTest', ['is_variadic' => true]];
yield 'deprecated' => ['deprecated_test', 'deprecatedTest', ['deprecated' => true, 'alternative' => 'bar']];
yield 'deprecated' => ['deprecated_test', 'deprecatedTest', ['deprecation_info' => new DeprecatedCallableInfo('foo/bar', '1.2')]];
}

public function testRuntimeExtension()
Expand Down
7 changes: 4 additions & 3 deletions tests/Extension/Fixtures/ExtensionWithAttributes.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use Twig\Attribute\AsTwigFilter;
use Twig\Attribute\AsTwigFunction;
use Twig\Attribute\AsTwigTest;
use Twig\DeprecatedCallableInfo;
use Twig\Environment;

#[AsTwigExtension]
Expand Down Expand Up @@ -41,7 +42,7 @@ public function variadicFilter(string ...$strings)
{
}

#[AsTwigFilter('deprecated_filter', deprecated: true, alternative: 'bar')]
#[AsTwigFilter('deprecated_filter', deprecationInfo: new DeprecatedCallableInfo('foo/bar', '1.2'))]
public function deprecatedFilter(string $string)
{
}
Expand Down Expand Up @@ -81,7 +82,7 @@ public function variadicFunction(string ...$strings)
{
}

#[AsTwigFunction('deprecated_function', deprecated: true, alternative: 'bar')]
#[AsTwigFunction('deprecated_function', deprecationInfo: new DeprecatedCallableInfo('foo/bar', '1.2'))]
public function deprecatedFunction(string $string)
{
}
Expand All @@ -96,7 +97,7 @@ public function variadicTest(string ...$strings)
{
}

#[AsTwigTest('deprecated_test', deprecated: true, alternative: 'bar')]
#[AsTwigTest('deprecated_test', deprecationInfo: new DeprecatedCallableInfo('foo/bar', '1.2'))]
public function deprecatedTest(string $string)
{
}
Expand Down

0 comments on commit 1906c8f

Please sign in to comment.