SourceFileProcessor::__construct()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

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