Skip to content
This repository was archived by the owner on Sep 24, 2020. It is now read-only.

Start to work on generic issue reporters#235

Open
K-Phoen wants to merge 4 commits into
ovr:masterfrom
K-Phoen:reporters
Open

Start to work on generic issue reporters#235
K-Phoen wants to merge 4 commits into
ovr:masterfrom
K-Phoen:reporters

Conversation

@K-Phoen

@K-Phoen K-Phoen commented Oct 11, 2016

Copy link
Copy Markdown
Collaborator

Hey!

Type: new feature

Link to issue:

This pull request affects the following components (please check boxes):

  • Core
  • Analyzer
  • Compiler
  • Control Flow Graph
  • Documentation

In raising this pull request, I confirm the following (please check boxes):

  • I have read and understood the Contributing Guidelines.
  • I have checked that another pull request for this purpose does not exist.
  • I wrote some tests for this PR.

Small description of change:

This PR starts to make the output generation generic. We should be able to generate several output formats depending on what the user wants (xml, json, text, …).
For now, I only introduced a generic way to transform issues to JSON/XML, other. In future commits, I'll work on a solution to combine several outputs, manage IO, etc.

Thanks

@ddmler

ddmler commented Oct 11, 2016

Copy link
Copy Markdown
Collaborator

I assigned you to issue #18 then. It's HTML output. For start it would be enough to just wrap it in some html tags, the styling can be done later

Comment thread src/Report/JsonReporter.php Outdated
@@ -0,0 +1,38 @@
<?php

namespace PHPSA\Report;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should put Report inside Analyzer directory
And seems Issue's classes to this dir

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but syntax error issues belong to compiler not analyzer

@K-Phoen

K-Phoen commented Oct 11, 2016

Copy link
Copy Markdown
Collaborator Author

@ovr, @ddmler I reworked the initial commit a bit.

This PR now introduces the notion of reporter (a class in charge of reporting issues to the user), that can use different formatters and outputs.

In order to make it work, I also had to clean a few things, hence the number of modified lines.

Comment thread src/Compiler/Expression/Assign.php Outdated
$symbol = $context->getSymbol($var->name);
if (!$symbol) {
$symbol = new \PHPSA\Variable(
$symbol = new \PhpSA\Variable(

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

even though it works I think we should stick to PHPSA all uppercase?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PHPSA should be in uppercase
Because it's abbreviation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep 👍
This modification wasn't intended.

return $output . "\n";
}

private function formatNotice(Issue $issue)

@ddmler ddmler Oct 11, 2016

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't we change that to:
Filename
line: issue 1 [checkname]
code of issue 1
line: issue 2 [checkname]
code of issue 2
next Filename
...
Also we want to add language level errors 👍

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this PR, I'll only provide the architecture to write different outputs. We'll be able to add new or update existing ones later :)

Comment thread src/Issue.php
'description' => $this->description,
'location' => $this->location->toArray(),
'categories' => $this->categories,
'blame' => $this->blame,

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not needed there, toArray is a special method for CodeClimate

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having a method that is specific for CodeClimate in a class that's not specific is a bit weird I think.

Moreover, shouldn't we implement CodeClimate as another output format?

Comment thread src/Variable.php
protected $type;

/** @var NodeAbstract The AST node where the variable is declared */
protected $declarationStmt;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not Needed

$json = json_encode($issue->toArray());

if (!$this->isFirstIssue) {
$json = ', '.$json;

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I suggest to use format as CodeClimate
echo $json . chr(0);

Comment thread src/Context.php Outdated
* @param string|null $filepath
* @return bool
*/
protected function addIssue($type, $message, $line, $filepath = null)

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IssueLocation in near feature will be different and will support blocks
and half of line

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Btw, I suggest to pass Issue, because this will be rly hard to pass 100500 parameters to customize Issue
For example cutegories, IssueLocation

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I updated the method definition to use an IssueLocation object.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@K-Phoen But how to pass category? Myabe lets use Issue?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or another way to split methods like

->styleNotice
->securityNotice
->performanceNotice

m?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep yep, done (I didn't see your previous comment before updating the code).

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The Context class already has too many methods/responsibilities. I just wanted to initiate a bit of cleaning :)

@ovr ovr Oct 12, 2016

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but anyway main question how pass categories? Lets add a parameter with default value to notice method, will be helpfull to pass normal category or categories of the Issue

And for errorLanguage lets pass Issue::CATEGORY_BUG_RISK to Issue

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done :)

@K-Phoen K-Phoen force-pushed the reporters branch 3 times, most recently from b9d125e to de8145a Compare October 12, 2016 06:39
@K-Phoen

K-Phoen commented Oct 13, 2016

Copy link
Copy Markdown
Collaborator Author

@ovr If that sounds good to you, I think that I will modify the codeclimate-related code to be just another output format. I'll create an issue for that and do it in a separate PR.

Also, I think that the Context class looks to much like a god object (it holds too much responsibilities) and that we should think about what we want to do about it. If we actually want to do something about it.

WDYT?

@ovr ovr added this to the Release 0.6.1 milestone Nov 12, 2016
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants