1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* MIT License |
5
|
|
|
* |
6
|
|
|
* Copyright (c) 2016 Bernardo Secades |
7
|
|
|
* |
8
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy |
9
|
|
|
* of this software and associated documentation files (the "Software"), to deal |
10
|
|
|
* in the Software without restriction, including without limitation the rights |
11
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12
|
|
|
* copies of the Software, and to permit persons to whom the Software is |
13
|
|
|
* furnished to do so, subject to the following conditions: |
14
|
|
|
* |
15
|
|
|
* The above copyright notice and this permission notice shall be included in all |
16
|
|
|
* copies or substantial portions of the Software. |
17
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
18
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
19
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
20
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
21
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
22
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
23
|
|
|
* SOFTWARE. |
24
|
|
|
*/ |
25
|
|
|
|
26
|
|
|
namespace BernardoSecades\Packagist\SecurityChecker\Formatter; |
27
|
|
|
|
28
|
|
|
use BernardoSecades\Packagist\SecurityChecker\ValueObject\Package; |
29
|
|
|
use Symfony\Component\Console\Output\OutputInterface; |
30
|
|
|
use Symfony\Component\Console\Input\InputInterface; |
31
|
|
|
use Symfony\Component\Console\Helper\Table; |
32
|
|
|
|
33
|
|
|
/** |
34
|
|
|
* @author bernardosecades <[email protected]> |
35
|
|
|
*/ |
36
|
|
|
class TextFormatter extends AbstractFormatter |
37
|
|
|
{ |
38
|
|
|
/** |
39
|
|
|
* @param OutputInterface $out |
40
|
|
|
* @param InputInterface $input |
41
|
|
|
* @param Package[] $packages |
42
|
|
|
* @return mixed |
43
|
|
|
*/ |
44
|
|
|
public function displayReport(OutputInterface $out, InputInterface $input, array $packages) |
45
|
|
|
{ |
46
|
|
|
$out->writeln("\n<fg=black;bg=cyan>Packagist Security Checker - Report</>\n"); |
47
|
|
|
|
48
|
|
|
$totalBugs = 0; |
49
|
|
|
$report = []; |
50
|
|
|
/** @var Package $package */ |
51
|
|
|
foreach ($packages as $package) { |
52
|
|
|
if (!$package->hasPackagist()) { |
53
|
|
|
$bugColumn = '<comment>-</comment>'; |
54
|
|
|
} elseif ($package->hasBug()) { |
55
|
|
|
$totalBugs++; |
56
|
|
|
$bugColumn = '<error>Yes</error>'; |
57
|
|
|
} else { |
58
|
|
|
$bugColumn = '<info>No</info>'; |
59
|
|
|
} |
60
|
|
|
$row = [ |
61
|
|
|
$package->getName(), |
62
|
|
|
$bugColumn, |
63
|
|
|
$package->getVersion(), |
64
|
|
|
$package->hasPackagist() ? '<info>Yes</info>' : '<error>No</error>', |
65
|
|
|
$package->supportSemanticVersioning() ? '<info>Yes</info>' : '<error>No</error>', |
66
|
|
|
$package->getUrl(), |
67
|
|
|
]; |
68
|
|
|
$report[] = $row; |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
if ($totalBugs > 0) { |
72
|
|
|
$table = new Table($out); |
73
|
|
|
$table |
74
|
|
|
->setHeaders(['Package', 'Bugs', 'Current Version', 'Enabled in Packagist', 'Semantic Versioning', 'Url']) |
75
|
|
|
->setRows($report) |
76
|
|
|
->render(); |
77
|
|
|
$out->writeln(sprintf('<error>You have %d possible bugs, you should update those dependencies if affect your project</error>', $totalBugs)); |
78
|
|
|
$out->writeln('<comment>Example, if your current version is X.Y.Z, you should update at least to X.Y.(MAX-PATCH-VERSION)</comment>'); |
79
|
|
|
} else { |
80
|
|
|
$out->writeln('<info>Congratulations, you do not have bugs</info>'); |
81
|
|
|
} |
82
|
|
|
} |
83
|
|
|
} |
84
|
|
|
|