title: PHP Code Sniffer Rules
body: <p>I'm having trouble getting these rules to work:</p>
  
  <p>No space after function name:</p>
  
  <pre><code>// good
  public function cities()
  
  // bad
  public function cities ()
  </code></pre>
  
  <p>Ensure space between equals:</p>
  
  <pre><code>// good
  $test = 'test';
  
  // bad
  $test ='test';
  $test= 'test';
  </code></pre>
  
  <p>Must have spaces after comma in args:</p>
  
  <pre><code>// good
  function ($arg1, $arg2)
  
  // bad
  function ($arg1,$arg2)
  function ($arg1 ,$arg2)
  </code></pre>
  
  <p>My Rules:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;ruleset name="PSR2"&gt;
  &lt;description&gt;The PSR-2 coding standard.&lt;/description&gt;
  
  &lt;!-- PHP code MUST use the long &lt;?php ?&gt; tags or the short-echo &lt;?= ?&gt; tags; it MUST NOT use the other tag variations. --&gt;
  &lt;rule ref="Generic.PHP.DisallowShortOpenTag.EchoFound"&gt;
  &lt;severity&gt;0&lt;/severity&gt;
  &lt;/rule&gt;
  
  &lt;!-- PHP code MUST use only UTF-8 without BOM. --&gt;
  &lt;rule ref="Generic.Files.ByteOrderMark"/&gt;
  
  &lt;!-- Class names MUST be declared in StudlyCaps. --&gt;
  &lt;rule ref="Squiz.Classes.ValidClassName"/&gt;
  
  &lt;!-- Class constants MUST be declared in all upper case with underscore separators. --&gt;
  &lt;rule ref="Generic.NamingConventions.UpperCaseConstantName"/&gt;
  
  &lt;!-- Method names MUST be declared in camelCase(). --&gt;
  &lt;rule ref="Generic.NamingConventions.CamelCapsFunctionName"/&gt;
  
  &lt;!-- There MUST NOT be trailing whitespace at the end of non-blank lines. --&gt;
  &lt;rule ref="Squiz.WhiteSpace.SuperfluousWhitespace"&gt;
  
  &lt;/rule&gt;
  &lt;rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.StartFile"&gt;
  &lt;severity&gt;0&lt;/severity&gt;
  &lt;/rule&gt;
  &lt;rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EndFile"&gt;
  &lt;severity&gt;0&lt;/severity&gt;
  &lt;/rule&gt;
  &lt;rule ref="Squiz.WhiteSpace.SuperfluousWhitespace.EmptyLines"&gt;
  &lt;severity&gt;0&lt;/severity&gt;
  &lt;/rule&gt;
  
  &lt;!-- There MUST NOT be more than one statement per line. --&gt;
  &lt;rule ref="Generic.Formatting.DisallowMultipleStatements"/&gt;
  
  &lt;!-- Code MUST use an indent of 4 spaces, and MUST NOT use tabs for indenting. --&gt;
  &lt;rule ref="Generic.WhiteSpace.ScopeIndent"&gt;
  &lt;properties&gt;
   &lt;property name="ignoreIndentationTokens" type="array" value="T_COMMENT,T_DOC_COMMENT"/&gt;
  &lt;/properties&gt;
  &lt;/rule&gt;
  &lt;rule ref="Generic.WhiteSpace.DisallowTabIndent"/&gt;
  
  &lt;!-- PHP keywords MUST be in lower case. --&gt;
  &lt;rule ref="Generic.PHP.LowerCaseKeyword"/&gt;
  
  &lt;!-- The PHP constants true, false, and null MUST be in lower case. --&gt;
  &lt;rule ref="Generic.PHP.LowerCaseConstant"/&gt;
  
  &lt;!-- Method names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility. --&gt;
  &lt;rule ref="PSR2.Methods.MethodDeclaration"/&gt;
  
  &lt;!-- When present, there MUST be one blank line after the namespace declaration. --&gt;
  &lt;rule ref="PSR2.Namespaces.NamespaceDeclaration"/&gt;
  
  &lt;!-- When present, all use declarations MUST go after the namespace declaration.
      There MUST be one use keyword per declaration.
      There MUST be one blank line after the use block. --&gt;
  &lt;rule ref="PSR2.Namespaces.UseDeclaration"/&gt;
  
  &lt;!-- The extends and implements keywords MUST be declared on the same line as the class name.
      The opening brace for the class go MUST go on its own line; the closing brace for the class MUST go on the next line after the body.
      Lists of implements MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one interface per line. --&gt;
  &lt;rule ref="PSR2.Classes.ClassDeclaration"/&gt;
  
  &lt;!-- Visibility MUST be declared on all properties.
      The var keyword MUST NOT be used to declare a property.
      There MUST NOT be more than one property declared per statement.
      Property names SHOULD NOT be prefixed with a single underscore to indicate protected or private visibility. --&gt;
  &lt;rule ref="PSR2.Classes.PropertyDeclaration"/&gt;
  
  &lt;!-- Visibility MUST be declared on all methods. --&gt;
  &lt;rule ref="Squiz.Scope.MethodScope"/&gt;
  &lt;rule ref="Squiz.WhiteSpace.ScopeKeywordSpacing"/&gt;
  
  &lt;!-- Method names MUST NOT be declared with a space after the method name. The opening brace MUST go on its own line, and the closing brace MUST go on the next line following the body. There MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. --&gt;
  &lt;rule ref="Squiz.Functions.FunctionDeclaration"/&gt;
  &lt;rule ref="Squiz.Functions.LowercaseFunctionKeywords"/&gt;
  
  &lt;!-- In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma. --&gt;
  &lt;rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing"&gt;
  &lt;properties&gt;
   &lt;property name="equalsSpacing" value="1"/&gt;
  &lt;/properties&gt;
  &lt;/rule&gt;
  &lt;rule ref="Squiz.Functions.FunctionDeclarationArgumentSpacing.SpacingAfterHint"&gt;
  &lt;severity&gt;0&lt;/severity&gt;
  &lt;/rule&gt;
  
  &lt;!-- Method arguments with default values MUST go at the end of the argument list. --&gt;
  &lt;rule ref="PEAR.Functions.ValidDefaultValue"/&gt;
  
  &lt;!-- Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line. When the argument list is split across multiple lines, the closing parenthesis and opening brace MUST be placed together on their own line with one space between them. --&gt;
  &lt;rule ref="Squiz.Functions.MultiLineFunctionDeclaration"/&gt;
  
  &lt;!-- When making a method or function call, there MUST NOT be a space between the method or function name and the opening parenthesis, there MUST NOT be a space after the opening parenthesis, and there MUST NOT be a space before the closing parenthesis. In the argument list, there MUST NOT be a space before each comma, and there MUST be one space after each comma.
  Argument lists MAY be split across multiple lines, where each subsequent line is indented once. When doing so, the first item in the list MUST be on the next line, and there MUST be only one argument per line. --&gt;
  &lt;rule ref="Generic.Functions.FunctionCallArgumentSpacing"/&gt;
  &lt;rule ref="PSR2.Methods.FunctionCallSignature.SpaceAfterCloseBracket"&gt;
  &lt;severity&gt;0&lt;/severity&gt;
  &lt;/rule&gt;
  
  &lt;!-- The general style rules for control structures are as follows:
  There MUST be one space after the control structure keyword
  There MUST NOT be a space after the opening parenthesis
  There MUST NOT be a space before the closing parenthesis
  There MUST be one space between the closing parenthesis and the opening brace
  The structure body MUST be indented once
  The closing brace MUST be on the next line after the body --&gt;
  &lt;rule ref="Squiz.ControlStructures.ControlSignature"&gt;
  &lt;properties&gt;
   &lt;property name="ignoreComments" value="true"/&gt;
  &lt;/properties&gt;
  &lt;/rule&gt;
  &lt;rule ref="Squiz.WhiteSpace.ScopeClosingBrace"/&gt;
  &lt;rule ref="Squiz.ControlStructures.ForEachLoopDeclaration"/&gt;
  &lt;rule ref="Squiz.ControlStructures.ForLoopDeclaration"/&gt;
  &lt;rule ref="Squiz.ControlStructures.LowercaseDeclaration"/&gt;
  &lt;!-- checked in ControlStructures/ControlStructureSpacingSniff --&gt;
  
  &lt;!-- The body of each structure MUST be enclosed by braces. This standardizes how the structures look, and reduces the likelihood of introducing errors as new lines get added to the body. --&gt;
  &lt;rule ref="Generic.ControlStructures.InlineControlStructure"/&gt;
  
  &lt;/ruleset&gt;
  </code></pre>