Completed
Push — develop ( a83b86...c4e2fc )
by Jorijn
05:26 queued 01:08
created

SimpleFormatter   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 41.38%

Importance

Changes 0
Metric Value
eloc 30
dl 0
loc 51
ccs 12
cts 29
cp 0.4138
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B displayResults() 0 42 8
1
<?php
2
3
namespace Jorijn\LaravelSecurityChecker\Formatter;
4
5
use Symfony\Component\Console\Output\OutputInterface;
6
7
class SimpleFormatter implements FormatterInterface
8
{
9
    /**
10
     * Displays a security report as simple plain text.
11
     *
12
     * @param OutputInterface $output
13
     * @param string          $lockFilePath    The file path to the checked lock file
14
     * @param array           $vulnerabilities An array of vulnerabilities
15
     */
16 3
    public function displayResults(OutputInterface $output, $lockFilePath, array $vulnerabilities)
17
    {
18 3
        $output->writeln(sprintf('Security Check Report: <comment>%s</>', realpath($lockFilePath)));
19
20 3
        if ($count = count($vulnerabilities)) {
21
            $status = 'CRITICAL';
22
            $style = 'error';
23
        } else {
24 3
            $status = 'OK';
25 3
            $style = 'info';
26
        }
27
28 3
        $output->writeln(sprintf(
29 3
            '<%s>[%s] %d %s known vulnerabilities</>',
30 3
            $style,
31 3
            $status,
32 3
            $count,
33 3
            1 === $count ? 'package has' : 'packages have'
34
        ));
35
36 3
        if (0 !== $count) {
37
            $output->write("\n");
38
39
            foreach ($vulnerabilities as $dependency => $issues) {
40
                $dependencyFullName = $dependency.' ('.$issues['version'].')';
41
                $output->writeln('<info>'.$dependencyFullName."\n".str_repeat(
42
                    '-',
43
                    strlen($dependencyFullName)
44
                )."</>\n");
45
46
                foreach ($issues['advisories'] as $issue => $details) {
47
                    $output->write(' * ');
48
                    if ($details['cve']) {
49
                        $output->write('<comment>'.$details['cve'].': </comment>');
50
                    }
51
                    $output->writeln($details['title']);
52
53
                    if ('' !== $details['link']) {
54
                        $output->writeln('   '.$details['link']);
55
                    }
56
57
                    $output->writeln('');
58
                }
59
            }
60
        }
61 3
    }
62
}
63