|
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
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @author bernardosecades <[email protected]> |
|
34
|
|
|
*/ |
|
35
|
|
|
class JsonFormatter extends AbstractFormatter |
|
36
|
|
|
{ |
|
37
|
|
|
/** |
|
38
|
|
|
* @param OutputInterface $out |
|
39
|
|
|
* @param InputInterface $input |
|
40
|
|
|
* @param Package[] $packages |
|
41
|
|
|
* @return mixed |
|
42
|
|
|
*/ |
|
43
|
|
|
public function displayReport(OutputInterface $out, InputInterface $input, array $packages) |
|
44
|
|
|
{ |
|
45
|
|
|
$report = []; |
|
46
|
|
|
/** @var Package $package */ |
|
47
|
|
|
foreach ($packages as $package) { |
|
48
|
|
|
$row = [ |
|
49
|
|
|
'package' => $package->getName(), |
|
50
|
|
|
'bug' => $package->hasPackagist() ? $package->hasBug() : '-', |
|
51
|
|
|
'currentVersion' => $package->getVersion(), |
|
52
|
|
|
'enabledInPackagist' => $package->hasPackagist(), |
|
53
|
|
|
'semanticVersioning' => $package->supportSemanticVersioning(), |
|
54
|
|
|
'url' => $package->getUrl(), |
|
55
|
|
|
]; |
|
56
|
|
|
$report[] = $row; |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
$jsonReport = defined('JSON_PRETTY_PRINT') ? json_encode($report, JSON_PRETTY_PRINT) : json_encode($report); |
|
60
|
|
|
$out->writeln($jsonReport); |
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|