PHP_CodeSniffer icon indicating copy to clipboard operation
PHP_CodeSniffer copied to clipboard

add a getter for PHP_CodeSniffer\Files\File::$content

Open joachim-n opened this issue 2 months ago • 7 comments

It would be useful when debugging to have a way to dump just the PHP content of a File object, because when I dump() a file object I get screens and screens of stuff, and my IDE's debugger doesn't like long strings.

Either making protected $content readonly (if the minimum supported version of PHP allows this), or adding a getter method for it.

joachim-n avatar Nov 07 '25 12:11 joachim-n

@joachim-n Have you tried using the PHPCSDebug sniff from PHPCSDevTools ?

jrfnl avatar Nov 07 '25 12:11 jrfnl

I haven't, but what I wanted to see in this case was the exact PHP string that PHPCS is working with.

joachim-n avatar Nov 07 '25 14:11 joachim-n

I haven't, but what I wanted to see in this case was the exact PHP string that PHPCS is working with.

@joachim-n But aren't you the one feeding that string/file to PHPCS ? So how is it that that string would be unknown to you ? And what does your IDE have to do with it ? (Not trying to be difficult, just trying to understand the use case)

jrfnl avatar Nov 08 '25 02:11 jrfnl

Because the bug over in that other issue is cumulative, I can't run just a single test and know what I'm passing in.

So I'm running several tests, and in the code that's causing the problem, I want to see the PHP causing the error when the error happens. So if I dump() the PHP at the point where I pass it in, I'll get a ton of output.

I want to do:

if (thing not set that will cause an error) {
dump PHP
}

I was trying to figure out whether the problem sniff always triggers, or only triggers for certain things.

And what does your IDE have to do with it?

I use VSCode, and value strings in the debugger that are too long for the panel do not wrap. It's not possible to see the string of PHP that is in the File object.

joachim-n avatar Nov 08 '25 08:11 joachim-n

@joachim-n Hmm.. I guess I still don't understand, as, if you can add dump() statements in select places, why would you not be able to add a temporary getContent() method to the File class for your debugging session only ?

So I still don't understand why you are requesting for such a method to be added to PHPCS proper, while PHPCS doesn't need it and I can't recall anybody else ever asking for it either.

In other words, how can I justify making a change in PHPCS for something which is only needed by one person, 100% specific to their debugging set up and doesn't benefit the end-user ?

jrfnl avatar Nov 08 '25 15:11 jrfnl

I imagined it would be useful in general, but you're better placed than me to make a judgment on that, so fair enough -- feel free to close.

joachim-n avatar Nov 08 '25 15:11 joachim-n

@joachim-n I'll leave the ticket open for a little longer to see if anyone else speaks up with a use case for this, but yes, will mark it as close candidate.

jrfnl avatar Nov 09 '25 01:11 jrfnl