SimpleFormatter   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 51
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 30
c 1
b 0
f 0
dl 0
loc 51
ccs 29
cts 29
cp 1
rs 10
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 6
    public function displayResults(OutputInterface $output, $lockFilePath, array $vulnerabilities)
17
    {
18 6
        $output->writeln(sprintf('Security Check Report: <comment>%s</>', realpath($lockFilePath)));
19
20 6
        if ($count = count($vulnerabilities)) {
21 3
            $status = 'CRITICAL';
22 3
            $style = 'error';
23
        } else {
24 3
            $status = 'OK';
25 3
            $style = 'info';
26
        }
27
28 6
        $output->writeln(sprintf(
29 6
            '<%s>[%s] %d %s known vulnerabilities</>',
30 2
            $style,
31 2
            $status,
32 2
            $count,
33 6
            1 === $count ? 'package has' : 'packages have'
34
        ));
35
36 6
        if (0 !== $count) {
37 3
            $output->write("\n");
38
39 3
            foreach ($vulnerabilities as $dependency => $issues) {
40 3
                $dependencyFullName = $dependency.' ('.$issues['version'].')';
41 3
                $output->writeln('<info>'.$dependencyFullName."\n".str_repeat(
42 3
                    '-',
43 3
                    strlen($dependencyFullName)
44 3
                )."</>\n");
45
46 3
                foreach ($issues['advisories'] as $issue => $details) {
47 3
                    $output->write(' * ');
48 3
                    if ($details['cve']) {
49 3
                        $output->write('<comment>'.$details['cve'].': </comment>');
50
                    }
51 3
                    $output->writeln($details['title']);
52
53 3
                    if ('' !== $details['link']) {
54 3
                        $output->writeln('   '.$details['link']);
55
                    }
56
57 3
                    $output->writeln('');
58
                }
59
            }
60
        }
61 6
    }
62
}
63