Skip to content

Commit

Permalink
Update phpdoc
Browse files Browse the repository at this point in the history
  • Loading branch information
GromNaN committed Nov 30, 2023
1 parent c7f20ab commit 9d3dd5b
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/Extension/Attribute/AsTwigFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
/**
* Registers a method as template filter.
*
* If the first argument of the method has Twig\Environment type-hint, the filter will receive the current environment.
* If the next argument of the method is named $context and has array type-hint, the filter will receive the current context.
* Additional arguments of the method come from the filter call.
*
* #[AsTwigFilter('foo')]
* function fooFilter(Environment $env, array $context, $string, $arg1 = null, ...) { ... }
*
* @see TwigFilter
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
7 changes: 7 additions & 0 deletions src/Extension/Attribute/AsTwigFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
/**
* Registers a method as template function.
*
* If the first argument of the method has Twig\Environment type-hint, the function will receive the current environment.
* If the next argument of the method is named $context and has array type-hint, the function will receive the current context.
* Additional arguments of the method come from the function call.
*
* #[AsTwigFunction('foo')]
* function fooFunction(Environment $env, array $context, $string, $arg1 = null, ...) { ... }
*
* @see TwigFunction
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
7 changes: 7 additions & 0 deletions src/Extension/Attribute/AsTwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,13 @@
/**
* Registers a method as template test.
*
* If the first argument of the method has Twig\Environment type-hint, the test will receive the current environment.
* If the next argument of the method is named $context and has array type-hint, the test will receive the current context.
* The last argument of the method is the value to be tested, if any.
*
* #[AsTwigTest('foo')]
* public function fooTest(Environment $env, array $context, $value, $arg1 = null) { ... }
*
* @see TwigTest
*/
#[\Attribute(\Attribute::TARGET_METHOD | \Attribute::IS_REPEATABLE)]
Expand Down
6 changes: 3 additions & 3 deletions src/Extension/AttributeExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ private function initFromAttributes()
foreach ($method->getAttributes(AsTwigFilter::class) as $attribute) {
$attribute = $attribute->newInstance();

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

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

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

0 comments on commit 9d3dd5b

Please sign in to comment.