Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Collect and scan files included by the autoloaders (#3183)
Refs #2861
- Loading branch information
Showing
15 changed files
with
166 additions
and
75 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,55 @@ | ||
<?php | ||
|
||
namespace Psalm\Internal; | ||
|
||
use function array_diff; | ||
use function array_merge; | ||
use function array_unique; | ||
use function array_values; | ||
use function get_included_files; | ||
use function preg_grep; | ||
|
||
use const PREG_GREP_INVERT; | ||
|
||
/** | ||
* Include collector | ||
* | ||
* Used to execute code that may cause file inclusions, and report what files have been included | ||
* NOTE: dependencies of this class should be kept at minimum, as it's used before autoloader is | ||
* registered. | ||
*/ | ||
final class IncludeCollector | ||
{ | ||
/** @var list<string> */ | ||
private $included_files = []; | ||
|
||
/** | ||
* @template T | ||
* @param callable():T $f | ||
* @return T | ||
*/ | ||
public function runAndCollect(callable $f) | ||
{ | ||
$before = get_included_files(); | ||
$ret = $f(); | ||
$after = get_included_files(); | ||
|
||
$included = array_diff($after, $before); | ||
|
||
$this->included_files = array_values(array_unique(array_merge($this->included_files, $included))); | ||
|
||
return $ret; | ||
} | ||
|
||
/** @return list<string> */ | ||
public function getIncludedFiles(): array | ||
{ | ||
return $this->included_files; | ||
} | ||
|
||
/** @return list<string> */ | ||
public function getFilteredIncludedFiles(): array | ||
{ | ||
return array_values(preg_grep('@^phar://@', $this->getIncludedFiles(), PREG_GREP_INVERT)); | ||
} | ||
} |
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
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
Oops, something went wrong.