Skip to content

Commit

Permalink
Add ignore line
Browse files Browse the repository at this point in the history
  • Loading branch information
noximo committed Mar 17, 2019
1 parent 742a9ce commit 1926b40
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@
"phpstan/phpstan": "^0.11",
"nette/utils": "2.5.*",
"webmozart/path-util": "^2.3",
"thecodingmachine/safe": "^0.1.9"
"thecodingmachine/safe": "^0.1.9",
"nette/neon": "^3.0.0"
},
"license": "MIT",
"require-dev": {
Expand Down
18 changes: 14 additions & 4 deletions src/FileOutput.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
<?php

declare(strict_types=1);

namespace noximo;

use Nette\IOException;
use Nette\Neon\Neon;
use Nette\Utils\FileSystem;
use Nette\Utils\RegexpException;
use Nette\Utils\Strings;
Expand All @@ -14,16 +16,24 @@

class FileOutput implements ErrorFormatter
{
/** @var string */
public const ERROR = 'error';

/** @var string */
public const LINK = 'link';

/** @var string */
public const LINE = 'line';

/** @var string */
public const FILES = 'files';

/** @var string */
public const UNKNOWN = 'unknown';

/** @var string */
public const IGNORE = 'ignore';

/** @var string */
private $link = 'editor://open/?file=%file&line=%line';

Expand Down Expand Up @@ -51,7 +61,7 @@ public function __construct(string $outputFile, ?ErrorFormatter $defaultFormatte
$this->defaultFormatter = $defaultFormatterClass;
$cwd = \Safe\getcwd() . DIRECTORY_SEPARATOR;
try {
$outputFile = Strings::replace($outputFile, '{time}', (string)time());
$outputFile = Strings::replace($outputFile, '{time}', (string) time());
} catch (RegexpException $e) {
}

Expand Down Expand Up @@ -114,9 +124,10 @@ private function generateFile(AnalysisResult $analysisResult): void
$line = $fileSpecificError->getLine() ?? 1;
$link = strtr($this->link, ['%file' => $file, '%line' => $line]);
$output[self::FILES][$file][] = [
self::ERROR => $this->formatMessage($fileSpecificError->getMessage()),
self::ERROR => self::formatMessage($fileSpecificError->getMessage()),
self::LINK => $link,
self::LINE => $line,
self::IGNORE => Neon::encode($fileSpecificError->getMessage()),
];
}

Expand All @@ -126,13 +137,12 @@ private function generateFile(AnalysisResult $analysisResult): void
});
}
unset($file);

}

FileSystem::write($this->outputFile, $this->getTable($output));
}

private function formatMessage(string $message): string
private static function formatMessage(string $message): string
{
$words = explode(' ', $message);
$words = array_map(function ($word) {
Expand Down
5 changes: 5 additions & 0 deletions src/table.phtml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
<?php

declare(strict_types=1);

namespace noximo;
Expand Down Expand Up @@ -112,6 +113,10 @@ namespace noximo;
<?= $error[FileOutput::ERROR] ?>
</td>
</tr>
<tr>
<td></td>
<td><?= $error[FileOutput::IGNORE] ?></td>
</tr>
<?php endforeach ?>
<?php endforeach ?>
<?php endif ?>
Expand Down

0 comments on commit 1926b40

Please sign in to comment.