Completed
Pull Request — master (#27)
by
unknown
03:00
created

SourceFileProcessor::processFileList()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 13
ccs 0
cts 13
cp 0
rs 9.4285
cc 1
eloc 11
nc 1
nop 3
crap 2
1
<?php
2
3
namespace PHPSemVerCheckerGit;
4
5
6
use PHPSemVerChecker\Finder\Finder;
7
use PHPSemVerChecker\Scanner\Scanner;
8
use Symfony\Component\Console\Output\OutputInterface;
9
use Symfony\Component\Console\Helper\ProgressBar;
10
use PHPSemVerCheckerGit\Filter\SourceFilter;
11
use Gitter\Repository;
12
13
class SourceFileProcessor
14
{
15
    /**
16
     * @var Repository
17
     */
18
    private $repository;
19
    /**
20
     * @var OutputInterface
21
     */
22
    private $output;
23
    /**
24
     * @var Finder
25
     */
26
    private $finder;
27
    /**
28
     * @var SourceFilter
29
     */
30
    private $filter;
31
    /**
32
     * @var string
33
     */
34
    private $directory;
35
    /**
36
     * @var string[]
37
     */
38
    private $modifiedFiles;
39
40
    /**
41
     * SourceFileProcessor constructor.
42
     * @param SourceFilter &$filter
43
     * @param Repository $repository
44
     * @param OutputInterface $output
45
     * @param Finder $finder
46
     * @param string $directory
47
     * @param string[] $modifiedFiles
48
     */
49
    public function __construct(SourceFilter $filter, Repository $repository, OutputInterface $output, Finder $finder, $directory, array $modifiedFiles)
50
    {
51
        $this->repository = $repository;
52
        $this->output = $output;
53
        $this->finder = $finder;
54
        $this->filter = $filter;
55
        $this->directory = $directory;
56
        foreach($modifiedFiles as $file) {
57
            if(substr($file, -4) === '.php') {
58
                $this->modifiedFiles[] = $file;
59
            }
60
        }
61
    }
62
63
    /**
64
     * @param string $commitIdentifier
65
     * @param $include
66
     * @param $exclude
67
     * @return ProcessedFileList
68
     */
69
    public function processFileList(
70
        $commitIdentifier,
71
        $include,
72
        $exclude
73
    ) {
74
        $scanner = new Scanner();
75
        $this->repository->checkout($commitIdentifier . ' --');
76
        $source = $this->finder->findFromString($this->directory, $include, $exclude);
77
        $count = count($source);
78
        $source = $this->filter->filter($source, $this->modifiedFiles);
79
        $this->scanFileList($scanner, $source);
80
        return new ProcessedFileList($count, $source, $scanner);
81
    }
82
83
    /**
84
     * @param Scanner $scanner
85
     * @param array $files
86
     */
87
    private function scanFileList(Scanner &$scanner, array &$files)
88
    {
89
        $progress = new ProgressBar($this->output, count($files));
90
        foreach ($files as $file) {
91
            $scanner->scan($file);
92
            $progress->advance();
93
        }
94
        $progress->clear();
95
    }
96
97
}