mirror of
https://github.com/danog/psalm.git
synced 2024-11-30 04:39:00 +01:00
allow libraries to provide psalm plugins (#5165)
This commit is contained in:
parent
56b7cb2423
commit
d740c1679c
@ -31,11 +31,8 @@ class ComposerLock
|
||||
public function isPlugin($package): bool
|
||||
{
|
||||
return is_array($package)
|
||||
&& isset($package['name'])
|
||||
&& isset($package['name'], $package['extra']['psalm']['pluginClass'])
|
||||
&& is_string($package['name'])
|
||||
&& isset($package['type'])
|
||||
&& $package['type'] === 'psalm-plugin'
|
||||
&& isset($package['extra']['psalm']['pluginClass'])
|
||||
&& is_array($package['extra'])
|
||||
&& is_array($package['extra']['psalm'])
|
||||
&& is_string($package['extra']['psalm']['pluginClass']);
|
||||
@ -71,7 +68,7 @@ class ComposerLock
|
||||
}
|
||||
|
||||
/**
|
||||
* @return list<array{type:string,name:string,extra:array{psalm:array{pluginClass:string}}}>
|
||||
* @return list<array{name:string,extra:array{psalm:array{pluginClass:string}}}>
|
||||
*/
|
||||
private function getAllPluginPackages(): array
|
||||
{
|
||||
@ -80,7 +77,7 @@ class ComposerLock
|
||||
/** @psalm-suppress MixedAssignment */
|
||||
foreach ($packages as $package) {
|
||||
if ($this->isPlugin($package)) {
|
||||
/** @var array{type:'psalm-plugin',name:string,extra:array{psalm:array{pluginClass:string}}} */
|
||||
/** @var array{name:string,extra:array{psalm:array{pluginClass:string}}} */
|
||||
$ret[] = $package;
|
||||
}
|
||||
}
|
||||
|
@ -10,10 +10,39 @@ class ComposerLockTest extends TestCase
|
||||
/**
|
||||
* @test
|
||||
*/
|
||||
public function pluginIsPackageOfTypePsalmPlugin(): void
|
||||
public function packageIsPsalmPlugin(): void
|
||||
{
|
||||
$lock = new ComposerLock([$this->jsonFile((object)[])]);
|
||||
$this->assertTrue($lock->isPlugin($this->pluginEntry('vendor/package', 'Some\Class')));
|
||||
|
||||
$this->assertTrue($lock->isPlugin([
|
||||
'name' => 'vendor/package',
|
||||
'type' => 'psalm-plugin',
|
||||
'extra' => [
|
||||
'psalm' => [
|
||||
'pluginClass' => 'Some\Class'
|
||||
]
|
||||
]
|
||||
]), 'Non-plugin should not be considered a plugin');
|
||||
|
||||
$this->assertTrue($lock->isPlugin([
|
||||
'name' => 'vendor/package',
|
||||
'type' => 'library',
|
||||
'extra' => [
|
||||
'psalm' => [
|
||||
'pluginClass' => 'Some\Class'
|
||||
]
|
||||
]
|
||||
]), 'Non-plugin should not be considered a plugin');
|
||||
|
||||
$this->assertTrue($lock->isPlugin([
|
||||
'name' => 'vendor/package',
|
||||
'extra' => [
|
||||
'psalm' => [
|
||||
'pluginClass' => 'Some\Class'
|
||||
]
|
||||
]
|
||||
]), 'Non-plugin should not be considered a plugin');
|
||||
|
||||
// counterexamples
|
||||
|
||||
$this->assertFalse($lock->isPlugin([]), 'Non-package should not be considered a plugin');
|
||||
|
Loading…
Reference in New Issue
Block a user