Skip to content

Commit 8ac575b

Browse files
committed
feature: support stubs per major version
1 parent 89ed8f3 commit 8ac575b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

src/Plugin.php

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<?php
22
namespace Psalm\LaravelPlugin;
33

4+
use Illuminate\Foundation\Application;
45
use Psalm\LaravelPlugin\Handlers\Application\ContainerHandler;
56
use Psalm\LaravelPlugin\Handlers\Application\OffsetHandler;
67
use Psalm\LaravelPlugin\Handlers\Eloquent\ModelMethodHandler;
@@ -20,7 +21,9 @@
2021
use Psalm\Plugin\RegistrationInterface;
2122
use SimpleXMLElement;
2223
use Throwable;
24+
use function array_merge;
2325
use function dirname;
26+
use function explode;
2427
use function glob;
2528

2629
class Plugin implements PluginEntryPointInterface
@@ -39,9 +42,26 @@ public function __invoke(RegistrationInterface $registration, ?SimpleXMLElement
3942
$this->registerStubs($registration);
4043
}
4144

45+
protected function getCommonStubs(): array
46+
{
47+
return glob(dirname(__DIR__) . '/stubs/*.stubphp');
48+
}
49+
50+
protected function getStubsForVersion(string $version): array
51+
{
52+
[$majorVersion] = explode('.', $version);
53+
54+
return glob(dirname(__DIR__) . '/stubs/'.$majorVersion.'/*.stubphp');
55+
}
56+
4257
private function registerStubs(RegistrationInterface $registration): void
4358
{
44-
foreach (glob(dirname(__DIR__) . '/stubs/*.stubphp') as $stubFilePath) {
59+
$stubs = array_merge(
60+
$this->getCommonStubs(),
61+
$this->getStubsForVersion(Application::VERSION),
62+
);
63+
64+
foreach ($stubs as $stubFilePath) {
4565
$registration->addStubFile($stubFilePath);
4666
}
4767

0 commit comments

Comments
 (0)