Completed
Push — master ( 132a7c...1cf077 )
by Povilas
02:35 queued 01:04
created

Console   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 7

Importance

Changes 0
Metric Value
wmc 6
c 0
b 0
f 0
lcom 0
cbo 7
dl 0
loc 46
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B printData() 0 37 6
1
<?php
2
3
namespace Povils\PHPMND\Printer;
4
5
use JakubOnderka\PhpConsoleColor\ConsoleColor;
6
use JakubOnderka\PhpConsoleHighlighter\Highlighter;
7
use Povils\PHPMND\FileReportList;
8
use Povils\PHPMND\HintList;
9
use Symfony\Component\Console\Output\OutputInterface;
10
11
/**
12
 * Class Console
13
 *
14
 * @package Povils\PHPMND\Printer
15
 */
16
class Console implements Printer
17
{
18
    const LINE_LENGTH = 80;
19
    const TAB = 4;
20
21
    /**
22
     * {@inheritDoc}
23
     */
24
    public function printData(OutputInterface $output, FileReportList $fileReportList, HintList $hintList)
25
    {
26
        $separator = str_repeat('-', self::LINE_LENGTH);
27
        $output->writeln(PHP_EOL . $separator . PHP_EOL);
28
29
        $total = 0;
30
        foreach ($fileReportList->getFileReports() as $fileReport) {
31
            $entries = $fileReport->getEntries();
32
            $total += count($entries);
33
            foreach ($entries as $entry) {
34
                $output->writeln(sprintf(
35
                    '%s:%d. Magic number: %s',
36
                    $fileReport->getFile()->getRelativePathname(),
37
                    $entry['line'],
38
                    $entry['value']
39
                ));
40
41
                $highlighter = new Highlighter(new ConsoleColor());
42
                $output->writeln(
43
                    $highlighter->getCodeSnippet($fileReport->getFile()->getContents(), $entry['line'], 0, 0)
44
                );
45
46
                if ($hintList->hasHints()) {
47
                    $hints = $hintList->getHintsByValue($entry['value']);
48
                    if (false === empty($hints)) {
49
                        $output->writeln('Suggestions:');
50
                        foreach ($hints as $hint) {
51
                            $output->writeln(str_repeat(' ', 2 * self::TAB) . $hint);
52
                        }
53
                        $output->write(PHP_EOL);
54
                    }
55
                }
56
            }
57
            $output->writeln($separator . PHP_EOL);
58
        }
59
        $output->writeln('<info>Total of Magic Numbers: ' . $total . '</info>');
60
    }
61
}
62