Skip to content
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

Outputting errors in stderr instead of stdout #37

Closed
kkmuffme opened this issue Apr 28, 2019 · 13 comments
Closed

Outputting errors in stderr instead of stdout #37

kkmuffme opened this issue Apr 28, 2019 · 13 comments
Assignees

Comments

@kkmuffme
Copy link

Would be great if it could output errors on stderr instead of stdout, so phpcf can be in automated deploy pipelines/CI.

e.g.
phpcf myfile >> /dev/null 2>> error.log

Additionally, having the output in json (or at least somewhat configurable) would be great too

@wapmorgan
Copy link
Owner

wapmorgan commented Apr 29, 2019

You can check for exitCode of process: if any problem found, it will be -1

@kkmuffme
Copy link
Author

Yeah but by that time it is too late if I want to echo the output to a log file, so if it contains any data the deploy/CI process will stop & output the error.

@wapmorgan
Copy link
Owner

Streaming info to stderr does not fit into phpcf interaction model. May be using xml output would be good for this. But, really, you can use exit code to stop CI process after analyzing via phpcf.

@wapmorgan wapmorgan self-assigned this Apr 30, 2019
@wapmorgan wapmorgan added the bug label Apr 30, 2019
@kkmuffme
Copy link
Author

kkmuffme commented May 2, 2019

Ok would it be possible to get a json then on stdout (like phpcs offers)?

@wapmorgan wapmorgan added enhancement and removed bug labels May 3, 2019
@wapmorgan
Copy link
Owner

Yeah, check out dev-master and use --output-json[=OUTPUT-JSON] Path to store json-file with problems found in code. option. This generates json with output like:

{
    "info_messages": [
        {
            "type": "info",
            "message": "Skipping file \/media\/wapmorgan\/HDD\/\u0414\u043e\u043a\u0443\u043c\u0435\u043d\u0442\u044b\/PhpCodeFixer\/tests\/trait.php due to file size limit."
        }
    ],
    "problems": [
        {
            "version": "5.3",
            "file": "\/5.3.php",
            "line": 3,
            "type": "ini",
            "checker": "define_syslog_variables"
        }
    ],
    "repalces_suggestions": [
        {
            "type": "function",
            "problem": "mcrypt_generic_end()",
            "replacement": "mcrypt_generic_deinit()"
        }
    ],
    "notes": [
        {
            "type": "function_usage",
            "problem": "piet() (@call_with_passing_by_reference)",
            "note": "Call with passing by reference is deprecated. Problem is \"&$hoho\""
        }
    ]
}

@kkmuffme
Copy link
Author

kkmuffme commented May 8, 2019

@wapmorgan perfect.

Can you include the file path/name in the json too?

Also there is a small spelling mistake: repalces_suggestions => replace_suggestions

@kkmuffme
Copy link
Author

kkmuffme commented May 8, 2019

@wapmorgan ah sorry, didn't see that bc it looks like version above

@wapmorgan
Copy link
Owner

Added path field to problems sections with full path to file.
Fixed typo - replace_suggestions now.

@kkmuffme
Copy link
Author

Thanks

@kkmuffme
Copy link
Author

I just tested this now and it would be nicer if:
a) the json would be single line (bc easier to process) - so just remove the new lines please
b) it would append to the file instead of overwriting it

That would make it really really easy to include in every CI/CD workflow
(but it's an amazing standalone tool already :-)

@wapmorgan
Copy link
Owner

wapmorgan commented May 12, 2019

bc easier to process

bc - is it a program? Which program does not support parsing a json with whitespaces?

it would append to the file instead of overwriting it

What do it for? This makes no sense: when you do new analyze, you need new results. Two json objects on different lines in the same file - is not valid json data.

@wapmorgan
Copy link
Owner

Now, If analyzer found any problem, phpcf returns 1 exit code. If you passed --output-json, result will be saved to this file. Then parse it and show)

Or I didn't understand use-case?

@kkmuffme
Copy link
Author

I already worked around it & got it integrated :-)

Anyway the original use case was:
a) bc I can just parse 1 line (or parse a file line by line) instead of having to parse the whole file
b) yes it would make the json invalid, however when checking many files it easier to write the whole output to the same file and then just read this file line by line (e.g. how it can be done with psalm, phpcs,...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants