-
-
Notifications
You must be signed in to change notification settings - Fork 283
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
2,282 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace NunoMaduro\PhpInsights\Application\Console\Formatters; | ||
|
||
use Exception; | ||
use NunoMaduro\PhpInsights\Application\Console\Contracts\Formatter; | ||
use NunoMaduro\PhpInsights\Domain\Insights\InsightCollection; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Twig\Environment as Twig; | ||
use Twig\Loader\FilesystemLoader; | ||
use Twig\TwigFilter; | ||
|
||
/** | ||
* @internal | ||
*/ | ||
final class Html implements Formatter | ||
{ | ||
/** @var OutputInterface */ | ||
private $output; | ||
|
||
public function __construct(InputInterface $input, OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Format the result to the desired format. | ||
* | ||
* @param InsightCollection $insightCollection | ||
* @param string $dir | ||
* @param array<string> $metrics | ||
* | ||
* @throws Exception | ||
*/ | ||
public function format( | ||
InsightCollection $insightCollection, | ||
string $dir, | ||
array $metrics | ||
): void { | ||
$this->output->write($this->getTwig()->render('dashboard.html.twig', [ | ||
'dir' => $dir, | ||
'results' => $insightCollection->results(), | ||
'insights' => $insightCollection, | ||
]), false, OutputInterface::OUTPUT_RAW); | ||
} | ||
|
||
private function getTwig(): Twig | ||
{ | ||
$loader = new FilesystemLoader(__DIR__.'/../../../../views'); | ||
$twig = new Twig($loader, [ | ||
'cache' => false, | ||
'debug' => true, | ||
]); | ||
|
||
$twig->addFilter(new TwigFilter('sluggify', static function (string $slug): string { | ||
$slug = preg_replace('/<(.*?)>/u', '', (string) $slug); | ||
$slug = preg_replace('/[\'"‘’“”]/u', '', (string) $slug); | ||
$slug = mb_strtolower((string) $slug, 'UTF-8'); | ||
|
||
preg_match_all('/[\p{L}\p{N}\.]+/u', (string) $slug, $words); | ||
|
||
return implode('-', array_filter($words[0])); | ||
})); | ||
|
||
return $twig; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
<!doctype html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="utf-8"> | ||
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> | ||
|
||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/css/bootstrap.min.css" integrity="sha256-YLGeXaapI0/5IgZopewRJcFXomhRMlYYjugPLSyNjTY=" crossorigin="anonymous" /> | ||
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.10.2/css/all.min.css" integrity="sha256-zmfNZmXoNWBMemUOo1XUGFfc0ihGGLYdgtJS3KCr/l0=" crossorigin="anonymous" /> | ||
|
||
<title>PHP Insights</title> | ||
</head> | ||
<body> | ||
<div class="container-fluid"> | ||
|
||
<h1>PHP Insights</h1> | ||
|
||
<p> | ||
<time datetime="{{ 'now'|date('Y-m-d H:i:s') }}">{{ 'now'|date('Y-m-d') }}</time> | ||
<code>{{ dir }}</code> | ||
</p> | ||
|
||
<div class="row"> | ||
<div class="col">{% include 'partials/stats_per_metric.html.twig' with {'id': 'quality', 'title': 'code quality', 'score': results.codeQuality} %}</div> | ||
<div class="col">{% include 'partials/stats_per_metric.html.twig' with {'id': 'complexity', 'title': 'complexity', 'score': results.complexity} %}</div> | ||
<div class="col">{% include 'partials/stats_per_metric.html.twig' with {'id': 'structure', 'title': 'structure', 'score': results.structure} %}</div> | ||
<div class="col">{% include 'partials/stats_per_metric.html.twig' with {'id': 'style', 'title': 'style', 'score': results.style} %}</div> | ||
</div> | ||
|
||
<div class="alert alert-light"> | ||
score scale: | ||
<span class="text-danger">■</span> 1 - 49 | ||
<span class="text-warning">■</span> 50 - 79 | ||
<span class="text-success">■</span> 80 - 100 | ||
</div> | ||
|
||
{% include 'partials/insights_per_metric.html.twig' with {'id': 'quality', 'title': 'code quality', 'metricNamespacePart': '\\Code\\'} %} | ||
{% include 'partials/insights_per_metric.html.twig' with {'id': 'complexity', 'title': 'complexity', 'metricNamespacePart': '\\Complexity\\'} %} | ||
{% include 'partials/insights_per_metric.html.twig' with {'id': 'structure', 'title': 'structure', 'metricNamespacePart': '\\Architecture\\'} %} | ||
{% include 'partials/insights_per_metric.html.twig' with {'id': 'style', 'title': 'style', 'metricNamespacePart': '\\Style\\'} %} | ||
|
||
</div> | ||
|
||
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script> | ||
<script src="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.3.1/js/bootstrap.bundle.min.js" integrity="sha256-fzFFyH01cBVPYzl16KT40wqjhgPtq6FFUB6ckN2+GGw=" crossorigin="anonymous"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<h2 id="{{ id }}">{{ title }}</h2> | ||
<div class="list-group mb-3"> | ||
{% for metric, insightsPerMetric in insights.insightsPerMetric %} | ||
{% if metricNamespacePart in metric %} | ||
{% for insight in insightsPerMetric %} | ||
{% if insight.hasIssue() %} | ||
<div class="list-group-item"> | ||
<div class="clearfix" data-toggle="collapse" href="#code-{{ insight.insightClass|sluggify }}" > | ||
<i class="fas text-danger fa-times"></i> | ||
<strong>{{ insight.title }}</strong> | ||
<span class="text-muted">({{ insight.details|length }})</span> | ||
<code class="float-right">{{ insight.insightClass }}</code> | ||
</div> | ||
<div class="collapse" id="code-{{ insight.insightClass|sluggify }}"> | ||
<ul> | ||
{% for detail in insight.details %} | ||
<li> | ||
{% if detail.hasFile() %} | ||
<code> | ||
{{ detail.file }}{% if detail.hasLine() %}:{{ detail.line }}{% endif %}{% if detail.hasFunction() %}:{{ detail.function }}{% endif %} | ||
</code> | ||
{% endif %} | ||
{% if detail.hasMessage() %} | ||
<span>{{ detail.message }}</span> | ||
{% endif %} | ||
</li> | ||
{% endfor %} | ||
</ul> | ||
</div> | ||
</div> | ||
{% endif %} | ||
{% endfor %} | ||
{% endif %} | ||
{% endfor %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<div class="alert text-center alert-{{ score >= 80 ? 'success' : (score >= 50 ? 'warning' : 'danger') }}"> | ||
<strong>{{ title }}</strong> | ||
<a href="#{{ id }}" class="alert-link"><i class="fas fa-anchor"></i></a> | ||
<div class="lead">{{ score|number_format(1, '.') }} %</div> | ||
</div> |