Method attendance_check
has 86 lines of code (exceeds 25 allowed). Consider refactoring. Open
function attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
Function attendance_check
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
function attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
- 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
Method list_attendance_stats
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
function list_attendance_stats($user_id){
$sql = "SELECT
events.name AS name, SUM(events.worth) AS sum_worth, events.worth AS worth
FROM occurrence
The method attendance_check uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$attended = "no";
}
- 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
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 24 and the first side effect is on line 2. Open
<?php
- Exclude checks
The parameter $user_id is not named in camelCase. Open
function attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $user_id is not named in camelCase. Open
function list_attendance_stats($user_id){
$sql = "SELECT
events.name AS name, SUM(events.worth) AS sum_worth, events.worth AS worth
FROM occurrence
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
Blank line found at start of control structure Open
}else{
- Exclude checks
Blank line found at start of control structure Open
if(mysql_num_rows($result)!=0){
- Exclude checks
Line exceeds 120 characters; contains 149 characters Open
if($_SESSION['sessionposition'] != "Webmaster" && $_SESSION['sessionposition'] != "President"){echo("you do not have permission to view this page.");
- Exclude checks
Line exceeds 120 characters; contains 136 characters Open
//$sql = "SELECT `id`,`firstname`, `lastname` FROM `contact_information` WHERE `active_sem` = '$current_semester' ORDER BY `firstname`";
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(mysql_num_rows($result)!=0){
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 8 Open
echo "<option value='$row[id]'>$row[firstname] $row[lastname]</option>";
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 12 Open
while($row = mysql_fetch_array($results)){
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 16 Open
if($attended == 1){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($attended == 1){
- Exclude checks
Closing brace indented incorrectly; expected 12 spaces, found 4 Open
}
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($_SESSION['sessionposition'] != "Webmaster" && $_SESSION['sessionposition'] != "President"){echo("you do not have permission to view this page.");
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 3 Open
attendance_check($_POST['user_id']);
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 16 Open
}
- Exclude checks
Closing brace must be on a line by itself Open
echo("</table></div>");}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Opening brace should be on a new line Open
function attendance_check($user_id){
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
if (isset($_POST['list']) && ('process' == $_POST['list'])) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$result = mysql_query($sql);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
echo<<<END
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 0 Open
echo<<<END
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(isset($_SESSION['sessionposition']) != true){echo("You do not have permission to view this page.");
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 12 Open
}
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($row = mysql_fetch_array($results)){
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
echo("</table></div>");}
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
while($row = mysql_fetch_array($results)){
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 0 Open
if($_SESSION['sessionposition'] != "Webmaster" && $_SESSION['sessionposition'] != "President"){echo("you do not have permission to view this page.");
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($row = mysql_fetch_array($result)) {
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
}
- Exclude checks
Opening brace should be on a new line Open
function list_attendance_stats($user_id){
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 16 Open
}else{
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if(isset($_SESSION['sessionposition']) != true){echo("You do not have permission to view this page.");
- Exclude checks
Newline required after opening brace Open
if(isset($_SESSION['sessionposition']) != true){echo("You do not have permission to view this page.");
- Exclude checks
Newline required after opening brace Open
if($_SESSION['sessionposition'] != "Webmaster" && $_SESSION['sessionposition'] != "President"){echo("you do not have permission to view this page.");
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Space before opening parenthesis of function call prohibited Open
require_once ('session.php');
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
if($results){
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$sql = "SELECT `id`,`firstname`, `lastname` FROM `contact_information` WHERE 1 ORDER BY `firstname`";
- Exclude checks
Expected 1 space after WHILE keyword; 0 found Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($results){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
echo " <div style='margin: 0px auto; width: 100%; text-align: center;'>
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
}
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
while($row = mysql_fetch_array($result)){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($attended == 1){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($results){
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if(mysql_num_rows($result)!=0){
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 0 Open
echo "
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Closing brace indented incorrectly; expected 12 spaces, found 0 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
echo<<<END
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 0 Open
}
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 4 Open
echo"
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 0 Open
}else{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
if($_SESSION['sessionposition'] != "Webmaster" && $_SESSION['sessionposition'] != "President"){echo("you do not have permission to view this page.");
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 4 Open
while($row = mysql_fetch_array($result)) {
- Exclude checks
The variable $num_missed is not named in camelCase. Open
function list_attendance_stats($user_id){
$sql = "SELECT
events.name AS name, SUM(events.worth) AS sum_worth, events.worth AS worth
FROM occurrence
- 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 list_attendance_stats($user_id){
$sql = "SELECT
events.name AS name, SUM(events.worth) AS sum_worth, events.worth AS worth
FROM occurrence
- 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 attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
- 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 list_attendance_stats($user_id){
$sql = "SELECT
events.name AS name, SUM(events.worth) AS sum_worth, events.worth AS worth
FROM occurrence
- 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 attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
- 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 attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
- 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 $num_missed is not named in camelCase. Open
function list_attendance_stats($user_id){
$sql = "SELECT
events.name AS name, SUM(events.worth) AS sum_worth, events.worth AS worth
FROM occurrence
- 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 attendance_check($user_id){
$sql = "SELECT occurrence.e_id AS e_id, occurrence.id AS id, occurrence.date AS date,
events.name AS name, events.worth AS worth, occurrence.type AS type,
recorded_attendance.attended AS attended
FROM occurrence
- 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();
}
}