This repository was archived by the owner on Mar 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathHtmlRenderer.php
102 lines (91 loc) · 2.51 KB
/
HtmlRenderer.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<?php
namespace ComposerExtension;
use Hal\Application\Extension\Reporter\ReporterHtmlSummary;
class HtmlRenderer implements ReporterHtmlSummary {
/**
* @var \StdClass;
*/
private $datas;
/**
* HtmlRenderer constructor.
* @param \StdClass $datas
*/
public function __construct(\StdClass $datas)
{
$this->datas = $datas;
}
/**
* @inheritdoc
*/
public function getMenus()
{
// you can add one or more items to the menu
return [
'composer' => 'Composer'
];
}
/**
* @inheritdoc
*/
public function renderJs()
{
// add your Js code here
return "document.getElementById('link-composer').onclick = function() { displayTab(this, 'composer')};";
}
/**
* @inheritdoc
*/
public function renderHtml()
{
if(!$this->datas->require) {
return <<<EOT
<div class="tab" id="composer">
<div class="row">
<h3>No result</h3>
<p>
No composer.json file found
</p>
</div>
EOT;
}
$this->datas->require = (array) $this->datas->require;
$this->datas->authors= (array) $this->datas->authors;
$nb = sizeof($this->datas->require);
$html = <<<EOT
<div class="tab" id="composer">
<div class="row">
<div class="col-12">
<h3>Dependencies <small>({$nb})</small></h3>
<table class="table table-striped">
<thead>
<tr style="text-align:left;">
<th>Package</th>
<th>Required version</th>
<th>Latest version</th>
<th>License</th>
<th></th>
</tr>
</thead>
<tbody>
EOT;
foreach($this->datas->require as $package) {
$licenses = implode(',', $package->license);
$html .= "<tr>
<td><a href=\"{$package->homepage}\" target=\"_blank\">{$package->name}</a></td>
<td>{$package->required}</td>"
. ($package->latest ? "
<td>{$package->latest}</td>
<td>{$licenses}</td>
<td><small><a href=\"{$package->zip}\">download zip</a></small></td>" : "<td></td><td></td><td></td>")
. "</tr>";
}
$html .= <<<EOT
</tbody>
</table>
</div>
</div>
</div>
EOT;
return $html;
}
}