1
0
mirror of https://github.com/danog/psalm.git synced 2024-11-30 04:39:00 +01:00

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) vimeo/psalm#1710

* cs fix
This commit is contained in:
Bruce Weirdan 2019-06-01 15:53:42 +03:00 committed by Matthew Brown
parent 0420865f72
commit 169121b6fd

View File

@ -966,10 +966,7 @@ class Config
* 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 @@ class Config
$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 {