efabrica / phpstan-latte
Installs: 8 256
Dependents: 0
Suggesters: 0
Security: 0
Stars: 43
Watchers: 4
Forks: 4
Open Issues: 26
Requires
- php: >=7.4 <8.4
- ext-json: *
- latte/latte: ^2.11.6 | ^3.0.4
- nette/finder: ^2.5|^3.0
- nette/utils: ^3.2|^4.0
- phpstan/phpstan: ^1.10.50
- phpstan/phpstan-nette: ^1.2.6
Requires (Dev)
- efabrica/coding-standard: ^0.7
- nette/application: ^3.1.6
- nette/forms: ^3.1.12
- nikic/php-parser: ^4.19
- phpstan/phpstan-strict-rules: ^1.4
- phpunit/phpunit: ^9.5
- spaze/phpstan-disallowed-calls: ^2.11 | ^3.0
- dev-main
- 0.17.1
- 0.17.0
- 0.16.3
- 0.16.2
- 0.16.1
- 0.16.0
- 0.15.0
- 0.14.0
- 0.13.2
- 0.13.1
- 0.13.0
- 0.12.0
- 0.11.0
- 0.10.0
- 0.9.0
- 0.8.0
- 0.7.0
- 0.6.0
- 0.5.0
- 0.4.0
- 0.3.0
- 0.2.0
- 0.1.0
- dev-compatibility-updates
- dev-template-to-string
- dev-form-container-semi-dynamic-names
- dev-custom-form-final-classes
- dev-support-for-form-containers
This package is auto-updated.
Last update: 2024-11-30 20:17:43 UTC
README
PHPStan extension to check compiled Latte templates in context of a Presenter or a Component etc. Templates are compiled to PHP code which is then analyzed with PHPStan rules according to a configured rule level and rules from loaded extensions.
The extension is based on Tomas Votruba's blog series and his packages symplify and reveal.
Features
- Supports Latte 2 and Latte 3
- Templates are analysed in context in which they are rendered (one template can be analysed with different contexts if it is used on multiple places)
- Automatically collects all existing template variables, components, simple forms, render calls,... from PHP code.
- Analyses existence and parameters of filters and functions.
- Can analyse existence and parameters of links (if you configure
applicationMapping
). - Can use pre-configured latte engine from your application container (no need to configure manually)
- Analyses existence of components, forms and form fields used in template
- Analyses included templates in context of including template
- Can resolve rendered template path even from more complex expressions (but still has limitations)
- Can report unanalysed templates
- You can use annotations to fine-tuning analysis of latte templates
- If you use some non-standard and magic using rendering you can implement your own template resolvers (experimental)
Read How it works, when it doesn't, and troubleshooting
Installation
To use this extension, require it in Composer:
composer require efabrica/phpstan-latte --dev
If you also install phpstan/extension-installer then you're all set!
Manual installation
Add this line to your phpstan.neon:
includes: - vendor/efabrica/phpstan-latte/rules.neon
It is recommended to use this extension with phpstan-nette extension for better analysis of templates.
Configuration
- Latte engine configuration
- Analyser configuration
- Ignoring errors
- Link checking
- Other configuration options
If analysis reports errors about missing context (variables/components, ...) set in external packages you need to set option latte.collectedPaths
as descibed in Analyser configuration.
Annotations
There are cases that cannot be resolved automatically by static analysis.
In these cases annotations line @phpstan-latte-ignore
or @phpstan-latte-var
could be used to guide resolvers to analyse latte templates correctly.
How to extend this extension
This extension supports only common built-in methods for resolving paths to latte files, collecting variables, components, forms etc. However, we know that in a wild there are applications which use their own methods for these purposes. That's why we create this extension extensible. See more about this topic here.
Development
If you want to contribute your PR are welcomed. If you want to discuss your idea first then create issue.
Thank you for using this package. Let us know if it helped you or what could be improved.