Completed
Pull Request — master (#27)
by Björn
01:26
created

SourceFileProcessor   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 6

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 1
cbo 6
dl 0
loc 80
ccs 0
cts 31
cp 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 13 3
A processFileList() 0 9 1
A scanFileList() 0 9 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($commitIdentifier, $include, $exclude)
70
    {
71
        $scanner = new Scanner();
72
        $this->repository->checkout($commitIdentifier . ' --');
73
        $unfiltered = $this->finder->findFromString($this->directory, $include, $exclude);
74
        $source = $this->filter->filter($unfiltered, $this->modifiedFiles);
75
        $this->scanFileList($scanner, $source);
76
        return new ProcessedFileList($unfiltered, $source, $scanner);
77
    }
78
79
    /**
80
     * @param Scanner $scanner
81
     * @param array $files
82
     */
83
    private function scanFileList(Scanner $scanner, array $files)
84
    {
85
        $progress = new ProgressBar($this->output, count($files));
86
        foreach ($files as $file) {
87
            $scanner->scan($file);
88
            $progress->advance();
89
        }
90
        $progress->clear();
91
    }
92
}