CRITICAL
Rule Definition
Using naming conventions helps reduce the effort to understand the SourceCode and also to increase the code quality
Violation Code Sample
Normal Variables
================
In Correct Naming Convention
----------------------------
$var_name = 'hello';
$_varName = 'hello';
echo $var_name;
echo $_varName;
echo 'Hello '.$var_name;
echo MyClass::$var_name;
echo $this->var_name;
echo $object->myFunction($one_two, $var2);
$someObject->my_function($var_name);
Member Variables Inside Class
============================
In Correct Naming Convention
----------------------------
$var_name = 'hello';
$_varName = 'hello';
public $var_name = 'hello';
public $_varName = 'hello';
protected $_varName = 'hello';
protected $_varname = 'hello';
private $_var_name = 'hello';
private $varName = 'hello';
Variables in the string
======================
In Correct Naming Convention
----------------------------
echo "Hello $var_name";
echo "Hello $_varName";
echo "{$_SERVER['HOSTNAME']} $var_name";
Fixed Code Sample
Normal Variables
================
Correct Naming Convention
$varName = 'hello';
$varname = 'hello';
$varname2 = 'hello';
echo $varName;
echo $varname;
echo $varName2;
echo 'Hello '.$varName;
echo MyClass::$var_name;
echo $this->varName;
echo $this->myFunction($one, $two);
Member Variables Inside Class
============================
Correct Naming Convention
-------------------------
1. $varName = 'hello';
2. $varname = 'hello';
3. $varname2 = 'hello';
public $varName = 'hello';
public $varname = 'hello';
public $varName2 = 'hello';
protected $_var_name = 'hello';
protected $varName = 'hello';
protected $_varName2 = 'hello';
private $_varName = 'hello';
private $_varname = 'hello';
private $_varName2 = 'hello';
Variables in the string
======================
Correct Naming Convention
-------------------------
echo "Hello $varName";
echo "Hello $varname";
echo "Hello $varName2";
Reference
http://pear.php.net/package/PHP_CodeSniffer/docs/2.5.0/PHP_CodeSniffer/Zend_Sniffs_NamingConventions_ValidVariableNameSniff.html
Related Technologies
Technical Criterion
Documentation - Naming Convention Conformity
About CAST Appmarq
CAST Appmarq is by far the biggest repository of data about real IT systems. It's built on thousands of analyzed applications, made of 35 different technologies, by over 300 business organizations across major verticals. It provides IT Leaders with factual key analytics to let them know if their applications are on track.