-
-
Notifications
You must be signed in to change notification settings - Fork 377
/
Copy pathFilter.php
93 lines (79 loc) · 2.22 KB
/
Filter.php
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
<?php declare(strict_types=1);
/*
* This file is part of phpunit/php-code-coverage.
*
* (c) Sebastian Bergmann <sebastian@phpunit.de>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace SebastianBergmann\CodeCoverage;
use function array_keys;
use function is_file;
use function realpath;
use function str_contains;
use function str_starts_with;
final class Filter
{
/**
* @var array<string,true>
*/
private array $files = [];
/**
* @var array<string,bool>
*/
private array $isFileCache = [];
/**
* @param list<string> $filenames
*/
public function includeFiles(array $filenames): void
{
foreach ($filenames as $filename) {
$this->includeFile($filename);
}
}
public function includeFile(string $filename): void
{
$filename = realpath($filename);
if (!$filename) {
return;
}
$this->files[$filename] = true;
}
public function isFile(string $filename): bool
{
if (isset($this->isFileCache[$filename])) {
return $this->isFileCache[$filename];
}
if ($filename === '-' ||
str_starts_with($filename, 'vfs://') ||
str_contains($filename, 'xdebug://debug-eval') ||
str_contains($filename, 'eval()\'d code') ||
str_contains($filename, 'runtime-created function') ||
str_contains($filename, 'runkit created function') ||
str_contains($filename, 'assert code') ||
str_contains($filename, 'regexp code') ||
str_contains($filename, 'Standard input code')) {
$isFile = false;
} else {
$isFile = is_file($filename);
}
$this->isFileCache[$filename] = $isFile;
return $isFile;
}
public function isExcluded(string $filename): bool
{
return !isset($this->files[$filename]) || !$this->isFile($filename);
}
/**
* @return list<string>
*/
public function files(): array
{
return array_keys($this->files);
}
public function isEmpty(): bool
{
return $this->files === [];
}
}