@@ -48,26 +48,58 @@ is likely disabled. A bug for sure, but perhaps not a critical one.
4848However, ` user.getRoleLabel(usr.role) ` will cause an uncaught ` TypeError ` if that method's parameter is not nullable,
4949since Twig will call that method with ` null ` . Instead of just having a buggy badge, * the whole page breaks* .
5050
51- # Usage
51+ # Installation
5252First, install using
5353``` bash
5454composer require --dev alisqi/twigqi
5555```
5656
57- Next, add the extension to your ` Twig\Environment ` :
57+ ## Symfony integration
58+ In a Symfony application, you can enable the extension in your ` config\services.yaml `
59+ ``` yaml
60+ when@dev :
61+ services :
62+ AlisQI\TwigQI\Extension :
63+ autowire : true
64+ tags : [ 'twig.extension' ]
65+ ` ` `
66+
67+ Alternatively, you can extend ` AlisQI\TwigQI\Extension` and add the `When` attribute.
5868` ` ` php
59- $logger = new AlisQI\TwigQI\Logger\TriggerErrorLogger();
60- $twig->addExtension(new AlisQI\TwigQI\Extension($logger));
69+ <?php
70+
71+ namespace App\T wig;
72+
73+ use AlisQI\T wigQI\E xtension;
74+ use Symfony\C omponent\D ependencyInjection\A ttribute\W hen;
75+
76+ #[When('dev')]
77+ class QualityExtension extends Extension {}
6178` ` `
79+ This allows you to configure which inspections to enable. See details below.
6280
63- The ` TriggerErrorLogger ` will report issues using PHP's ` trigger_error ` with ` E_USER_* ` levels.
64- Alternatively, you can use any other logger ` \Psr\Log\LoggerInterface ` implementation .
81+ # ## Logging
82+ Either way, all inspection results will [show up](docs/error-on-page.png) in the Web Debug Toolbar's logs .
6583
66- Set up your app and/or CI build to report these as you see fit.
84+ 
6785
68- And that's it! 😎
86+ This example is based on the [Symfony demo application](https://github.com/symfony/demo), where
87+ `src/templates/blog/post_show.html.twig` was amended to include the following in the `main` block :
88+ ` ` ` twig
89+ {% types post: '\\ App\\ Entity\\ Post' %}
90+ {% if false %} {# to demonstrate static typing during template compilation #}
91+ {{ post.tilte }}
92+ {% endif %}
93+ ` ` `
94+
95+ # # Non-Symfony projects
96+ You can also add the extension manually to your `Twig\Environment` :
97+ ` ` ` php
98+ $twig->addExtension(new AlisQI\T wigQI\E xtension($logger));
99+ ` ` `
69100
70101# # Configuration
102+ # ## Select inspections
71103You can cherry-pick your inspections (see below) :
72104` ` ` php
73105use AlisQI\T wigQI\E xtension;
@@ -80,6 +112,12 @@ new Extension($logger, [
80112]);
81113` ` `
82114
115+ # ## Logging
116+ The extension class requires a `\Psr\Log\LoggerInterface` implementation.
117+
118+ This package includes the `TriggerErrorLogger` class, which reports issues using PHP's `trigger_error()`
119+ with appropriate `E_USER_*` levels.
120+
83121# Design
84122The current design uses `NodeVisitor` classes for every inspection. That allows for easy testing and configurability.
85123
0 commit comments