show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_SESSION. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_SESSION. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_SESSION. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_SESSION. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_SESSION. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_POST. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_SESSION. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
show_page accesses the super-global variable $_GET. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
Method show_page
has 287 lines of code (exceeds 25 allowed). Consider refactoring. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
File updateinfo.php
has 324 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
require_once ('session.php');
require_once ('mysql_access.php');
?>
<!doctype html>
Function show_page
has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The function show_page() has 318 lines of code. Current threshold is set to 100. Avoid really long methods. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- Exclude checks
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
return $db->real_escape_string($a);
- 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($sql);
- 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
$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
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$result = $db->query($sql);
- 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
$result2 = $db->query($sql2);
- 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 show_page uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$genderM = "";
$genderF = "";
}
- 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 show_page uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$user_id = $_SESSION['sessionID'];
$sql = "SELECT * FROM `contact_information` WHERE `id` = '$user_id' LIMIT 1";
$result = $db->query($sql);
- 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 show_page uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
echo "There may have been an error. Click <a href='./updateinfo.php'>here</a> to try again.";
$_SESSION['active_sem'] = $current_semester;
echo $_SESSION['active_sem'];
}
- 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 show_page uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$selectedF = "";
$selectedT = "checked=\"yes\"";
}
- 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
return $db->real_escape_string($a);
- 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 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
Avoid unused local variables such as '$result2'. Open
$result2 = $db->query($sql2);
- 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('array_map_calllback', $_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 27 and the first side effect is on line 2. Open
<?php
- Exclude checks
Avoid variables with short names like $a. Configured minimum length is 3. Open
function array_map_calllback($a) {
- 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
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
Blank line found at end of control structure Open
- Exclude checks
Blank line found at start of control structure Open
} else {
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "true" but found "True" Open
$active_page = True;
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "False" Open
$exec_page = False;
- Exclude checks
TRUE, FALSE and NULL must be lowercase; expected "false" but found "False" Open
$public_page = False;
- 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 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 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 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 162 characters Open
<p>If you wish to change your status, the form can be found <a href="https://docs.google.com/a/truman.edu/file/d/0B_qnfQK1uoMVZGhKbGxsLUtMRW8/edit">here</a></p>
- 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 180 characters Open
<input type="text" name="homeaddress" value="$row[homeaddress]" pattern="[a-zA-Z\d\s\-\,\#\.\+]+" placeholder="123 Any Street" autocomplete="Permanent street-address"/>
- 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
End of line character is invalid; expected "\n" but found "\r\n" Open
<?php
- 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 indented incorrectly; expected at least 4 spaces, found 2 Open
global $current_semester;
- 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 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 4 spaces, found 2 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$selected = $row['hide_info'];
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($selected == 'F'){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$selectedF = "";
- 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
echo $_SESSION['active_sem'];
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if($gender == 2){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderF = "checked=\"yes\"";
- 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 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
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
$genderM = "";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
}
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('mysql_access.php');
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
}else if($gender == 1){
- 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
$i = 1;
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
show_page();
- 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 8 spaces, found 4 Open
$user_id = $_SESSION['sessionID'];
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderF = "";
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
}else if($gender == 1){
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Opening brace should be on a new line Open
function list_orgs(){
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
if (isset($_POST['update'])) {
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
include('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$result = $db->query($sql);
- 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
$selectedF = "checked=\"yes\"";
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$genderM = "";
- 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($gender == 2){
- 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
echo "There may have been an error. Click <a href='./updateinfo.php'>here</a> to try again.";
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$gender = $row['gender'];
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 2 Open
if (isset($_GET['forced']) == "true") {
- Exclude checks
Opening brace should be on a new line Open
function array_map_calllback($a) {
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
include('mysql_access.php');
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($result && $_POST['race'] != "" && $_POST['gender'] != 0){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($gender == 2){
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 0 Open
$select_orgs = <<<SQL
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 2 Open
}
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
return $db->real_escape_string($a);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$b_day = mktime(0, 0, 0, intval($row['bmonth']), 1, 2000);
- 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
$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 12 spaces, found 6 Open
$genderF = "";
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- 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
include ('mysql_access.php');
- 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 8 spaces, found 0 Open
echo<<<END
- Exclude checks
Opening brace should be on a new line Open
function show_page() {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$_POST = array_map('array_map_calllback', $_POST);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$user_id = $_SESSION['sessionID'];
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$row = mysqli_fetch_array($result);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
if($selected == 'F'){
- 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
Line indented incorrectly; expected at least 16 spaces, found 4 Open
$i = $i + 1;
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 2 Open
}
- Exclude checks
Opening brace should be on a new line Open
function show_active() {
- 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 16 spaces, found 4 Open
echo "<option id='$orgs[id]''>$orgs[name]</option>";
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$result2 = $db->query($sql2);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
} else {
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
$month = date('F', $b_day);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 6 Open
$selectedT = "";
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Usage of ELSE IF is discouraged; use ELSEIF instead Open
}else if($gender == 1){
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 2 Open
$force = "";
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$sql = <<<SQL
- 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 8 spaces, found 4 Open
$result = $db->query($sql);
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 2 Open
include ('mysql_access.php');
- Exclude checks
The variable $user_id is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $current_semester is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $user_id is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $user_id is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $b_day is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $current_semester is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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`
- 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 $current_semester is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $current_semester is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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`
- 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`
- 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 $b_day is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $user_id is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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 $user_id is not named in camelCase. Open
function show_page() {
include('mysql_access.php');
global $current_semester;
if (isset($_POST['update'])) {
- 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`
- 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();
}
}