-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAnalyser.php
46 lines (36 loc) · 1.39 KB
/
Analyser.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
<?php
declare(strict_types=1);
namespace NamespaceProtector;
use NamespaceProtector\Result\ResultParser;
use NamespaceProtector\Common\PathInterface;
use NamespaceProtector\Result\ResultAnalyser;
use NamespaceProtector\Parser\ParserInterface;
use NamespaceProtector\Result\ResultAnalyserInterface;
use NamespaceProtector\Result\Factory\CollectionFactoryInterface;
final class Analyser
{
/** @var ParserInterface[] */
private array $parserList;
private CollectionFactoryInterface $collectedFactory;
public function __construct(
CollectionFactoryInterface $collectedFactory,
ParserInterface ...$parserList
) {
$this->parserList = $parserList;
$this->collectedFactory = $collectedFactory;
}
public function execute(PathInterface $filePath): ResultAnalyserInterface
{
$cumulativeParserResult = new ResultParser($this->collectedFactory->createEmptyMutableCollection());
$resultsParser = new ResultAnalyser($this->collectedFactory);
array_map(
fn ($currentParser) => $cumulativeParserResult->append($currentParser->parseFile($filePath)),
$this->parserList
);
array_map(
fn ($currentParser) => $resultsParser->append($currentParser),
iterator_to_array($cumulativeParserResult->getResultCollectionReadable(), true)
);
return $resultsParser;
}
}