My set-up comprises a lib
folder with classes and a view
folder with PHP files, that produce output. The views are imported inside a View
class similar to this:
class View {
public function render(string $basename, Array $params) : string {
extract($params, EXTR_PREFIX_INVALID, 'v');
ob_start();
include sprintf('%s/views/%s.php', dirname(__DIR__), $basename);
$out = ob_get_contents();
ob_end_clean();
return $out;
}
}
I have basically two problems with Psalm in this situation:
For
View::render
it reports aUnresolvableInclude
. I can even type the$basename
with something like@param "view1"|"view2"|"about" $basename
without effect. The unresolvable include remains.
The
extract()
puts the content of$params
in the local scope, where the view files are included. This allows me to have<?=escape($foo)?>
“tags” in my view files with
$params === ['foo' => 'bar']
. However, Psalm doesn’t catch up on this and reports a lot ofUndefinedGlobalVariable
problems.
My question: How can I tell psalm about the view files and the variables? Or alternatively, how can I re-structure this code so that psalm can test it for me?