forked from phpstan/phpstan
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Finding out which files are excluded moved to FileExcluder
- Loading branch information
1 parent
802e663
commit 9c52617
Showing
5 changed files
with
74 additions
and
42 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
<?php declare(strict_types = 1); | ||
|
||
namespace PHPStan\File; | ||
|
||
class FileExcluder | ||
{ | ||
|
||
/** | ||
* Directories to exclude from analysing | ||
* | ||
* @var string[] | ||
*/ | ||
private $analyseExcludes; | ||
|
||
public function __construct( | ||
FileHelper $fileHelper, | ||
array $analyseExcludes | ||
) | ||
{ | ||
$this->analyseExcludes = array_map(function (string $exclude) use ($fileHelper): string { | ||
$normalized = $fileHelper->normalizePath($exclude); | ||
|
||
if ($this->isFnmatchPattern($normalized)) { | ||
return $normalized; | ||
} | ||
|
||
return $fileHelper->absolutizePath($normalized); | ||
}, $analyseExcludes); | ||
} | ||
|
||
public function isExcludedFromAnalysing(string $file): bool | ||
{ | ||
foreach ($this->analyseExcludes as $exclude) { | ||
if (strpos($file, $exclude) === 0) { | ||
return true; | ||
} | ||
|
||
if ($this->isFnmatchPattern($exclude) && fnmatch($exclude, $file, DIRECTORY_SEPARATOR === '\\' ? FNM_NOESCAPE : 0)) { | ||
return true; | ||
} | ||
} | ||
|
||
return false; | ||
} | ||
|
||
private function isFnmatchPattern(string $path): bool | ||
{ | ||
return preg_match('~[*?[\]]~', $path) > 0; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters