-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathFilteredExamples.php
More file actions
executable file
·46 lines (40 loc) · 1.16 KB
/
FilteredExamples.php
File metadata and controls
executable file
·46 lines (40 loc) · 1.16 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
35
36
37
38
39
40
41
42
43
44
45
46
<?php declare(strict_types=1);
namespace TH\DocTest\Iterator;
use TH\DocTest\Example;
use TH\Maybe\Option;
final class FilteredExamples implements Examples
{
public function __construct(
private readonly Examples $examples,
private readonly string $filter,
) {}
/**
* @return \Traversable<Example>
*/
public function getIterator(): \Traversable
{
foreach ($this->examples as $example) {
if (\str_contains((string) $example->location, $this->filter)) {
yield $example;
}
}
}
public static function filter(Examples $examples, string $filter): self
{
return new self($examples, $filter);
}
/**
* @param array<string> $paths paths to files and folder to look for PHP comments code examples in
* @param Option<array<string>> $languageFilter Use empty string for unspecified language
*/
public static function fromPaths(
array $paths,
string $filter,
Option $languageFilter,
): self {
return self::filter(
AllExamples::fromPaths($paths, $languageFilter),
$filter,
);
}
}