Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$results=$db->query($query);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$results=$db->query($query);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$results=$db->query($query);
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UndefinedVariable
Since: 2.8.0
Detects when a variable is used that has not been defined before.
Example
class Foo
{
private function bar()
{
// $message is undefined
echo $message;
}
}
Source https://phpmd.org/rules/cleancode.html#undefinedvariable
The method did_user_attend uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
{
$present = false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
The method is_user_excused uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
{
$present = false;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused local variables such as '$db'. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$db'. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The function signup() contains an exit expression. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid unused local variables such as '$db'. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The function add_excuse() contains an exit expression. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid unused local variables such as '$result'. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$db'. Open
$results=$db->query($query);
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
The function missed_meeting() contains an exit expression. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
ExitExpression
Since: 0.2
An exit-expression within regular code is untestable and therefore it should be avoided. Consider to move the exit-expression into some kind of startup script where an error/exception code is returned to the calling environment.
Example
class Foo {
public function bar($param) {
if ($param === 42) {
exit(23);
}
}
}
Source https://phpmd.org/rules/design.html#exitexpression
Avoid unused local variables such as '$result'. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$db'. Open
$results=$db->query($query);
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$db'. Open
$results=$db->query($query);
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Avoid unused local variables such as '$result'. Open
$result = $db->query($statement) or die("could not update");
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
Similar blocks of code found in 2 locations. Consider refactoring. Open
function did_user_attend ($uid,$eid)
{
include('mysql_access.php');
$query = "SELECT user_id FROM events_signup WHERE event_id = '$eid' AND user_id = '$uid'";
$results=$db->query($query);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 102.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
function is_user_excused ($uid,$eid)
{
include('mysql_access.php');
$query = "SELECT user_id FROM excused WHERE event_id = '$eid' AND user_id = '$uid'";
$results=$db->query($query);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 102.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid variables with short names like $id. Configured minimum length is 3. Open
function id_to_name ($id)
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used for alignment; tabs are not allowed Open
$statement ="INSERT INTO events_signup (user_id,event_id) VALUES ($uid,$eid)";
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($final['user_id'] == $uid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Expected "function abc(...)"; found "function abc (...)" Open
function add_excuse ($uid,$eid,$excuse,$semester)
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
function add_excuse ($uid,$eid,$excuse,$semester)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$results->free();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $present;
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
function signup ($uid,$eid)
- Exclude checks
Expected "function abc(...)"; found "function abc (...)" Open
function missed_meeting ($uid,$meeting,$excuse,$semester)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
function did_user_attend ($uid,$eid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $present;
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
function is_user_excused ($uid,$eid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$final=mysqli_fetch_array($results);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$present = false;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$final=mysqli_fetch_array($results);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
else
- Exclude checks
Expected "function abc(...)"; found "function abc (...)" Open
function id_to_name ($id)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $present;
- Exclude checks
Expected "function abc(...)"; found "function abc (...)" Open
function signup ($uid,$eid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$results=$db->query($query);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query = "SELECT user_id FROM events_signup WHERE event_id = '$eid' AND user_id = '$uid'";
- Exclude checks
Expected "function abc(...)"; found "function abc (...)" Open
function is_user_excused ($uid,$eid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$present = true;
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
function id_to_name ($id)
- Exclude checks
Expected 0 spaces before opening parenthesis; 1 found Open
function missed_meeting ($uid,$meeting,$excuse,$semester)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
if ($final['user_id'] == $uid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
return $present;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$statement ="INSERT INTO excused (user_id,event_id,excuse,semester) VALUES ($uid,$eid,'$excuse','$semester')";
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$statement ="INSERT INTO meetings_missed (user_id,meeting,semester,excuse) VALUES ($uid,'$meeting','$semester','$excuse')";
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$results=$db->query($query);
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
else
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
{
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$results->free();
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Expected "function abc(...)"; found "function abc (...)" Open
function did_user_attend ($uid,$eid)
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
}
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$present = false;
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$query = "SELECT user_id FROM excused WHERE event_id = '$eid' AND user_id = '$uid'";
- Exclude checks
Spaces must be used for alignment; tabs are not allowed Open
$present = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $final[$operand];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$results=$db->query($query);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$final=mysqli_fetch_array($results);
- Exclude checks
Line exceeds 120 characters; contains 127 characters Open
$statement ="INSERT INTO meetings_missed (user_id,meeting,semester,excuse) VALUES ($uid,'$meeting','$semester','$excuse')";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$results->free();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$query = "SELECT $operand FROM events_listing WHERE $condition = '$value'";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
include('mysql_access.php');
- Exclude checks
End of line character is invalid; expected "\n" but found "\r\n" Open
<?php
- Exclude checks
Whitespace found at end of line Open
return $name;
- Exclude checks
Expected 1 space between comma and argument "$eid"; 0 found Open
function signup ($uid,$eid)
- Exclude checks
Expected 1 space between comma and argument "$excuse"; 0 found Open
function missed_meeting ($uid,$meeting,$excuse,$semester)
- Exclude checks
Expected 1 space between comma and argument "$semester"; 0 found Open
function missed_meeting ($uid,$meeting,$excuse,$semester)
- Exclude checks
Whitespace found at end of line Open
$condition = 'id';
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
return $name;
- Exclude checks
Expected 1 space between comma and argument "$eid"; 0 found Open
function is_user_excused ($uid,$eid)
- Exclude checks
Whitespace found at end of line Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Whitespace found at end of line Open
return $present;
- Exclude checks
A closing tag is not permitted at the end of a PHP file Open
?>
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
$name = select_event($operand, $condition, $id);
- Exclude checks
Whitespace found at end of line Open
$result = $db->query($statement) or die("could not update");
- Exclude checks
Whitespace found at end of line Open
return $present;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
$condition = 'id';
- Exclude checks
Whitespace found at end of line Open
include('mysql_access.php');
- Exclude checks
Expected 1 space after closing parenthesis; found 6 Open
if ($final['user_id'] == $uid)
- Exclude checks
Expected 1 space after closing brace; newline found Open
}
- Exclude checks
Whitespace found at end of line Open
function id_to_name ($id)
- Exclude checks
Expected 1 space between comma and argument "$excuse"; 0 found Open
function add_excuse ($uid,$eid,$excuse,$semester)
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
$operand = 'event_name';
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks
Expected 1 newline at end of file; 0 found Open
?>
- Exclude checks
Expected 1 space between comma and argument "$eid"; 0 found Open
function add_excuse ($uid,$eid,$excuse,$semester)
- Exclude checks
Expected 1 space after closing parenthesis; found 6 Open
if ($final['user_id'] == $uid)
- Exclude checks
Expected 1 space between comma and argument "$semester"; 0 found Open
function add_excuse ($uid,$eid,$excuse,$semester)
- Exclude checks
Expected 1 space between comma and argument "$eid"; 0 found Open
function did_user_attend ($uid,$eid)
- Exclude checks
Expected 1 space after closing brace; newline found Open
}
- Exclude checks
Whitespace found at end of line Open
{
- Exclude checks
Expected 1 space between comma and argument "$meeting"; 0 found Open
function missed_meeting ($uid,$meeting,$excuse,$semester)
- Exclude checks
Expected 1 space after ELSE keyword; newline found Open
else
- Exclude checks