Total Complexity | 9 |
Total Lines | 62 |
Duplicated Lines | 0 % |
Changes | 2 | ||
Bugs | 1 | Features | 0 |
1 | <?php |
||
7 | final class FileStreamCollector implements CollectorInterface, IndexCollectorInterface |
||
8 | { |
||
9 | use CollectorTrait; |
||
10 | |||
11 | public function __construct(private array $ignoredPathPatterns = [], private array $ignoredClasses = []) |
||
12 | { |
||
13 | } |
||
14 | |||
15 | private array $requests = []; |
||
16 | |||
17 | public function getCollected(): array |
||
18 | { |
||
19 | return $this->requests; |
||
20 | } |
||
21 | |||
22 | public function startup(): void |
||
23 | { |
||
24 | $this->isActive = true; |
||
25 | FileStreamProxy::register(); |
||
26 | FileStreamProxy::$collector = $this; |
||
27 | FileStreamProxy::$ignoredPathPatterns = $this->ignoredPathPatterns; |
||
28 | FileStreamProxy::$ignoredClasses = $this->ignoredClasses; |
||
29 | } |
||
30 | |||
31 | public function shutdown(): void |
||
32 | { |
||
33 | FileStreamProxy::unregister(); |
||
34 | FileStreamProxy::$collector = null; |
||
35 | FileStreamProxy::$ignoredPathPatterns = []; |
||
36 | FileStreamProxy::$ignoredClasses = []; |
||
37 | |||
38 | $this->reset(); |
||
39 | $this->isActive = false; |
||
40 | } |
||
41 | |||
42 | public function collect(string $operation, string $path, array $args): void |
||
43 | { |
||
44 | if (!$this->isActive()) { |
||
45 | return; |
||
46 | } |
||
47 | |||
48 | $this->requests[$operation][] = [ |
||
49 | 'path' => $path, |
||
50 | 'args' => $args, |
||
51 | ]; |
||
52 | } |
||
53 | |||
54 | public function getIndexData(): array |
||
55 | { |
||
56 | return [ |
||
57 | 'file' => array_merge( |
||
58 | ...array_map( |
||
59 | fn (string $operation) => [$operation => is_countable($this->requests[$operation]) ? count($this->requests[$operation]) : 0], |
||
60 | array_keys($this->requests) |
||
61 | ) |
||
62 | ), |
||
63 | ]; |
||
64 | } |
||
65 | |||
66 | private function reset(): void |
||
69 | } |
||
70 | } |
||
71 |