Skip to content

Commit

Permalink
Allow dynamic list of stub files thanks to StubFilesExtension
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Sep 2, 2021
1 parent 23b1c7f commit 2ba9332
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
13 changes: 13 additions & 0 deletions src/PhpDoc/StubFilesExtension.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php declare(strict_types = 1);

namespace PHPStan\PhpDoc;

interface StubFilesExtension
{

public const EXTENSION_TAG = 'phpstan.stubFilesExtension';

/** @return string[] */
public function getFiles(): array;

}
16 changes: 15 additions & 1 deletion src/PhpDoc/StubPhpDocProviderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\PhpDoc;

use PHPStan\DependencyInjection\Container;
use PHPStan\Parser\Parser;
use PHPStan\Type\FileTypeMapper;

Expand All @@ -12,6 +13,8 @@ class StubPhpDocProviderFactory

private \PHPStan\Type\FileTypeMapper $fileTypeMapper;

private Container $container;

/** @var string[] */
private array $stubFiles;

Expand All @@ -22,20 +25,31 @@ class StubPhpDocProviderFactory
public function __construct(
Parser $parser,
FileTypeMapper $fileTypeMapper,
Container $container,
array $stubFiles
)
{
$this->parser = $parser;
$this->fileTypeMapper = $fileTypeMapper;
$this->container = $container;
$this->stubFiles = $stubFiles;
}

public function create(): StubPhpDocProvider
{
$stubFiles = $this->stubFiles;
$extensions = $this->container->getServicesByTag(StubFilesExtension::EXTENSION_TAG);
foreach ($extensions as $extension) {
$extensionFiles = $extension->getFiles();
foreach ($extensionFiles as $extensionFile) {
$stubFiles[] = $extensionFile;
}
}

return new StubPhpDocProvider(
$this->parser,
$this->fileTypeMapper,
$this->stubFiles
$stubFiles
);
}

Expand Down

0 comments on commit 2ba9332

Please sign in to comment.