-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathextension.php
More file actions
34 lines (28 loc) · 1.41 KB
/
extension.php
File metadata and controls
34 lines (28 loc) · 1.41 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
return $GLOBALS['andersundsehr/phpstan-git-files.memory-cache'] ??= (function (): array {
$exec = fn(string $command): array => array_filter(explode("\n", (string)shell_exec($command)));
$command = <<<BASH
git ls-files | xargs ls -d 2>/dev/null | grep '\.php$' | awk -v cwd="$(pwd)" '{print cwd "/" $0}'
BASH;
$absoluteFiles = $exec($command);
// sort paths by amount of slashes high count first
usort($absoluteFiles, static fn(string $a, string $b): int => substr_count($b, '/') <=> substr_count($a, '/'));
$deepestDirectory = dirname($absoluteFiles[0]) . '/';
//filter all files in that directory
$absoluteFiles = array_filter($absoluteFiles, static fn(string $path): bool => !str_starts_with($path, $deepestDirectory));
// add directory, We add this so the cache is not ignored. see https://github.com/andersundsehr/phpstan-git-files/issues/3
array_unshift($absoluteFiles, $deepestDirectory);
# use git root if phpstan is installed/run in a subdirectory
$command = <<<BASH
git status --ignored --porcelain {$deepestDirectory} | grep '^!!' | awk -v prefix="$(git rev-parse --show-toplevel)" '{print prefix "/" $2}'
BASH;
$absoluteIgnoredFiles = $exec($command);
return [
'parameters' => [
'paths' => $absoluteFiles,
'excludePaths' => [
'analyse' => $absoluteIgnoredFiles,
],
],
];
})();