Has anyone successfully set Psalm up with Kirby? I’m seeing a bunch of errors like UndefinedClass or PropertyNotSetInConstructor which makes me think it is an autoloading issue.
I think Psalm automatically uses Composer’s autoloader, but apparently that isn’t sufficient. I know index.php is the entry file for Kirby, so I tried adding autoloader="index.php" to my psalm.xml file. However, that resulted in a lot of DuplicateClass errors. I also tried using autoloader="kirby/bootstrap.php" but I still got the undefined type of errors.
So, has anyone figured out the right configuration for Psalm when making a Kirby site?
Thanks for providing the example! I hadn’t been able to find one myself. However, even with copying some of that, I don’t think it is working quite right. Also, I’m doing this for a Kirby site (the starterkit), not in a plugin.
If I run Psalm through the command line, the behavior seems more consistent as I change parameters in psalm.xml. So, it seems like the command line is the most reliable way to test Psalm.
I did find adding autoloader="index.php" to be helpful for analyzing individual files through the command line (I think this was helpful because I have a custom auto loader in a plugin). Unfortunately, autoloader="index.php" makes the GUI based single-file inspections in PhpStorm’s buggy since they no longer match the output from the command line.
So, the final solution was to add autoloader="site/plugins/my-pluging-with-custom-autoloader/index.php" to my psalm.xml.
I’ve also created a scope in PhpStorm for the site folder recursively (excluding the plugins folder recursively), and now I can now run full code analysis on that scope.