Skip to main content

PHP Coding Violations


Missing File Doc Comment

Description: The file doc comment is missing from the start of the file

Label Label Label

Bad Example
// Code without a file doc comment
function exampleFunction() {
// function code
}
Good Example
/**
* 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;

Label Label Label

Bad Example
// This is a line of code or comment that is significantly longer than the recommended 85 characters.
Good Example
// 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

Label Label Label

Bad Example
/**
* this is a long description that does not start with a capital letter.
*/
Good Example
/**
* 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

Label Label Label

Bad Example
// Misaligned with tabs
$variable = 'value';
Good Example
// Aligned with spaces
$variable = 'value';

Short Description Capitalize

Description: Doc comment short description must start with a capital letter

Label Label Label

Bad Example
/**
* short description without a capital letter.
*/
Good Example
/**
* 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

Label Label Label

Bad Example
/**
* This is a description
* @param int $value
*/
Good Example
/**
* 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

Label Label Label

Bad Example
functionCall(param1, param2,
moreContent);
Good Example
functionCall(
param1,
param2
);

Multi-line Function Closing Bracket

Description: Closing parenthesis of a multi-line function call must be on a line by itself

Label Label Label

Bad Example
functionCall(
param1,
param2);
Good Example
functionCall(
param1,
param2
);

Number of Spaces Before Tag Value

Description: Tag value for @package tag indented incorrectly

Label Label Label

Bad Example
/**
* @package MyPackage
*/
Good Example
/**
* @package MyPackage
*/

Missing PHP Version

Description: PHP version not specified

Label Label Label

Bad Example
/**
* This is the file comment.
*/
Good Example
/**
* This is the file comment.
*
* PHP Version 7.4
*/

Missing Category Tag

Description: Missing @category tag in file comment

Label Label Label

Bad Example
/**
* File description without a @category tag.
*/
Good Example
/**
* File description.
*
* @category Utilities
*/

Missing License Tag

Description: Missing @license tag in file comment

Label Label Label

Bad Example
/**
* File description without a @license tag.
*/
Good Example
/**
* File description.
*
* @license MIT License
*/

Description: Missing @link tag in file comment

Label Label Label

Bad Example
/**
* File description without a @link tag.
*/
Good Example
/**
* File description.
*
* @link https://example.com
*/

Missing Doc Comment for Class

Description: Missing doc comment for class component

Label Label Label

Bad Example
class MyClass {
// Class code here
}
Good Example
/**
* Class MyClass is responsible for XYZ operations.
*/
class MyClass {
// Class code here
}

Missing Doc Comment for Function

Description: Missing doc comment for function component

Label Label Label

Bad Example
function myFunction() {
// Function code here
}
Good Example
/**
* 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

Label Label Label

Bad Example
function exampleFunction() {
// Function code here
}
Good Example
function exampleFunction()
{
// Function code here
}

Wrong Exact Indentation

Description: Line indented incorrectly

Label Label Label

Bad Example
function exampleFunction() {
$variable = 'value';
}
Good Example
function exampleFunction() {
$variable = 'value';
}

Empty Lines Not Allowed

Description: Empty lines are not allowed in multi-line function calls

Label Label Label

Bad Example
functionCall(
param1,

param2
);
Good Example
functionCall(
param1,
param2
);

Spaces After Opening Bracket

Description: Space after opening parenthesis of function call prohibited

Label Label Label

Bad Example
functionCall( param1, param2 );
Good Example
functionCall(param1, param2);

Spaces Before Closing Bracket

Description: Expected 0 spaces before closing parenthesis

Label Label Label

Bad Example
functionCall(param1, param2 );
Good Example
functionCall(param1, param2);

No Underscore Before Private Method Name

Description: Private method name must be prefixed with an underscore

Label Label Label

Bad Example
private function privateMethodName() {
// method code
}
Good Example
private function _privateMethodName() {
// method code
}

Wrong Indentation

Description: Line indented incorrectly

Label Label Label

Bad Example
function exampleFunction() {
$variable = 'value';
}
Good Example
function exampleFunction() {
$variable = 'value';
}

No Underscore Before Private Member Variable

Description: Private member variable must be prefixed with an underscore

Label Label Label

Bad Example
private $privateVariable;
Good Example
private $_privateVariable;

Object Operator Indentation

Description: Object operator not indented correctly

Label Label Label

Bad Example
$object
->method();
Good Example
$object
->method();

Control Signature Found

Description: Expected foreach (...) {\n; found foreach(...){\n

Label Label Label

Bad Example
foreach($items as $item){
// loop code
}
Good Example
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

Label Label Label

Bad Example
if ($condition)
{
// condition code
}
Good Example
if ($condition) {
// condition code
}

Closing Brace Indentation

Description: Closing brace indented incorrectly

Label Label Label

Bad Example
function exampleFunction() {
$variable = 'value';
}
Good Example
function exampleFunction() {
$variable = 'value';
}

Wrong Style for Function Comment

Description: You must use /** style comments for a function comment

Label Label Label

Bad Example
// Function to calculate value
function calculate() { }
Good Example
/**
* Function to calculate value
*/
function calculate() { }

Space After Closing Bracket

Description: Space after closing parenthesis of function call prohibited

Label Label Label

Bad Example
functionCall(param1, param2) ;
Good Example
functionCall(param1, param2);

Space Before Comma

Description: Space found before comma in argument list

Label Label Label

Bad Example
functionCall(param1 , param2);
Good Example
functionCall(param1, param2);

Missing Parameter Doc

Description: Doc comment for parameter missing

Label Label Label

Bad Example
/**
* Calculates value
*/
function calculate($value) { }
Good Example
/**
* 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

Label Label Label

Bad Example
/**
* Calculates value
*
*/
function calculate() { }
Good Example
/**
* Calculates value
*/
function calculate() { }

Missing Return Tag

Description: Missing @return tag in function comment

Label Label Label

Bad Example
/**
* Calculates value
*/
function calculate() {
return 42;
}
Good Example
/**
* Calculates value
*
* @return int The calculated result
*/
function calculate() {
return 42;
}

Parameter Comment Not Found

Description: Missing parameter comment

Label Label Label

Bad Example
/**
* Calculates value
*
* @param int $value
*/
function calculate($value) { }
Good Example
/**
* Calculates value
*
* @param int $value The value to calculate
*/
function calculate($value) { }

Wrong Spacing After Parameter Type

Description: Expected 1 spaces after parameter type

Label Label Label

Bad Example
/**
* Calculates value
*
* @param int$value The value to calculate
*/
function calculate($value) { }
Good Example
/**
* 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

Label Label Label

Bad Example
/**
* Calculates value
* @param int $value The value to calculate
* @return int The calculated result
*/
function calculate($value) { }
Good Example
/**
* 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

Label Label Label

Bad Example
functionCall(param1,param2);
Good Example
functionCall(param1, param2);

Use Include

Description: File is being conditionally included; use "include" instead

Label Label Label

Bad Example
if ($condition) {
require 'file.php';
}
Good Example
if ($condition) {
include 'file.php';
}

Missing Short Description

Description: Missing short description in doc comment

Label Label Label

Bad Example
/**
*
* @param int $value The value to calculate
* @return int The result
*/
function calculate($value) { }
Good Example
/**
* 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

Label Label Label

Bad Example
/**
* Calculates value
*/
function calculate() { }
Good Example
/**
* Calculates value
*/
function calculate() { }

Extra Parameter Comment

Description: Superfluous parameter comment

Label Label Label

Bad Example
/**
* 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) { }
Good Example
/**
* 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

Label Label Label

Bad Example
functionCall(
param1,
param2
);
Good Example
functionCall(
param1,
param2
);

Perl-style Comments

Description: Perl-style comments are not allowed. Use // Comment. or /* comment */ instead.

Label Label Label

Bad Example
# This is a Perl-style comment
Good Example
// This is the correct comment style

Space Before Brace

Description: Expected 1 space before opening brace

Label Label Label

Bad Example
function myFunction(){
Good Example
function myFunction() {

Space After Function

Description: Expected 1 space after FUNCTION keyword

Label Label Label

Bad Example
functionmyFunction() {
Good Example
function myFunction() {

Parameter Name Mismatch

Description: Doc comment for parameter does not match actual variable name

Label Label Label

Bad Example
/** @param string $name */ function greet($username) {
Good Example
/** @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

Label Label Label

Bad Example
function myFunction(
$param1, $param2) {
Good Example
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

Label Label Label

Bad Example
function myFunction(
$param1, $param2)
{
Good Example
function myFunction(
$param1, $param2) {

Inline Control Structures

Description: Inline control structures are discouraged

Label Label Label

Bad Example
if ($a == $b) echo 'Equal';
Good Example
if ($a == $b) {
echo 'Equal';
}

Spacing After Opening Brace

Description: First condition of a multi-line IF statement must directly follow the opening parenthesis

Label Label Label

Bad Example
if (
($a == $b) &&
($c == $d)
) {
Good Example
if (($a == $b) &&
($c == $d)) {

Opening Statement Indentation

Description: Opening statement of multi-line function call not indented correctly

Label Label Label

Bad Example
myFunction(
'arg1',
'arg2'
);
Good Example
myFunction(
'arg1',
'arg2'
);

Name Format

Description: Public method name is not in camel caps format

Label Label Label

Bad Example
function my_function() { }
Good Example
function myFunction() { }

Minified File

Description: File appears to be minified and cannot be processed

Label Label Label

Bad Example
/* Minified code */ var a=1;function b(){return a};
Good Example
function exampleFunction() {
$a = 1;
return $a;
}

Disallow Tab Indent

Description: Spaces must be used to indent lines; tabs are not allowed

Label Label Label

Bad Example
/* tab here */ function example() {

No Content After Brace

Description: Opening brace must be the last content on the line

Label Label Label

Bad Example
function example() { echo 'Hello'; }
Good Example
function example() {
echo 'Hello';
}

Use Include Once

Description: File is being conditionally included; use include_once instead

Label Label Label

Bad Example
if ($condition) { include 'file.php'; }
Good Example
if ($condition) { include_once 'file.php'; }

Space Before Opening Parenthesis

Description: Expected 0 spaces before opening parenthesis

Label Label Label

Bad Example
function example () { }
Good 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.

Label Label Label

Bad Example
<?php ?>
Good Example
<?php echo 'Hello, World!'; ?>

Bad Comment Format

Description: You must use /** style comments for a file comment

Label Label Label

Bad Example
// File Comment
Good Example
/** File Comment */

Automated Software Quality Assurance


8, Chalkis Street, Thessaloniki, Greece, Tel: +30 2310 471 030
Copyright © 2024 Cyclopt