Conversation
d0a7ea1 to
396dc78
Compare
ruudk
left a comment
There was a problem hiding this comment.
I would use the Twig environment using a loader, then it auto picks up all namespaces.
ba45518 to
9b97b95
Compare
@ruudk, I've updated this to use a loader, but I'm not loving it. Because use App\Kernel;
use App\Kernel;
use Symfony\Component\Dotenv\Dotenv;
require __DIR__ . '/../vendor/autoload.php';
(new Dotenv())->bootEnv(__DIR__ . '/../.env');
$kernel = new Kernel('test', (bool) $_SERVER['APP_DEBUG']);
$kernel->boot();
return $kernel->getContainer()->get('test.service_container')->get('twig'); |
|
Yes. Downside is that now you are using the In TwigStan I came up with this solution: |
| if ($templateArg->value instanceof Variable && is_string($templateArg->value->name)) { | ||
| $varType = $scope->getVariableType($templateArg->value->name); | ||
|
|
||
| foreach ($varType->getConstantStrings() as $constantString) { | ||
| $templateNames[] = $constantString->getValue(); | ||
| } | ||
| } elseif ($templateArg->value instanceof String_) { | ||
| $templateNames[] = $templateArg->value->value; | ||
| } |
There was a problem hiding this comment.
I think you can avoid the if/else and write
| if ($templateArg->value instanceof Variable && is_string($templateArg->value->name)) { | |
| $varType = $scope->getVariableType($templateArg->value->name); | |
| foreach ($varType->getConstantStrings() as $constantString) { | |
| $templateNames[] = $constantString->getValue(); | |
| } | |
| } elseif ($templateArg->value instanceof String_) { | |
| $templateNames[] = $templateArg->value->value; | |
| } | |
| $argType = $scope->getType($templateArg->value); | |
| foreach ($varType->getConstantStrings() as $constantString) { | |
| $templateNames[] = $constantString->getValue(); | |
| } |
| foreach ($templateNames as $templateName) { | ||
| if ($this->twigEnvironmentResolver->templateExists($templateName)) { | ||
| continue; | ||
| } | ||
|
|
||
| $errors[] = RuleErrorBuilder::message(sprintf( | ||
| 'Twig template "%s" does not exist.', | ||
| $templateName | ||
| ))->line($templateArg->getStartLine())->identifier('twig.templateNotFound')->build(); | ||
| } |
There was a problem hiding this comment.
I dunno if the error strategy need to depends on the PHPStan Level.
For instance, maybe existingTemplate|nonExistingTemplate should only be reported at level 7 or more.
In the same way unions/maybe are reported on level 7 for classic rules.
Fixes #257