PHP Coding Violations
Missing File Doc Comment
Description: The file doc comment is missing from the start of the file
// Code without a file doc comment
function exampleFunction() {
// function code
}
/**
* This is the file doc comment that provides a brief description of the file's purpose.
*/
function exampleFunction() {
// function code
}
Line Exceeds Length
Description: Line exceeds 85 characters;
// This is a line of code or comment that is significantly longer than the recommended 85 characters.
// This line has been shortened to fit within the recommended 85 character limit.
Long Description Capitalize
Description: Doc comment long description must start with a capital letter
/**
* this is a long description that does not start with a capital letter.
*/
/**
* This is a long description that starts with a capital letter.
*/
No Indent Tabs
Description: Spaces must be used for alignment; tabs are not allowed
// Misaligned with tabs
$variable = 'value';
// Aligned with spaces
$variable = 'value';
Short Description Capitalize
Description: Doc comment short description must start with a capital letter
/**
* short description without a capital letter.
*/
/**
* Short description that starts with a capital letter.
*/
Number of Blank Lines Before Tags
Description: There must be exactly one blank line before the tags in a doc comment
/**
* This is a description
* @param int $value
*/
/**
* This is a description
*
* @param int $value
*/
Multi-line Function Opening Bracket
Description: Opening parenthesis of a multi-line function call must be the last content on the line
functionCall(param1, param2,
moreContent);
functionCall(
param1,
param2
);
Multi-line Function Closing Bracket
Description: Closing parenthesis of a multi-line function call must be on a line by itself
functionCall(
param1,
param2);
functionCall(
param1,
param2
);
Number of Spaces Before Tag Value
Description: Tag value for @package tag indented incorrectly
/**
* @package MyPackage
*/
/**
* @package MyPackage
*/
Missing PHP Version
Description: PHP version not specified
/**
* This is the file comment.
*/
/**
* This is the file comment.
*
* PHP Version 7.4
*/
Missing Category Tag
Description: Missing @category tag in file comment
/**
* File description without a @category tag.
*/
/**
* File description.
*
* @category Utilities
*/
Missing License Tag
Description: Missing @license tag in file comment
/**
* File description without a @license tag.
*/
/**
* File description.
*
* @license MIT License
*/
Missing Link Tag
Description: Missing @link tag in file comment
/**
* File description without a @link tag.
*/
/**
* File description.
*
* @link https://example.com
*/
Missing Doc Comment for Class
Description: Missing doc comment for class component
class MyClass {
// Class code here
}
/**
* Class MyClass is responsible for XYZ operations.
*/
class MyClass {
// Class code here
}
Missing Doc Comment for Function
Description: Missing doc comment for function component
function myFunction() {
// Function code here
}
/**
* Executes the primary function logic.
*
* @return void
*/
function myFunction() {
// Function code here
}
Brace On Same Line
Description: Opening brace should be on a new line
function exampleFunction() {
// Function code here
}
function exampleFunction()
{
// Function code here
}
Wrong Exact Indentation
Description: Line indented incorrectly
function exampleFunction() {
$variable = 'value';
}
function exampleFunction() {
$variable = 'value';
}
Empty Lines Not Allowed
Description: Empty lines are not allowed in multi-line function calls
functionCall(
param1,
param2
);
functionCall(
param1,
param2
);
Spaces After Opening Bracket
Description: Space after opening parenthesis of function call prohibited
functionCall( param1, param2 );
functionCall(param1, param2);
Spaces Before Closing Bracket
Description: Expected 0 spaces before closing parenthesis
functionCall(param1, param2 );
functionCall(param1, param2);
No Underscore Before Private Method Name
Description: Private method name must be prefixed with an underscore
private function privateMethodName() {
// method code
}
private function _privateMethodName() {
// method code
}
Wrong Indentation
Description: Line indented incorrectly
function exampleFunction() {
$variable = 'value';
}
function exampleFunction() {
$variable = 'value';
}
No Underscore Before Private Member Variable
Description: Private member variable must be prefixed with an underscore
private $privateVariable;
private $_privateVariable;
Object Operator Indentation
Description: Object operator not indented correctly
$object
->method();
$object
->method();
Control Signature Found
Description: Expected foreach (...) {\n
; found foreach(...){\n
foreach($items as $item){
// loop code
}
foreach ($items as $item) {
// loop code
}
Number of Spaces Before Opening Brace
Description: There must be a single space between the closing parenthesis and the opening brace of a multi-line IF statement
if ($condition)
{
// condition code
}
if ($condition) {
// condition code
}
Closing Brace Indentation
Description: Closing brace indented incorrectly
function exampleFunction() {
$variable = 'value';
}
function exampleFunction() {
$variable = 'value';
}
Wrong Style for Function Comment
Description: You must use /**
style comments for a function comment
// Function to calculate value
function calculate() { }
/**
* Function to calculate value
*/
function calculate() { }
Space After Closing Bracket
Description: Space after closing parenthesis of function call prohibited
functionCall(param1, param2) ;
functionCall(param1, param2);
Space Before Comma
Description: Space found before comma in argument list
functionCall(param1 , param2);
functionCall(param1, param2);
Missing Parameter Doc
Description: Doc comment for parameter missing
/**
* Calculates value
*/
function calculate($value) { }
/**
* Calculates value
*
* @param int $value The value to calculate
*/
function calculate($value) { }
Spacing After Doc Comment
Description: Additional blank lines found at end of doc comment
/**
* Calculates value
*
*/
function calculate() { }
/**
* Calculates value
*/
function calculate() { }
Missing Return Tag
Description: Missing @return tag in function comment
/**
* Calculates value
*/
function calculate() {
return 42;
}
/**
* Calculates value
*
* @return int The calculated result
*/
function calculate() {
return 42;
}
Parameter Comment Not Found
Description: Missing parameter comment
/**
* Calculates value
*
* @param int $value
*/
function calculate($value) { }
/**
* Calculates value
*
* @param int $value The value to calculate
*/
function calculate($value) { }
Wrong Spacing After Parameter Type
Description: Expected 1 spaces after parameter type
/**
* Calculates value
*
* @param int$value The value to calculate
*/
function calculate($value) { }
/**
* Calculates value
*
* @param int $value The value to calculate
*/
function calculate($value) { }
Non Parameter Group
Description: Tag @return cannot be grouped with parameter tags in a doc comment
/**
* Calculates value
* @param int $value The value to calculate
* @return int The calculated result
*/
function calculate($value) { }
/**
* Calculates value
*
* @param int $value The value to calculate
*
* @return int The calculated result
*/
function calculate($value) { }
No Spaces After Comma
Description: No space found after comma in argument list
functionCall(param1,param2);
functionCall(param1, param2);
Use Include
Description: File is being conditionally included; use "include" instead
if ($condition) {
require 'file.php';
}
if ($condition) {
include 'file.php';
}
Missing Short Description
Description: Missing short description in doc comment
/**
*
* @param int $value The value to calculate
* @return int The result
*/
function calculate($value) { }
/**
* Calculates a value based on input.
*
* @param int $value The value to calculate
* @return int The result
*/
function calculate($value) { }
Asterisk Indentation
Description: Expected 5 space(s) before asterisk
/**
* Calculates value
*/
function calculate() { }
/**
* Calculates value
*/
function calculate() { }
Extra Parameter Comment
Description: Superfluous parameter comment
/**
* Calculates value
*
* @param int $value The value to calculate
* @param string $extra Extra parameter that is not used
* @return int The result
*/
function calculate($value) { }
/**
* Calculates value
*
* @param int $value The value to calculate
* @return int The result
*/
function calculate($value) { }
Multi-line Function Indentation
Description: Multi-line function call not indented correctly
functionCall(
param1,
param2
);
functionCall(
param1,
param2
);
Perl-style Comments
Description: Perl-style comments are not allowed. Use // Comment.
or /* comment */
instead.
# This is a Perl-style comment
// This is the correct comment style
Space Before Brace
Description: Expected 1 space before opening brace
function myFunction(){
function myFunction() {
Space After Function
Description: Expected 1 space after FUNCTION keyword
functionmyFunction() {
function myFunction() {
Parameter Name Mismatch
Description: Doc comment for parameter does not match actual variable name
/** @param string $name */ function greet($username) {
/** @param string $username */ function greet($username) {
Close Bracket Line
Description: The closing parenthesis of a multi-line function declaration must be on a new line
function myFunction(
$param1, $param2) {
function myFunction(
$param1, $param2
) {
New line Before Opening Brace
Description: The closing parenthesis and the opening brace of a multi-line function declaration must be on the same line
function myFunction(
$param1, $param2)
{
function myFunction(
$param1, $param2) {
Inline Control Structures
Description: Inline control structures are discouraged
if ($a == $b) echo 'Equal';
if ($a == $b) {
echo 'Equal';
}
Spacing After Opening Brace
Description: First condition of a multi-line IF statement must directly follow the opening parenthesis
if (
($a == $b) &&
($c == $d)
) {
if (($a == $b) &&
($c == $d)) {
Opening Statement Indentation
Description: Opening statement of multi-line function call not indented correctly
myFunction(
'arg1',
'arg2'
);
myFunction(
'arg1',
'arg2'
);
Name Format
Description: Public method name is not in camel caps format
function my_function() { }
function myFunction() { }
Minified File
Description: File appears to be minified and cannot be processed
/* Minified code */ var a=1;function b(){return a};
function exampleFunction() {
$a = 1;
return $a;
}
Disallow Tab Indent
Description: Spaces must be used to indent lines; tabs are not allowed
/* tab here */ function example() {
No Content After Brace
Description: Opening brace must be the last content on the line
function example() { echo 'Hello'; }
function example() {
echo 'Hello';
}
Use Include Once
Description: File is being conditionally included; use include_once
instead
if ($condition) { include 'file.php'; }
if ($condition) { include_once 'file.php'; }
Space Before Opening Parenthesis
Description: Expected 0 spaces before opening parenthesis
function example () { }
function example() { }
No PHP code found
Description: No PHP code was found in this file and short open tags are not allowed by this install of PHP. This file may be using short open tags but PHP does not allow them.
<?php ?>
<?php echo 'Hello, World!'; ?>
Bad Comment Format
Description: You must use /**
style comments for a file comment
// File Comment
/** File Comment */