Skip to content

Commit 09aaed1

Browse files
README: console-application.php for Symfony 5
1 parent 69d0cbf commit 09aaed1

File tree

1 file changed

+31
-10
lines changed

1 file changed

+31
-10
lines changed

README.md

+31-10
Original file line numberDiff line numberDiff line change
@@ -83,30 +83,51 @@ parameters:
8383

8484
Be aware that it may hide genuine errors in your application.
8585

86-
## Console command analysis
86+
## Analysis of Symfony Console Commands
8787

88-
You can opt in for more advanced analysis by providing the console application from your own application. This will allow the correct argument and option types to be inferred when accessing `$input->getArgument()` or `$input->getOption()`.
88+
You can opt in for more advanced analysis of [Symfony Console Commands](https://symfony.com/doc/current/console.html)
89+
by providing the console application from your own application. This will allow the correct argument and option types to be inferred when accessing `$input->getArgument()` or `$input->getOption()`.
8990

90-
```
91+
```neon
9192
parameters:
9293
symfony:
9394
console_application_loader: tests/console-application.php
9495
```
9596

96-
For example, in a Symfony project, `console-application.php` would look something like this:
97+
Symfony 4:
9798

9899
```php
99-
require __DIR__.'/../config/bootstrap.php';
100-
$kernel = new \App\Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
101-
return new \Symfony\Bundle\FrameworkBundle\Console\Application($kernel);
100+
// tests/console-application.php
101+
102+
use App\Kernel;
103+
use Symfony\Bundle\FrameworkBundle\Console\Application;
104+
105+
require __DIR__ . '/../config/bootstrap.php';
106+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
107+
return new Application($kernel);
102108
```
103109

104-
You may then encounter an error with PhpParser:
110+
Symfony 5:
111+
112+
```php
113+
// tests/console-application.php
105114
106-
```bash
107-
Compile Error: Cannot Declare interface PhpParser\NodeVisitor, because the name is already in use
115+
use App\Kernel;
116+
use Symfony\Bundle\FrameworkBundle\Console\Application;
117+
use Symfony\Component\Dotenv\Dotenv;
118+
119+
require __DIR__ . '/../vendor/autoload.php';
120+
121+
(new Dotenv())->bootEnv(__DIR__ . '/../.env');
122+
123+
$kernel = new Kernel($_SERVER['APP_ENV'], (bool) $_SERVER['APP_DEBUG']);
124+
return new Application($kernel);
108125
```
109126

127+
You may then encounter an error with PhpParser:
128+
129+
> Compile Error: Cannot Declare interface PhpParser\NodeVisitor, because the name is already in use
130+
110131
If this is the case, you should create a new environment for your application that will disable inlining. In `config/packages/phpstan_env/parameters.yaml`:
111132

112133
```yaml

0 commit comments

Comments
 (0)