Skip to content
Permalink
Browse files

Fall back to autoload when loading plugin classes (#1717)

* Fall back to autoload when loading plugin classes

This allows to use plugins installed alongside Psalm (when it's not
installed in the project being analyzed).

This fixes (partially) #1710

* cs fix
  • Loading branch information...
weirdan authored and muglug committed Jun 1, 2019
1 parent 0420865 commit 169121b6fdd78c984294b8511e8a23d2c3b35e28
Showing with 8 additions and 10 deletions.
  1. +8 −10 src/Psalm/Config.php
@@ -966,10 +966,7 @@ public function getPluginClasses(): array
* Initialises all the plugins (done once the config is fully loaded)
*
* @return void
* @psalm-suppress MixedArrayAccess
* @psalm-suppress MixedAssignment
* @psalm-suppress MixedOperand
* @psalm-suppress MixedArrayOffset
* @psalm-suppress MixedTypeCoercion
*/
public function initializePlugins(ProjectAnalyzer $project_analyzer)
@@ -982,13 +979,14 @@ public function initializePlugins(ProjectAnalyzer $project_analyzer)
$plugin_class_name = $plugin_class_entry['class'];
$plugin_config = $plugin_class_entry['config'];
try {
if ($this->composer_class_loader) {
$plugin_class_path = $this->composer_class_loader->findFile($plugin_class_name);
if (!$plugin_class_path) {
throw new \UnexpectedValueException($plugin_class_name . ' is not a known class');
}
// Below will attempt to load plugins from the project directory first.
// Failing that, it will use registered autoload chain, which will load
// plugins from Psalm directory or phar file. If that fails as well, it
// will fall back to project autoloader. It may seem that the last step
// will always fail, but it's only true if project uses Composer autoloader
if ($this->composer_class_loader
&& ($plugin_class_path = $this->composer_class_loader->findFile($plugin_class_name))
) {
/** @psalm-suppress UnresolvableInclude */
require_once($plugin_class_path);
} else {

0 comments on commit 169121b

Please sign in to comment.
You can’t perform that action at this time.