1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace MagentoHackathon; |
4
|
|
|
|
5
|
|
|
use MagentoHackathon\Model\FileList; |
6
|
|
|
use Symfony\Component\Finder\Finder; |
7
|
|
|
|
8
|
|
|
class FileCollector |
9
|
|
|
{ |
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* @var array |
13
|
|
|
*/ |
14
|
|
|
private $includeNameList = []; |
15
|
|
|
|
16
|
|
|
/** |
17
|
|
|
* @var array |
18
|
|
|
*/ |
19
|
|
|
private $patternForExclude = []; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var Finder |
23
|
|
|
*/ |
24
|
|
|
private $finder; |
25
|
|
|
/** |
26
|
|
|
* @var FileList |
27
|
|
|
*/ |
28
|
|
|
private $fileList; |
29
|
|
|
|
30
|
|
|
/** |
31
|
|
|
* @param Finder $finder |
32
|
|
|
* @param FileList $fileList |
33
|
|
|
* @param array|null $includeNameList |
34
|
|
|
* @param array|null $patternForExclude |
35
|
|
|
*/ |
36
|
|
|
public function __construct( |
37
|
|
|
Finder $finder, |
38
|
|
|
FileList $fileList, |
39
|
|
|
array $includeNameList = null, |
40
|
|
|
$patternForExclude = null |
41
|
|
|
) { |
42
|
|
|
$this->finder = $finder; |
43
|
|
|
$this->fileList = $fileList; |
44
|
|
|
|
45
|
|
|
if ($includeNameList === null) { |
46
|
|
|
$includeNameList = ['*.php', 'composer.json', '*.xml', '*.phtml']; |
47
|
|
|
} |
48
|
|
|
$this->includeNameList = $includeNameList; |
49
|
|
|
|
50
|
|
|
if ($patternForExclude === null) { |
51
|
|
|
$patternForExclude = ['*Test.php']; |
52
|
|
|
} |
53
|
|
|
$this->patternForExclude = $patternForExclude; |
54
|
|
|
} |
55
|
|
|
|
56
|
|
|
/** |
57
|
|
|
* Return Files that are relevant for decency's. |
58
|
|
|
* @param string $folder |
59
|
|
|
* @return FileList |
60
|
|
|
*/ |
61
|
|
|
public function getRelevantFiles(string $folder): FileList |
62
|
|
|
{ |
63
|
|
|
// build the finder and file types for include |
64
|
|
|
$finder = $this->finder; |
65
|
|
|
$finder = $finder->files(); |
66
|
|
|
$finder->in($folder); |
67
|
|
|
|
68
|
|
|
foreach ($this->includeNameList as $name) { |
69
|
|
|
$finder->name($name); |
70
|
|
|
} |
71
|
|
|
|
72
|
|
|
foreach ($this->patternForExclude as $notName) { |
73
|
|
|
$finder->notName($notName); |
74
|
|
|
} |
75
|
|
|
|
76
|
|
|
foreach ($finder->getIterator() as $file) { |
77
|
|
|
$this->fileList->addEntry($file); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
return $this->fileList; |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
|