Skip to content

Commit 0074062

Browse files
author
Яценко Андрей
committed
issue: html report
1 parent e675d6e commit 0074062

File tree

5 files changed

+84
-23
lines changed

5 files changed

+84
-23
lines changed

public/.gitignore

Lines changed: 0 additions & 1 deletion
This file was deleted.

src/Commands/GenerateReportCommand.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Illuminate\Console\Command;
66
use LaravelRouteCoverage\RouteCoverage;
7+
use LaravelRouteCoverage\Report\Html\Reporter as HtmlReporter;
78

89
/**
910
* Class StatusCommand
@@ -41,5 +42,6 @@ public function handle()
4142
$data,
4243
'box-double'
4344
);
45+
(new HtmlReporter(['app_path'=>app_path()]))->generate($parser);
4446
}
4547
}

src/Report/Html/Reporter.php

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,50 +2,62 @@
22

33
namespace LaravelRouteCoverage\Report\Html;
44

5-
use Hal\Application\Config\Config;
6-
use Hal\Metric\Consolidated;
7-
use Hal\Metric\Group\Group;
8-
use Hal\Metric\Metrics;
95
use LaravelRouteCoverage\RouteCoverage;
106

117
class Reporter
128
{
139
/** @var array */
1410
private $config;
15-
11+
1612
/**
1713
* @param array $config
1814
*/
1915
public function __construct(array $config)
2016
{
2117
$this->config = $config;
2218
}
23-
24-
19+
20+
2521
public function generate(RouteCoverage $result)
2622
{
27-
//;
28-
$content = '<html><head></head> <body>';
23+
$content = '<html><title>Route coverage report</title><link rel="stylesheet" href="css/style.css"><body>';
2924
$content .= '<h2>Covarage ' . $result->getCoveragePercent() . '% </h2>';
30-
25+
3126
$content .= '<table>';
3227
$content .= '<thead><td>URL</td><td>Methods</td><td>Controller</td><td>Action</td><td>Count</td></thead>';
3328
$content .= '<tbody>';
34-
foreach ($result->getRouteStatistic() as $route){
35-
$content .= '<tr>';
29+
foreach ($result->getRouteStatistic() as $route) {
30+
if ($route['count'] > 3) {
31+
$class = 'success';
32+
} elseif ($route['count'] > 0) {
33+
$class = 'warning';
34+
} else {
35+
$class = 'error';
36+
}
37+
38+
39+
$content .= '<tr class="' . $class . '">';
3640
$content .= '<td>' . $route['url'] . ' </td>';
37-
$content .= '<td>' . implode(', ', $route['methods']) . ' </td>';
41+
$content .= '<td class="methods">' . implode(', ', $route['methods']) . ' </td>';
3842
$content .= '<td>' . $route['controller'] . ' </td>';
3943
$content .= '<td>' . $route['action'] . ' </td>';
40-
$content .= '<td>' . $route['count'] . ' </td>';
44+
$content .= '<td class="count">' . $route['count'] . ' </td>';
4145
$content .= '</tr>';
4246
}
4347
$content .= '</tbody></table>';
44-
48+
4549
$content .= '</body></html>';
46-
50+
51+
if (!file_exists($this->config['app_path'] . '/../public/route-coverage')) {
52+
mkdir($this->config['app_path'] . '/../public/route-coverage', 0755);
53+
}
54+
if (!file_exists($this->config['app_path'] . '/../public/route-coverage/css')) {
55+
mkdir($this->config['app_path'] . '/../public/route-coverage/css', 0755);
56+
}
57+
copy(__DIR__ . '/../../../template/html/style.css', $this->config['app_path'] . '/../public/route-coverage/css/style.css');
58+
4759
$myFile = $this->config['app_path'] . '/../public/route-coverage/report.html';
48-
$fh = fopen($myFile, 'w');
60+
$fh = fopen($myFile, 'w');
4961
fwrite($fh, $content);
5062
fclose($fh);
5163
}

src/RouterService.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ public static function getAllUri()
1313
$clearRoutes = [];
1414
$laravelRoutes = Route::getRoutes()->getRoutes();
1515
foreach ($laravelRoutes as $route) {
16-
if (preg_match('/App\\\/', $route->action['uses'])) {
16+
if (is_string($route->action['uses']) && preg_match('/App\\\/', $route->action['uses'])) {
1717
$action = explode('@', $route->action['controller']);
1818
$clearRoutes[] = [
19-
'url'=>$route->uri,
20-
'methods'=>$route->methods,
21-
'controller'=>array_shift($action),
22-
'action'=>array_shift($action),
19+
'url' => $route->uri,
20+
'methods' => $route->methods,
21+
'controller' => array_shift($action),
22+
'action' => array_shift($action),
2323
];
2424
}
2525
}

template/html/style.css

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
html, body {
2+
width: 100%;
3+
height: 100%;
4+
font-family: -apple-system, system-ui, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
5+
font-size: 16px;
6+
background: #FFFFFF;
7+
color: #242729FF;
8+
-webkit-font-smoothing: subpixel-antialiased;
9+
padding: 20px;
10+
}
11+
12+
thead {
13+
font-weight: 700;
14+
background-color: #eeeeee;
15+
}
16+
17+
thead tr td {
18+
padding: 10px 15px;
19+
}
20+
21+
tbody tr td {
22+
padding: 10px 15px;
23+
}
24+
25+
/*tbody tr:nth-child(2n) {
26+
background: #f2f2f2;
27+
}*/
28+
29+
.methods {
30+
width: 100px;
31+
word-break: break-all;
32+
}
33+
34+
.count {
35+
text-align: center;
36+
}
37+
38+
.success {
39+
background-color: rgba(0, 128, 0, 0.1);
40+
}
41+
42+
.warning {
43+
background-color: rgba(255, 165, 0, 0.1);
44+
}
45+
46+
.error {
47+
background-color: rgba(255, 0, 0, 0.1);
48+
}

0 commit comments

Comments
 (0)