driveto / phpstan-twig
Twig extensions for PHPStan
0.0.1
2022-08-15 07:32 UTC
Requires
- php: ^8.0
- nikic/php-parser: ^4.14
- phpstan/phpstan: ^1.8
Requires (Dev)
- consistence-community/coding-standard: ^3.11
- phpstan/phpstan-phpunit: ^1.1
- phpstan/phpstan-strict-rules: ^1.3
- phpunit/phpunit: ^9.5
- slevomat/coding-standard: ^8.3
- squizlabs/php_codesniffer: ^3.7
- symfony/framework-bundle: ^5.0 || ^6.0
- twig/twig: ^3.4
This package is not auto-updated.
Last update: 2025-03-25 17:00:48 UTC
README
Inspired by blog series by @TomasVortuba - https://tomasvotruba.com/blog/stamp-1-how-to-compile-twig-to-php/
Known issues
- Performance
- Currently, templates are processed only sequentially
- Same templates with same variables included in multiple templates are checked multiple times
- High memory usage when depth of included templates is higher
- Method name guessing is not supported. I believe that template engine should not guess which method programmer wanted to use. Therefore, if you want to use method, use it with full name and parentheses
{{ class.fullMethodName() }}
Installation
To use this extension, require it in Composer:
composer require --dev driveto/phpstan-twig
Include extension.neon in your project's PHPStan config:
includes:
- vendor/driveto/phpstan-twig/extension.neon
Add path to Twig service in phpstan.neon:
parameters:
twig:
twigEnvironmentLoader: tests/TwigEnvironmentLoader.php
Example of Twig loader:
use App\Kernel; use Symfony\Component\Dotenv\Dotenv; require __DIR__ . '/../vendor/autoload.php'; (new Dotenv())->bootEnv(__DIR__ . '/../.env'); $kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']); $kernel->boot(); return $kernel->getContainer()->get('twig');