-
Notifications
You must be signed in to change notification settings - Fork 0
/
PluginEntry.php
36 lines (31 loc) · 909 Bytes
/
PluginEntry.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
declare(strict_types=1);
namespace Altahrim\NextcloudPsalmPlugin;
use SimpleXMLElement;
use Psalm\Plugin\PluginEntryPointInterface;
use Psalm\Plugin\RegistrationInterface;
class PluginEntry implements PluginEntryPointInterface
{
public function __invoke(RegistrationInterface $psalm, ?SimpleXMLElement $config = null): void
{
$nextcloudBranch = isset($config->nextcloudVersion)
? $config->nextcloudVersion
: NextcloudVersion::get();
echo 'Target Nextcloud version: ', $nextcloudBranch, PHP_EOL;
$stubs = $this->listStubsForVersion($nextcloudBranch);
foreach ($stubs as $stub) {
$psalm->addStubFile($stub);
}
}
/**
* @return string[]
*/
private function listStubsForVersion(string $branch): array
{
$dir = __DIR__ . '/stubs/' . $branch;
if (!is_dir($dir)) {
throw new \Exception('Invalid version ' . $branch);
}
return glob($dir . '/*.phpstub' ) ?: [];
}
}