Skip to content

Commit

Permalink
minor #3856 Fix callable phpdoc for twig elements (VincentLanglet)
Browse files Browse the repository at this point in the history
This PR was merged into the 3.x branch.

Discussion
----------

Fix callable phpdoc for twig elements

Hi `@fabpot`
```
[MyRuntime::class, 'myMethod]
```
is not a valid callable in PHP 8 https://3v4l.org/tWqPs

But this syntax is supported because twig has a special behavior
```
$compiler->raw(sprintf('$this->env->getRuntime(\'%s\')->%s', $callable[0], $callable[1]));
```

The PHPDoc should be updated in order to reflect the real behavior and solve static analysis errors.
A phpstan discussion can be found here: phpstan/phpstan#9567

Commits
-------

cd68de5 Fix callable phpdoc for twig elements
  • Loading branch information
fabpot committed Jul 5, 2023
2 parents 58f7b22 + cd68de5 commit e145d36
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions src/TwigFilter.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class TwigFilter
private $arguments = [];

/**
* @param callable|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation.
* @param callable|array<class-string, string>|null $callable A callable implementing the filter. If null, you need to overwrite the "node_class" option to customize compilation.
*/
public function __construct(string $name, $callable = null, array $options = [])
{
Expand Down Expand Up @@ -57,7 +57,7 @@ public function getName(): string
/**
* Returns the callable to execute for this filter.
*
* @return callable|null
* @return callable|array<class-string, string>|null
*/
public function getCallable()
{
Expand Down
4 changes: 2 additions & 2 deletions src/TwigFunction.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ final class TwigFunction
private $arguments = [];

/**
* @param callable|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation.
* @param callable|array<class-string, string>|null $callable A callable implementing the function. If null, you need to overwrite the "node_class" option to customize compilation.
*/
public function __construct(string $name, $callable = null, array $options = [])
{
Expand All @@ -55,7 +55,7 @@ public function getName(): string
/**
* Returns the callable to execute for this function.
*
* @return callable|null
* @return callable|array<class-string, string>|null
*/
public function getCallable()
{
Expand Down
4 changes: 2 additions & 2 deletions src/TwigTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ final class TwigTest
private $arguments = [];

/**
* @param callable|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation.
* @param callable|array<class-string, string>|null $callable A callable implementing the test. If null, you need to overwrite the "node_class" option to customize compilation.
*/
public function __construct(string $name, $callable = null, array $options = [])
{
Expand All @@ -51,7 +51,7 @@ public function getName(): string
/**
* Returns the callable to execute for this test.
*
* @return callable|null
* @return callable|array<class-string, string>|null
*/
public function getCallable()
{
Expand Down

0 comments on commit e145d36

Please sign in to comment.