Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display insight class name (#137) #139

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/Application/Console/Style.php
Expand Up @@ -230,10 +230,13 @@ public function issues(InsightCollection $insightCollection, array $metrics, str
continue;
}
$issue .= ':';
if ($this->output->isVerbose()) {
$issue .= " ({$insight->getInsightClass()})";
}
$details = $insight->getDetails();
$totalDetails = count($details);

if ($this->output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL) {
if (! $this->output->isVerbose()) {
$details = array_slice($details, -3, 3, true);
}

Expand All @@ -242,7 +245,7 @@ public function issues(InsightCollection $insightCollection, array $metrics, str
$issue .= "\n $detail";
}

if ($this->output->getVerbosity() <= OutputInterface::VERBOSITY_NORMAL && $totalDetails > 3) {
if (! $this->output->isVerbose() && $totalDetails > 3) {
$totalRemainDetails = $totalDetails - 3;

$issue .= "\n <fg=red>+{$totalRemainDetails} issues omitted</>";
Expand Down
7 changes: 7 additions & 0 deletions src/Domain/Contracts/Insight.php
Expand Up @@ -22,4 +22,11 @@ public function hasIssue(): bool;
* @return string
*/
public function getTitle(): string;

/**
* Get the class name of Insight used.
*
* @return string
*/
public function getInsightClass(): string;
}
14 changes: 14 additions & 0 deletions src/Domain/Exceptions/SniffClassNotFound.php
@@ -0,0 +1,14 @@
<?php

declare(strict_types=1);

namespace NunoMaduro\PhpInsights\Domain\Exceptions;

use RuntimeException;

/**
* @internal
*/
final class SniffClassNotFound extends RuntimeException
{
}
8 changes: 8 additions & 0 deletions src/Domain/Insights/Insight.php
Expand Up @@ -30,4 +30,12 @@ final public function __construct(Collector $collector, array $config)
$this->collector = $collector;
$this->config = $config;
}

/**
* {@inheritdoc}
*/
public function getInsightClass(): string
{
return static::class;
}
}
15 changes: 14 additions & 1 deletion src/Domain/Insights/Sniff.php
Expand Up @@ -6,6 +6,7 @@

use NunoMaduro\PhpInsights\Domain\Contracts\HasDetails;
use NunoMaduro\PhpInsights\Domain\Contracts\Insight;
use NunoMaduro\PhpInsights\Domain\Exceptions\SniffClassNotFound;
use PHP_CodeSniffer\Standards\Generic\Sniffs\PHP\ForbiddenFunctionsSniff;
use SlevomatCodingStandard\Sniffs\Classes\UnusedPrivateElementsSniff;
use SlevomatCodingStandard\Sniffs\Variables\UnusedVariableSniff;
Expand Down Expand Up @@ -57,7 +58,7 @@ public function hasIssue(): bool
*/
public function getTitle(): string
{
$sniffClass = explode('.', $this->errors[0]->getSourceClass())[0];
$sniffClass = $this->getInsightClass();

if (array_key_exists($sniffClass, self::$messages)) {
return sprintf(self::$messages[$sniffClass], count($this->errors));
Expand All @@ -80,4 +81,16 @@ public function getDetails(): array
return $error->getFileInfo()->getRealPath() . ':' . $error->getLine() . ': ' . $error->getMessage();
}, $this->errors);
}

/**
* {@inheritdoc}
*/
public function getInsightClass(): string
{
if (\count($this->errors) === 0) {
throw new SniffClassNotFound('Unable to found Sniff used');
}

return explode('.', $this->errors[0]->getSourceClass())[0];
}
}