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

Unexpected WordPress.WP.AlternativeFunctions.file_system_read_fopen warning #1173

Closed
paulschreiber opened this issue Sep 28, 2017 · 3 comments
Milestone

Comments

@paulschreiber
Copy link
Contributor

[PHPCS 3.1, WPCS 0.13.1, PHP 5.6.30]

I'm using fopen() with a stream, and WPCS is now flagging this as filesystem usage:

<?php
Header( 'HTTP/1.1 200 OK' );
Header( 'Content-Type: text/csv' );
Header( "Content-Disposition: attachment; filename={$filename}" );

$output_stream = fopen( 'php://output', 'w' );

fputcsv( $output_stream, $output_columns );
foreach ( self::$metadata as $row ) {
	fputcsv( $output_stream, $row );
}

fclose( $output_stream );

I get this error:

File operations should use WP_Filesystem methods instead of direct PHP filesystem calls. Found: fopen()

WP_Filesystem doesn't seem appropriate here.

Do you recommend a different way of writing the above code?

@JDGrimes
Copy link
Contributor

This is related to #295, though that is for a different sniff.

@GaryJones
Copy link
Member

Very relevant: #1265 (comment)

@jrfnl
Copy link
Member

jrfnl commented Dec 9, 2022

Closing as fixed by #1655 which was included in WPCS 2.1.0.

@jrfnl jrfnl closed this as completed Dec 9, 2022
@jrfnl jrfnl added this to the 2.1.0 milestone Jul 4, 2023
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

4 participants