1 | <?php declare(strict_types = 1); |
||
11 | class FileManager |
||
12 | { |
||
13 | /** |
||
14 | * Collection of File objects. |
||
15 | * @var FileCollection; |
||
16 | */ |
||
17 | private $files; |
||
18 | |||
19 | /** |
||
20 | * List of file extensions to look for. |
||
21 | * @var array |
||
22 | */ |
||
23 | private $fileExtensions; |
||
24 | |||
25 | /** |
||
26 | * List of files to ignore. |
||
27 | * @var array |
||
28 | */ |
||
29 | private $filesToIgnore; |
||
30 | |||
31 | /** |
||
32 | * FileManager constructor. |
||
33 | * @param array $fileExtensions List of file extensions to look for. |
||
34 | * @param array $filesToIgnore List of files to ignore. |
||
35 | */ |
||
36 | public function __construct(array $fileExtensions, array $filesToIgnore) |
||
41 | |||
42 | /** |
||
43 | * Recursively finds all files with the .php extension in the provided |
||
44 | * $paths and returns list as array. |
||
45 | * @param array $paths Paths in which to look for .php files. |
||
46 | * @return FileCollection |
||
47 | */ |
||
48 | public function getPhpFiles(array $paths): FileCollection |
||
57 | |||
58 | /** |
||
59 | * Recursively finds all files with the .php extension in the provided |
||
60 | * $path adds them to $this->files. |
||
61 | * @param string $path Path in which to look for .php files. |
||
62 | * @return void |
||
63 | */ |
||
64 | private function getPhpFilesFromPath(string $path): void |
||
71 | |||
72 | /** |
||
73 | * Collects file information unless it should be ignored. |
||
74 | * @param SplFileInfo $file The file information. |
||
75 | * @return void |
||
76 | */ |
||
77 | private function collectFile(SplFileInfo $file): void |
||
89 | |||
90 | /** |
||
91 | * Determines if a file should be ignored. |
||
92 | * @param \SplFileInfo $file File. |
||
93 | * @return boolean |
||
94 | */ |
||
95 | private function fileShouldBeIgnored(SplFileInfo $file): bool |
||
107 | |||
108 | /** |
||
109 | * Translate file path pattern to regex string. |
||
110 | * @param string $filePattern File pattern to be ignored. |
||
111 | * @return string |
||
112 | */ |
||
113 | private function patternToRegex(string $filePattern): string |
||
118 | } |
||
119 |