People may want to see the results from PHP Insights within a beautiful html page, or may want to check the results using the json format.
All the classes from PHP Insights are internal, so we are able to refactor without making a breaking change.
I would be satisfied with a simple TXT file listing all of the problems
JSON or any structured format would be appreciated so we can hook up test results to slack/any other post CI integration with notifications to moan at someone for degrading scores.
I personally do not like the implementation done in some of the symfony commands, for example, in lint:twig, the command itself has methods to displayTxt and displayJson.
I do not know how's the internal structure, if the current implementation is coupled with the console, but hopefully there is an abstraction layer, is that the case? If so, we only need to create classes that will generate the output for a specific format, ex: TxtFormatter, XmlFormatter, and accept the internal structure as input. In the command itself, it will just determine which formatter to use based on the optional argument --format.
I like the idea of optional --html or --json flags. But I think definitely, I'd like to see the total summarized at the end of the report. Meaning, you see the "+x issues omitted", just total all of the items in the category and show that total at the end
Code: 2 issues
Complexity: 400 issues
Architecture: 345 issues
Style: 5000 issues
As a workaround just pipe the output of the script to a log file, tail the file in another terminal, then hit enter a few times where you ran the command. worked great for me!
@karljakober I normally run php vendor/bin/phpinsights -n 2> /dev/null so it does not paginate and hides the progress bar, but the output is not easily parsable, so that's why being able to dump json or xml would be great.
an option for Checkstyle xml would be awsome
till we have it as a nice parameter, i hacked a quick text-to-xml parser together:
https://gist.github.com/nuernbergerA/b75c2cb2c80747fdf2e19e4bcfe00202
php artisan insights --no-interaction -v | php /path/to/parse_phpinsights.php > checkstyle-result.xml
@nunomaduro any idea how to implement (structure) different formats?
Not yet, I am open for ideas.
How about something like this for JSON?
[
"summary" : {
"code" : 42,
"complexity" : 42,
"architecture" : 42,
"style" : 42
},
"code" : [
{
"file" : "/src/path/file.php",
"line" : 42,
"type" : "error" // use standard warning levels to indicate severity,
"msg" : "Invalid stuff",
// I don't know if there is anything else that you have access to that might be helpful
},
{
}
],
"complexity" : [
// use similar structure as code but with any special details
],
"architecture" : [
],
"style" : [
]
]
How about an --format=checkstyle and --file=checkstyle-result.xml.
Without --file it will echo to stdout.
Other formats cold be
We can put each formater in a formaters directory.
All formaters implement an interface.
Naming decisions have to been made.
Possible names are:
Yes, let's go for format, and a interface called format.
There's no need for having our own Output interface, as we can just use Symfonys interface for that.
Just added support for json formatting in my PR. Feel free to check it out and see if the output satisfies the need.
Any chance of this being available sooner?
This would be very helpful!
Out of curiosity, what do you guys need the functionality for?
The pr we have open adds a Json format that we created ourself.
I will check this pr, next week. Promise. 馃憤馃徎
Pull request has been merged. Working on the release during today/tomorrow.
Most helpful comment
How about something like this for JSON?