Completed
Push — master ( 0bf797...d2e254 )
by Povilas
9s
created

Printer::printData()   B

Complexity

Conditions 3
Paths 3

Size

Total Lines 24
Code Lines 17

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 24
rs 8.9713
cc 3
eloc 17
nc 3
nop 1
1
<?php
2
3
namespace Povils\PHPMND;
4
5
use JakubOnderka\PhpConsoleColor\ConsoleColor;
6
use JakubOnderka\PhpConsoleHighlighter\Highlighter;
7
use Symfony\Component\Console\Output\OutputInterface;
8
9
/**
10
 * Class Printer
11
 *
12
 * @package Povils\PHPMND
13
 */
14
class Printer
15
{
16
    const LINE_LENGTH = 80;
17
18
    /**
19
     * @var FileReport[]
20
     */
21
    private $fileReports = [];
22
23
    /**
24
     * @param FileReport $fileReport
25
     */
26
    public function addFileReport(FileReport $fileReport)
27
    {
28
        $this->fileReports[] = $fileReport;
29
    }
30
31
    /**
32
     * @param OutputInterface $output
33
     */
34
    public function printData(OutputInterface $output)
35
    {
36
        $separator = str_repeat('-', self::LINE_LENGTH);
37
        $output->writeln(PHP_EOL . $separator . PHP_EOL);
38
39
        $total = 0;
40
        foreach ($this->fileReports as $fileReport) {
41
            $entries = $fileReport->getEntries();
42
            $total += count($entries);
43
            foreach ($entries as $entry) {
44
                $output->writeln(sprintf(
45
                    '%s:%d. Magic number: %s',
46
                    $fileReport->getFile()->getRelativePathname(),
47
                    $entry['line'],
48
                    $entry['value']
49
                ));
50
51
                $highlighter = new Highlighter(new ConsoleColor());
52
                $output->writeln($highlighter->getCodeSnippet($fileReport->getFile()->getContents(), $entry['line'], 0, 0));
53
            }
54
            $output->writeln($separator . PHP_EOL);
55
        }
56
        $output->writeln('<info>Total of Magic Numbers: ' . $total . '</info>');
57
    }
58
}
59