Skip to content

Commit

Permalink
Only analysis FileExcluder excludes stub files
Browse files Browse the repository at this point in the history
This will allow us to use ReflectionProvider in StubFilesExtension
  • Loading branch information
ondrejmirtes committed Jan 12, 2023
1 parent a2a733b commit 8ef5163
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 29 deletions.
3 changes: 1 addition & 2 deletions src/Analyser/IgnoredError.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Nette\Utils\Strings;
use PHPStan\File\FileExcluder;
use PHPStan\File\FileHelper;
use PHPStan\PhpDoc\EmptyStubFilesProvider;
use function count;
use function implode;
use function is_array;
Expand Down Expand Up @@ -60,7 +59,7 @@ public static function shouldIgnore(
return false;
}

$fileExcluder = new FileExcluder($fileHelper, new EmptyStubFilesProvider(), [$path]);
$fileExcluder = new FileExcluder($fileHelper, [$path]);
$isExcluded = $fileExcluder->isExcludedFromAnalysing($error->getFilePath());
if (!$isExcluded && $error->getTraitFilePath() !== null) {
return $fileExcluder->isExcludedFromAnalysing($error->getTraitFilePath());
Expand Down
5 changes: 1 addition & 4 deletions src/File/FileExcluder.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@

namespace PHPStan\File;

use PHPStan\PhpDoc\StubFilesProvider;
use function array_merge;
use function fnmatch;
use function in_array;
use function preg_match;
Expand Down Expand Up @@ -36,11 +34,10 @@ class FileExcluder
*/
public function __construct(
FileHelper $fileHelper,
StubFilesProvider $stubFilesProvider,
array $analyseExcludes,
)
{
foreach (array_merge($analyseExcludes, $stubFilesProvider->getStubFiles()) as $exclude) {
foreach ($analyseExcludes as $exclude) {
$len = strlen($exclude);
$trailingDirSeparator = ($len > 0 && in_array($exclude[$len - 1], ['\\', '/'], true));

Expand Down
6 changes: 4 additions & 2 deletions src/File/FileExcluderFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace PHPStan\File;

use PHPStan\PhpDoc\StubFilesProvider;
use function array_key_exists;
use function array_merge;
use function array_unique;
Expand All @@ -16,6 +17,7 @@ class FileExcluderFactory
*/
public function __construct(
private FileExcluderRawFactory $fileExcluderRawFactory,
private StubFilesProvider $stubFilesProvider,
private array $obsoleteExcludesAnalyse,
private ?array $excludePaths,
)
Expand All @@ -25,7 +27,7 @@ public function __construct(
public function createAnalyseFileExcluder(): FileExcluder
{
if ($this->excludePaths === null) {
return $this->fileExcluderRawFactory->create($this->obsoleteExcludesAnalyse);
return $this->fileExcluderRawFactory->create(array_merge($this->obsoleteExcludesAnalyse, $this->stubFilesProvider->getStubFiles()));
}

$paths = [];
Expand All @@ -36,7 +38,7 @@ public function createAnalyseFileExcluder(): FileExcluder
$paths = array_merge($paths, $this->excludePaths['analyseAndScan']);
}

return $this->fileExcluderRawFactory->create(array_values(array_unique($paths)));
return $this->fileExcluderRawFactory->create(array_merge(array_values(array_unique($paths)), $this->stubFilesProvider->getStubFiles()));
}

public function createScanFileExcluder(): FileExcluder
Expand Down
18 changes: 0 additions & 18 deletions src/PhpDoc/EmptyStubFilesProvider.php

This file was deleted.

5 changes: 2 additions & 3 deletions tests/PHPStan/File/FileExcluderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

namespace PHPStan\File;

use PHPStan\PhpDoc\EmptyStubFilesProvider;
use PHPStan\Testing\PHPStanTestCase;

class FileExcluderTest extends PHPStanTestCase
Expand All @@ -20,7 +19,7 @@ public function testFilesAreExcludedFromAnalysingOnWindows(
{
$this->skipIfNotOnWindows();

$fileExcluder = new FileExcluder($this->getFileHelper(), new EmptyStubFilesProvider(), $analyseExcludes);
$fileExcluder = new FileExcluder($this->getFileHelper(), $analyseExcludes);

$this->assertSame($isExcluded, $fileExcluder->isExcludedFromAnalysing($filePath));
}
Expand Down Expand Up @@ -128,7 +127,7 @@ public function testFilesAreExcludedFromAnalysingOnUnix(
{
$this->skipIfNotOnUnix();

$fileExcluder = new FileExcluder($this->getFileHelper(), new EmptyStubFilesProvider(), $analyseExcludes);
$fileExcluder = new FileExcluder($this->getFileHelper(), $analyseExcludes);

$this->assertSame($isExcluded, $fileExcluder->isExcludedFromAnalysing($filePath));
}
Expand Down

0 comments on commit 8ef5163

Please sign in to comment.