2012-08-02 116 views
2

當我phpcs --version類型,而不是獲得的版本號,我得到的是這樣的:PHPCS未在命令行上運行?

/Applications/drupal/php/bin/phpcs: line 2: ?php: No such file or directory 
/Applications/drupal/php/bin/phpcs: line 3: /Applications: is a directory 
/Applications/drupal/php/bin/phpcs: line 4: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 5: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 6: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 7: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 8: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 9: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 10: Applications: command not found 
/Applications/drupal/php/bin/phpcs: line 11: syntax error near unexpected token `newline' 
/Applications/drupal/php/bin/phpcs: line 11: ` * @author Greg Sherwood <[email protected]>' 

它看起來像它不讀PHP正確。我錯誤配置了什麼?

我所做的只是sudo pear安裝PHP_CodeSniffer。當我再次運行它,我得到:

梨/ PHP_CodeSniffer已經安裝並是一樣的發佈版本1.3.5

+0

嘗試執行'php phpcs --version',所以'phpcs'文件與PHP解釋器/可執行文件運行 – 2012-08-02 21:55:59

+0

這可行......但我無法讓我的插件在NetBeans中工作,我認爲它因爲phpcs沒有正確執行。 – 2012-08-03 19:34:16

+0

'當我嘗試'php phpcs --version'時無法打開輸入文件:phpcs' – Prateekro 2017-10-31 14:27:04

回答

14

當PEAR並安裝一個的PHP_CodeSniffer,它改變了主要的第一行phpcs腳本,以便#!行指向您系統上的PHP可執行文件。

所以安裝前,行看起來是這樣的:#[email protected][email protected]和安裝後,它會是這個樣子(具體取決於安裝PHP在哪裏):#!/usr/bin/php

PEAR有一個配置設置告訴它哪裏是PHP可執行文件安裝。您可以通過運行pear config-show並查找PHP CLI/CGI binary (php_bin)的值來查看此值。您需要確保這個值實際上是您系統上PHP的位置,否則所有腳本安裝(如PHPUnit)都會有類似的問題。

檢查此值的最佳方法是運行which php併爲PEAR配置變量設置該值。然後重新安裝PHP_CodeSniffer,以便重新進行更換。

所以我的系統,我應該這樣做:

$ which php 
/usr/bin/php 
$ sudo pear config-set php_bin /usr/bin/php 
config-set succeeded 
$ sudo pear uninstall php_codesniffer 
uninstall ok: channel://pear.php.net/PHP_CodeSniffer-1.3.5 
$ sudo pear install php_codesniffer 
downloading PHP_CodeSniffer-1.3.5.tgz ... 
Starting to download PHP_CodeSniffer-1.3.5.tgz (345,113 bytes) 
......................................................................done: 345,113 bytes 
install ok: channel://pear.php.net/PHP_CodeSniffer-1.3.5 

如果一切順利的話,你應該看到您的新phpcs文件的正確#!行:

$ which phpcs 
/usr/local/bin/phpcs 
$ head -n 1 /usr/local/bin/phpcs 
#!/usr/bin/php 

如果看起來正確的話,你將能夠毫無問題地運行phpcs命令。

+0

我在我的phpcs文件頂部有正確的行 - 它匹配我的php二進制文件的位置 - 但它仍然無法正確運行。它確實運行,如果我從父目錄做php phpcs --version。 – 2012-08-03 15:29:12

+0

我可以讓PHPCS輸出你看到的唯一方法是實際刪除第一行,或者在它之前放置一些內容(#!必須是該文件的第一個內容)。是否有可能在壞的安裝(甚至換行符)的頂部有一些奇怪的字符? – 2012-08-03 23:15:26

+0

這是我看到的: '[pattie @ Pattie-Reavess-MacBook-Pro〜] $ head -n 1/Applications/drupal/php/bin/phpcs #!/ Applications/drupal/php/bin/php ' – 2012-08-06 14:11:14

4

我苦苦掙扎了一段時間,但終於弄清楚了 - 如果您直接調用的PHP命令是真實可執行文件的shell腳本包裝器,則需要編輯phpcs腳本的第一行以調用PHP通過/usr/bin/env

#!/usr/bin/env /Applications/acquia-drupal/php5_3/bin/php 

,或者只是

#!/usr/bin/env php 

搜索者完全上下文 - 修復前:

~$ head -n 1 pear/bin/phpcs 
#!/Applications/acquia-drupal/php5_3/bin/php 
~$ phpcs --version 
/Users/mryan/pear/bin/phpcs: line 2: ?php: No such file or directory 
/Users/mryan/pear/bin/phpcs: line 3: /Applications: is a directory 
/Users/mryan/pear/bin/phpcs: line 4: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 5: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 6: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 7: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 8: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 9: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 10: Desktop: command not found 
/Users/mryan/pear/bin/phpcs: line 11: syntax error near unexpected token `newline' 
/Users/mryan/pear/bin/phpcs: line 11: ` * @author Greg Sherwood <[email protected]>' 
~$ /Applications/acquia-drupal/php5_3/bin/php pear/bin/phpcs --version 
PHP_CodeSniffer version 1.4.5 (stable) by Squiz Pty Ltd. (http://www.squiz.com.au) 

修復程序後:

~$ head -n 1 pear/bin/phpcs 
#!/usr/bin/env php 
~$ phpcs --version 
PHP_CodeSniffer version 1.4.5 (stable) by Squiz Pty Ltd. (http://www.squiz.com.au) 

現在我可以在PhpStorm配置CodeSniffer。

+0

這爲我工作,重新安裝後沒有。謝謝! – 2013-07-08 17:36:56