Package home | Report new bug | New search | Development Roadmap Status: Open | Feedback | All | Closed Since Version 3.7.2

Request #17240 Get --report-file to accept relative paths
Submitted: 2010-03-18 01:21 UTC
From: ashnazg Assigned: squiz
Status: Closed Package: PHP_CodeSniffer (version 1.2.2)
PHP Version: 5.2.4 OS: RHEL4
Roadmaps: (Not assigned)    

 [2010-03-18 01:21 UTC] ashnazg (Chuck Burgess)
Description: ------------ When using the --report-file option with a relative path, and the target file does not already exist, I get a file_put_contents() PHP Warning failure. If I use an absolute path, the file will be created successfully. If I use a relative path, I *must* create the file myself before running phpcs. Test script: --------------- Files: - relative/file1.php - relative/file2.php - relative/path/to/ Run from parent dir of relative/: phpcs --report-file=relative/path/to/checkstyle.xml --report=checkstyle --ignore=relative/path relative/ Expected result: ---------------- relative/path/to/checkstyle.xml file to be created Actual result: -------------- PHP Warning: file_put_contents(relative/path/to/checkstyle.xml): failed to open stream: No such file or directory in /absolute/path/to/PHP/CodeSniffer/Reporting.php on line 102 PHP Stack trace: PHP 1. {main}() /absolute/path/to/phpcs:0 PHP 2. PHP_CodeSniffer_CLI->process() /absolute/path/to/phpcs:30 PHP 3. PHP_CodeSniffer_CLI->printErrorReport() /absolute/path/to/PHP/CodeSniffer/CLI.php:438 PHP 4. PHP_CodeSniffer_Reporting->printReport() /absolute/path/to/PHP/CodeSniffer/CLI.php:475 PHP 5. file_put_contents() /absolute/path/to/PHP/CodeSniffer/Reporting.php:102


 [2010-03-19 08:01 UTC] squiz (Greg Sherwood)
-Summary: --report-file=relative/path/to.file requires to.file to pre-exist +Summary: Get --report-file to accept relative paths -Type: Bug +Type: Feature/Change Request -Assigned To: +Assigned To: squiz
I think this is just a consequence of the file_put_contents function. PHPCS doesn't try to turn relative paths into absolute; it just passes it directly through. I don't think I can determine if a path is relative either, because it could really be anything. I also can't use realpath() because the current working directory in PHPCS is not where you actually are (it changes it to make a few things work). So I may be able to get it going by changing dirs back and forth, but I don't think it's really worth it. I'm going to turn this into a feature request to support relative paths in the report-file command line arg. For now, everyone please use absolute paths.
 [2011-04-07 11:56 UTC] squiz (Greg Sherwood)
-Status: Assigned +Status: Open
 [2011-04-20 10:21 UTC] squiz (Greg Sherwood)
-Status: Open +Status: Closed -Assigned To: +Assigned To: squiz
This bug has been fixed in SVN. If this was a documentation problem, the fix will appear on by the end of next Sunday (CET). If this was a problem with the website, the change should be live shortly. Otherwise, the fix will appear in the package's next release. Thank you for the report and for helping us make PEAR better. I figured it out after all :)