Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$query_orgs = $db->query($select_orgs) or die("There was a problem querying the organizations. Contact the webmaster.");
- 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 function list_orgs() contains an exit expression. Open
$query_orgs = $db->query($select_orgs) or die("There was a problem querying the organizations. Contact the webmaster.");
- 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
$query_orgs = $db->query($select_orgs) or die("There was a problem querying the organizations. Contact the webmaster.");
- 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
if (isset($_POST['update'])) {
// Update Information
$_POST = array_map('mysql_real_escape_string', $_POST);
$user_id = $_SESSION['sessionID'];
$sql = <<<SQL
- 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 297.
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
A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 101 and the first side effect is on line 75. Open
<?php
- Exclude checks
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = 1;
- 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
Line exceeds 120 characters; contains 421 characters Open
$force = "<div style='margin: 50px; padding: 10px; background: #F08080; '><h1 style='color:red;'>Please update your information for this semester.</h1> Do you have any new <b>Littles</b>, different <b>status</b>, have a new <b>local address</b>, or change your <b>major</b> recently? You will not be able to access the site until you have clicked 'Update' below. If you have problems, contact the webmaster!</div>";
- Exclude checks
Line exceeds 120 characters; contains 398 characters Open
<input type="text" name="phone" value="$row[phone]" placeholder="+1-555-555-1234" required="" pattern="^(?:(?:\+?1\s*(?:[.-]\s*)?)?(?:\(\s*([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9])\s*\)|([2-9]1[02-9]|[2-9][02-8]1|[2-9][02-8][02-9]))\s*(?:[.-]\s*)?)?([2-9]1[02-9]|[2-9][02-9]1|[2-9][02-9]{2})\s*(?:[.-]\s*)?([0-9]{4})(?:\s*(?:#|x\.?|ext\.?|extension)\s*(\d+))?$" autocomplete="tel"/>
- Exclude checks
Line exceeds 120 characters; contains 179 characters Open
<input type="text" name="local_address" value="$row[localaddress]" pattern="[a-zA-Z\d\s\-\,\#\.\+]+" placeholder="123 Any Street" autocomplete="Local street-address"/>
- Exclude checks
Line exceeds 120 characters; contains 131 characters Open
<input type="text" name="first_name" value="$row[firstname]" placeholder="First name" required="" autocomplete="name"/>
- Exclude checks
Line exceeds 120 characters; contains 122 characters Open
$query_orgs = $db->query($select_orgs) or die("There was a problem querying the organizations. Contact the webmaster.");
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
<input type="text" name="email" value="$row[email]" placeholder="name@example.com" required="" autocomplete="email"/>
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
<input type="text" name="last_name" value="$row[lastname]" placeholder="Last name" required="" autocomplete="name"/>
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$_POST = array_map('mysql_real_escape_string', $_POST);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}else{
- Exclude checks
Space before opening parenthesis of function call prohibited Open
include ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$result2 = $db->query($sql2);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
echo $_SESSION['active_sem'];
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$gender = $row['gender'];
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
echo "There may have been an error. Click <a href='./updateinfo.php'>here</a> to try again.";
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$row = mysqli_fetch_array($result);
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderF = "";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 2 Open
$i = 1;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$sql = <<<SQL
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if($gender == 2){
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
echo '<div class="entry">You need to <a href="./login.php">login</a> before you can use this page.</div>';
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 4 Open
$i = $i + 1;
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 2 Open
$force = "";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 2 Open
if (isset($_GET['forced']) == "true") {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($result && $_POST['race'] != "" && $_POST['gender'] != 0){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
echo $_SESSION['active_sem'];
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$sql = "SELECT * FROM `contact_information` WHERE `id` = '$user_id' LIMIT 1";
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$selectedF = "";
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 2 Open
$query_orgs = $db->query($select_orgs) or die("There was a problem querying the organizations. Contact the webmaster.");
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
if (isset($_POST['update'])) {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
echo "Your information has been updated. Click <a href='./updateinfo.php'>here</a> to make more changes. ";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if($result && $_POST['race'] != "" && $_POST['gender'] != 0){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($selected == 'F'){
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$month = date('F', $b_day);
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($gender == 2){
- Exclude checks
Usage of ELSE IF is discouraged; use ELSEIF instead Open
}else if($gender == 1){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$selectedT = "";
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderF = "checked=\"yes\"";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 2 Open
include ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$user_id = $_SESSION['sessionID'];
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$result = $db->query($sql);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$user_id = $_SESSION['sessionID'];
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderF = "";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
function list_orgs(){
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('session.php');
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$_SESSION['active_sem'] = $current_semester;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$selectedF = "checked=\"yes\"";
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($gender == 2){
- Exclude checks
Opening brace should be on a new line Open
function list_orgs(){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($result && $_POST['race'] != "" && $_POST['gender'] != 0){
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$result = $db->query($sql);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if($selected == 'F'){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
}else if($gender == 1){
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$selected = $row['hide_info'];
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($selected == 'F'){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$selectedT = "checked=\"yes\"";
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else if($gender == 1){
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 4 Open
echo "<option id='$orgs[id]''>$orgs[name]</option>";
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 2 Open
}
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$b_day = mktime(0, 0, 0, $row['bmonth'], 1, 2000);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 0 Open
$select_orgs = <<<SQL
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 2 Open
while ($orgs = mysqli_fetch_array($query_orgs)) {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 4 Open
$force = "<div style='margin: 50px; padding: 10px; background: #F08080; '><h1 style='color:red;'>Please update your information for this semester.</h1> Do you have any new <b>Littles</b>, different <b>status</b>, have a new <b>local address</b>, or change your <b>major</b> recently? You will not be able to access the site until you have clicked 'Update' below. If you have problems, contact the webmaster!</div>";
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$sql2 = "UPDATE `contact_information` SET visited = '1' WHERE id = '$user_id' LIMIT 1";
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$_SESSION['active_sem'] = $current_semester;
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderM = "";
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
echo<<<END
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderM = "checked=\"yes\"";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}else if($gender == 1){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
}else if($gender == 1){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderM = "";
- Exclude checks
The variable $select_orgs is not named in camelCase. Open
function list_orgs(){
include ('mysql_access.php');
$select_orgs = <<<SQL
SELECT `name`, `id`
FROM `organizations`
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $select_orgs is not named in camelCase. Open
function list_orgs(){
include ('mysql_access.php');
$select_orgs = <<<SQL
SELECT `name`, `id`
FROM `organizations`
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $query_orgs is not named in camelCase. Open
function list_orgs(){
include ('mysql_access.php');
$select_orgs = <<<SQL
SELECT `name`, `id`
FROM `organizations`
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}
Source
The variable $query_orgs is not named in camelCase. Open
function list_orgs(){
include ('mysql_access.php');
$select_orgs = <<<SQL
SELECT `name`, `id`
FROM `organizations`
- Read upRead up
- Exclude checks
CamelCaseVariableName
Since: 0.2
It is considered best practice to use the camelCase notation to name variables.
Example
class ClassName {
public function doSomething() {
$data_module = new DataModule();
}
}