Difference between revisions of "PHP CodeSniffer (PHPcs)"

From HaFrWiki
Jump to: navigation, search
m (Bug Workarounds)
m (Bug Workarounds)
Line 13: Line 13:
 
* open the file with a normal developer text editor.
 
* open the file with a normal developer text editor.
 
* Adjust
 
* Adjust
<pre>
+
<syntaxhighlight lang="php" line start=1>
 
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
 
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
 
   include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
 
   include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
Line 19: Line 19:
 
   include_once 'PHP/CodeSniffer/CLI.php';
 
   include_once 'PHP/CodeSniffer/CLI.php';
 
}
 
}
</pre>
+
</syntaxhighlight>
 
Into something like:
 
Into something like:
<pre>
+
<syntaxhighlight lang="php" line start=1>
 
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
 
if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {
 
   include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
 
   include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';
Line 29: Line 29:
 
   include_once 'PHP/CodeSniffer/CLI.php';
 
   include_once 'PHP/CodeSniffer/CLI.php';
 
}
 
}
</pre>
+
</syntaxhighlight>
  
 
== See also ==
 
== See also ==

Revision as of 11:42, 20 June 2015

PHP CodeSniffer (PHPcs) is a useful tool for PHP developers.

Introduction

PHPcs is a PHP5 script that tokenises and "sniffs" PHP, JavaScript and CSS files to detect violations of a defined coding standard. It is an essential development tool that ensures your code remains clean and consistent. It can also help prevent some common semantic errors made by developers.

Bug Workarounds

Some users experience warning about not finding the CLI.php file after installing and trying the tools.

  • Search for the location of the phpcs file.
  • open the file with a normal developer text editor.
  • Adjust

<syntaxhighlight lang="php" line start=1> if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {

  include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';

else {

  include_once 'PHP/CodeSniffer/CLI.php';

} </syntaxhighlight> Into something like: <syntaxhighlight lang="php" line start=1> if (is_file(dirname(__FILE__).'/../CodeSniffer/CLI.php') === true) {

  include_once dirname(__FILE__).'/../CodeSniffer/CLI.php';

} else if (is_file('/usr/local/pear/share/pear/PHP/CodeSniffer/CLI.php')) {

  include_once '/usr/local/pear/share/pear/PHP/CodeSniffer/CLI.php';

} else {

  include_once 'PHP/CodeSniffer/CLI.php';

} </syntaxhighlight>

See also

top

Reference

top