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

Start to work on generic issue reporters #235

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

K-Phoen
Copy link
Collaborator

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

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
Copy link
Collaborator

ddmler commented Oct 11, 2016

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

@@ -0,0 +1,38 @@
<?php

namespace PHPSA\Report;
Copy link
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
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
Copy link
Collaborator Author

K-Phoen commented Oct 11, 2016

@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.

continue;
}

$symbol = $context->getSymbol($var->name);
if (!$symbol) {
$symbol = new \PHPSA\Variable(
$symbol = new \PhpSA\Variable(
Copy link
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
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
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)
Copy link
Collaborator

@ddmler ddmler Oct 11, 2016

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
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 :)

@@ -130,6 +132,7 @@ public function toArray()
'description' => $this->description,
'location' => $this->location->toArray(),
'categories' => $this->categories,
'blame' => $this->blame,
Copy link
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
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?

@@ -59,17 +60,22 @@ class Variable
*/
protected $type;

/** @var NodeAbstract The AST node where the variable is declared */
protected $declarationStmt;
Copy link
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
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);

src/Context.php Outdated
* @param string|null $filepath
* @return bool
*/
protected function addIssue($type, $message, $line, $filepath = null)
Copy link
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
Owner

Choose a reason for hiding this comment

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

Copy link
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
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
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
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
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
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 :)

Copy link
Owner

@ovr ovr Oct 12, 2016

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
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
Copy link
Collaborator Author

K-Phoen commented Oct 13, 2016

@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.

None yet

3 participants