Test Failed
Push — master ( 36eeda...83b81c )
by BruceScrutinizer
08:00
created

Analyser::convertReadOnlyCollectionToEditableCollection()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 4
nc 2
nop 1
dl 0
loc 9
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace NamespaceProtector;
6
7
use NamespaceProtector\Result\ResultParser;
8
use NamespaceProtector\Common\PathInterface;
9
use NamespaceProtector\Result\ResultAnalyser;
10
use NamespaceProtector\Parser\ParserInterface;
11
use NamespaceProtector\Result\ResultAnalyserInterface;
12
use NamespaceProtector\Result\Factory\CollectionFactoryInterface;
13
14
final class Analyser
15
{
16
    /** @var ParserInterface[]  */
17
    private $parserList;
18
19
    /** @var CollectionFactoryInterface */
20
    private $collectedFactory;
21
22
    public function __construct(
23
        CollectionFactoryInterface $collectedFactory,
24
        ParserInterface ...$parserList
25
    ) {
26
        $this->parserList = $parserList;
27
        $this->collectedFactory = $collectedFactory;
28
    }
29
30
    public function execute(PathInterface $filePath): ResultAnalyserInterface
31
    {
32
        $cumulativeParserResult = new ResultParser($this->collectedFactory->createEmptyMutableCollection());
33
34
        foreach ($this->parserList as $currentParser) {
35
            $resultOfcurrentParsedFile = $currentParser->parseFile($filePath);
36
            $cumulativeParserResult->append($resultOfcurrentParsedFile);
37
        }
38
39
        $resultsParser = new ResultAnalyser($this->collectedFactory);
40
41
        /**
42
         * @var \NamespaceProtector\Result\ResultProcessedFileInterface $currentParserResult
43
         */
44
        foreach ($cumulativeParserResult->getResultCollectionReadable() as $currentParserResult) {
45
            $resultsParser->append($currentParserResult);
46
        }
47
48
        return $resultsParser;
49
    }
50
}
51