-
-
Notifications
You must be signed in to change notification settings - Fork 19
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
[FEATURE] add codeclimate iteration zero #93
base: master
Are you sure you want to change the base?
Changes from 1 commit
2c143e9
1b25d4d
7053281
d0ae993
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<?php declare(strict_types=1); | ||
namespace Helmich\TypoScriptLint\Linter\ReportPrinter; | ||
|
||
use DOMDocument; | ||
use Helmich\TypoScriptLint\Application; | ||
use Helmich\TypoScriptLint\Linter\Report\Report; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
|
||
/** | ||
* Report printer that generates CodeClimate JSON documents [1]. | ||
* | ||
* These reports are well-suited for being used in continuous integration | ||
* environments like gitlab [2]. | ||
* | ||
* [1] https://github.com/codeclimate/spec/blob/master/SPEC.md | ||
* [2] https://docs.gitlab.com/ee/user/project/merge_requests/code_quality.html | ||
* | ||
* @package Helmich\TypoScriptLint | ||
* @subpackage Linter\ReportPrinter | ||
*/ | ||
class CodeClimateReportPrinter implements Printer | ||
{ | ||
|
||
/** @var OutputInterface */ | ||
private $output; | ||
|
||
/** | ||
* Constructs a new checkstyle report printer. | ||
* | ||
* @param OutputInterface $output Output stream to write on. Might be STDOUT or a file. | ||
*/ | ||
public function __construct(OutputInterface $output) | ||
{ | ||
$this->output = $output; | ||
} | ||
|
||
/** | ||
* Writes a report in checkstyle XML format. | ||
* | ||
* @param Report $report The report to print. | ||
* @return void | ||
*/ | ||
public function writeReport(Report $report): void | ||
{ | ||
$issues = []; | ||
|
||
foreach ($report->getFiles() as $file) { | ||
foreach ($file->getIssues() as $issue) { | ||
$issueData = [ | ||
'type' => 'issue', | ||
'check_name' => $issue->getSource(), | ||
'description' => $issue->getMessage(), | ||
'categories' => ['Style'], | ||
'location' => [ | ||
'path' => $file->getFilename(), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not entirely sure -- I think that With #91 (still work-in-progress, however), there is a utility class There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I know, can you tell me, maybe it makes sense to expose an |
||
'lines' => [ | ||
'begin' => $issue->getLine() ? ((string) $issue->getLine()) : 0 | ||
kaystrobach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
] | ||
] | ||
]; | ||
|
||
$column = $issue->getColumn(); | ||
if ($column !== null) { | ||
$issueData['location']['lines']['column'] = $column; | ||
} | ||
|
||
$issueData['fingerprint'] = $this->fingerprint($issueData); | ||
|
||
$issues[] = $issueData; | ||
} | ||
} | ||
|
||
$this->output->write(json_encode($issues)); | ||
} | ||
|
||
protected function fingerprint(array $issue) | ||
kaystrobach marked this conversation as resolved.
Show resolved
Hide resolved
|
||
{ | ||
return md5(json_encode($issue)); | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure if all checks fit into the
Style
category. For instance, theDuplicateAssignmentSniff
might also fit into theBug Risk
category.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you have a hint how to connect your issue to the categorie? From your code I have not seen an entry point to extract an issue category.