-3

I am trying to install php code sniffer. I have manage to get to a point where after running php /Users/ryanfernandes/pear/bin/phpcs --version it display the info. but when I try to run code sniffer by

php /Users/username/pear/bin/phpcs /Users/username/development/htdocs/test.php 
PHP Warning:  fwrite() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 155

Warning: fwrite() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 155
PHP Warning:  stream_get_meta_data() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 206

Warning: stream_get_meta_data() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 206
PHP Warning:  file_get_contents(): Filename cannot be empty in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 208

Warning: file_get_contents(): Filename cannot be empty in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 208
PHP Warning:  fclose() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 209

Warning: fclose() expects parameter 1 to be resource, boolean given in /Users/username/pear/share/pear/PHP/CodeSniffer/Reporting.php on line 209

Any help would be really appreciated.

Thanks

chepe263
  • 2,774
  • 22
  • 38

1 Answers1

1

From the error messages, it looks like you are using PHP_CodeSniffer version 1.5.4. PHP_CodeSniffer uses the tmpfile() function to create a temporary file. The directory that it is created in can be found by running:

php -r 'echo sys_get_temp_dir().PHP_EOL;'

Make sure you are allowed to write to that directory because the tmpfile() method is obviously returning FALSE, which most commonly happens if the directory is not writable.

Greg Sherwood
  • 6,992
  • 2
  • 29
  • 24
  • Hi Greg, Thanks for your reply. After giving read write permission it worked. Thanks again. Another question, each time now I have to run code sniffer i have to do the following php /Users/username/pear/bin/phpcs /Users/username/development/htdocs/test/test-cs.php instead of phpcs /Users/ryanfernandes/development/htdocs/ryan/test-cs.php Any help appreciated. – user3726629 Nov 12 '14 at 15:49
  • This would be because the PEAR executable directory (where PEAR puts scripts like phpcs) is not in your PATH. Run `pear config-show | grep bin_dir` to find that directory (e.g., /ur/local/bin). Now edit `~/.profile` (create it if it doesn't exit) and add the line `export PATH=/usr/local/bin:$PATH` and save. If you are already exporting the PATH there, just add the PEAR executable path to it instead (paths are separated by colons). Reload your profile by running `. ~/.profile` and the phpcs command should work. – Greg Sherwood Nov 12 '14 at 21:04
  • Hi Greg, Thanks again. After running pear config-show | grep bin_dir, I got this /Users/username/pear/bin. I already have .bash_profile with the following export PATH=$PATH:/Users/username/pear/bin/pear:/usr/local/zend/bin:/Users/username/pear/bin I am not sure if .profile and .bash_profile are the same. Also, if I do pear config-show I get the following Thanks – user3726629 Nov 13 '14 at 10:24
  • ===================================== Auto-discover new Channels auto_discover Default Channel default_channel pear.php.net HTTP Proxy Server Address http_proxy PEAR server [DEPRECATED] master_server pear.php.net Default Channel Mirror preferred_mirror pear.php.net Remote Configuration File remote_config PEAR executables directory bin_dir /Users/username/pear/bin – user3726629 Nov 13 '14 at 10:26
  • PEAR documentation directory doc_dir /Users/username/pear/docs PHP extension directory ext_dir /usr/local/zend/lib/php_extensions PEAR directory php_dir /Users/username/pear/share/pear PEAR Installer cache directory cache_dir /usr/local/zend/tmp/pear/cache PEAR configuration file cfg_dir /Users/username/pear/cfg directory PEAR data directory data_dir /Users/username/pear/data PEAR Installer download download_dir /tmp/pear/install directory – user3726629 Nov 13 '14 at 10:27
  • PHP CLI/CGI binary php_bin /usr/local/zend/bin/php php.ini location php_ini /usr/local/zend/etc/php.ini --program-prefix passed to php_prefix PHP's ./configure --program-suffix passed to php_suffix PHP's ./configure PEAR Installer temp directory temp_dir /tmp/pear/install PEAR test directory test_dir /Users/username/pear/tests PEAR www files directory www_dir /Users/username/pear/www – user3726629 Nov 13 '14 at 10:27
  • Cache TimeToLive cache_ttl 3600 Preferred Package State preferred_state stable Unix file mask umask 22 Debug Log Level verbose 1 PEAR password (for password maintainers) Signature Handling Program sig_bin /usr/local/bin/gpg Signature Key Directory sig_keydir /usr/local/zend/etc/pearkeys Signature Key Id sig_keyid Package Signature Type sig_type gpg – user3726629 Nov 13 '14 at 10:27
  • PEAR username (for username maintainers) User Configuration File Filename /Users/username/.pearrc System Configuration File Filename /usr/local/zend/etc/pear.conf – user3726629 Nov 13 '14 at 10:28
  • If phpcs is already in your path, then what happens when you try and run the command? Does it just say "command not found"? Does `which phpcs` produce any output? Does `echo $PATH` show you the correct path in there? If all that looks good, then I'm not sure what else to try. – Greg Sherwood Nov 13 '14 at 21:00