This PR was merged into the 3.x branch.
Discussion
----------
Add return type to compiled macro
This makes it easier for TwigStan to analyze the return type.
Commits
-------
1e7c719e24 Add return type to compiled macro
This PR was merged into the 3.x branch.
Discussion
----------
Rename Node classes related to variables
Whenever I work on Twig internals, it's always complicated to reason about variable names, probably because the class names are confusing. This PR is an attempt to find "better" and more explicit names.
This PR does the following renaming:
* `NameExpression` to `Variable\ContextVariable`
Represents the value of a context variable like `$context[VAR] ?? null`
* `AssignNameExpression` to `Variable\AssignContextVariable`
Represents a context variable assignment like in `$context[VAR] = `
* `TempNameExpression` to `Variable\LocalVariable`
Represents a "private" local variable like `$_l111`
Commits
-------
fc15e7ccbc Rename Node classes related to variables
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Documentation for types tag uses Twig types in examples instead of PHP
Specifically, "bool" => "boolean" and "int" => "number".
This aligns the `types` documentation with templates.rst. See #4362
Thanks, `@alexander`-schranz!
Commits
-------
f3e0a00cf0 Documentation for types tag uses Twig types in examples instead of PHP
This PR was merged into the 3.x branch.
Discussion
----------
Fix isset in ForLoopNode
Even though the code works perfectly fine, PHPStan doesn't understand it.
> Offset 'revindex0' does not exist on array{parent: array{index0: int<1, max>, index: int<2, max>, first: false, revindex0?: int, revindex?: int, length: int<0, max>, last?: bool}.
> Offset 'revindex' does not exist on array{parent: array{index0: int<1, max>, index: int<2, max>, first: false, revindex0: int, revindex?: int, length: int<0, max>, last?: bool}.
Since we want to work with `revindex` and `revindex0`, we can better check for their existence, instead of `length`.
/cc `@stof` `@fabpot`
Commits
-------
2b887e64 Fix isset in ForLoopNode
Even though the code works perfectly fine, PHPStan doesn't understand it.
Since we want to work with `revindex` and `revindex0`, we can better check for their
existence, instead of `length`.
Currently, the PHPDoc states that a string should be returned, but that's not correct.
It can be anything that is echo-able.
That means any scalar, Stringable and even null.
This PR was merged into the 3.x branch.
Discussion
----------
Migrate NodeTestCase to static data providers
PHPUnit 11 requires data providers to be static. This PR prepares our abstract `NodeTestCase` by deprecating the non-static `getTests()` and adding a static `provideTests()` as a replacement. I've also added PHPUnit attributes which newer PHPUnit releases prefer over PHPDoc annotations.
Commits
-------
f555a33c Migrate NodeTestCase to static data providers
Same as #4249
Even though PHP does not complain, PHPStan does.
> Cannot unset offset '_iterated' on array{ ... the context values ... }
Since this is compiled code, we can easily produce a bit more valid code in the eyes of PHPStan.
This PR was squashed before being merged into the 3.x branch.
Discussion
----------
Add return type `isTraitable`
I'd like to do this for more methods that are exposed in the compiled code. This will ease static analysis as there are less errors that are coming from Twig.
This is just a first small PR to see if this is acceptable 😊
Commits
-------
bb8b9c19 Add return type `isTraitable`