Skip to content

Commit 9d3dd5b

Browse files
committed
Update phpdoc
1 parent c7f20ab commit 9d3dd5b

File tree

4 files changed

+24
-3
lines changed

4 files changed

+24
-3
lines changed

src/Extension/Attribute/AsTwigFilter.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
/**
88
* Registers a method as template filter.
99
*
10+
* If the first argument of the method has Twig\Environment type-hint, the filter will receive the current environment.
11+
* If the next argument of the method is named $context and has array type-hint, the filter will receive the current context.
12+
* Additional arguments of the method come from the filter call.
13+
*
14+
* #[AsTwigFilter('foo')]
15+
* function fooFilter(Environment $env, array $context, $string, $arg1 = null, ...) { ... }
16+
*
1017
* @see TwigFilter
1118
*/
1219
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]

src/Extension/Attribute/AsTwigFunction.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
/**
88
* Registers a method as template function.
99
*
10+
* If the first argument of the method has Twig\Environment type-hint, the function will receive the current environment.
11+
* If the next argument of the method is named $context and has array type-hint, the function will receive the current context.
12+
* Additional arguments of the method come from the function call.
13+
*
14+
* #[AsTwigFunction('foo')]
15+
* function fooFunction(Environment $env, array $context, $string, $arg1 = null, ...) { ... }
16+
*
1017
* @see TwigFunction
1118
*/
1219
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]

src/Extension/Attribute/AsTwigTest.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
/**
88
* Registers a method as template test.
99
*
10+
* If the first argument of the method has Twig\Environment type-hint, the test will receive the current environment.
11+
* If the next argument of the method is named $context and has array type-hint, the test will receive the current context.
12+
* The last argument of the method is the value to be tested, if any.
13+
*
14+
* #[AsTwigTest('foo')]
15+
* public function fooTest(Environment $env, array $context, $value, $arg1 = null) { ... }
16+
*
1017
* @see TwigTest
1118
*/
1219
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]

src/Extension/AttributeExtension.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ private function initFromAttributes()
9898
foreach ($method->getAttributes(AsTwigFilter::class) as $attribute) {
9999
$attribute = $attribute->newInstance();
100100

101-
$name = $attribute->name ?? $method->getName();
101+
$name = $attribute->name;
102102
if (isset($filters[$name])) {
103103
throw new \LogicException(sprintf('Multiple definitions of the "%s" filter.', $name));
104104
}
@@ -127,7 +127,7 @@ private function initFromAttributes()
127127
foreach ($method->getAttributes(AsTwigFunction::class) as $attribute) {
128128
$attribute = $attribute->newInstance();
129129

130-
$name = $attribute->name ?? $method->getName();
130+
$name = $attribute->name;
131131
if (isset($functions[$name])) {
132132
throw new \LogicException(sprintf('Multiple definitions of the "%s" function.', $name));
133133
}
@@ -154,7 +154,7 @@ private function initFromAttributes()
154154
foreach ($method->getAttributes(AsTwigTest::class) as $attribute) {
155155
$attribute = $attribute->newInstance();
156156

157-
$name = $attribute->name ?? $method->getName();
157+
$name = $attribute->name;
158158
if (isset($tests[$name])) {
159159
throw new \LogicException(sprintf('Multiple definitions of the "%s" test.', $name));
160160
}

0 commit comments

Comments
 (0)