APO-Epsilon/apo-website

View on GitHub
attendance_check.php

Summary

Maintainability
B
5 hrs
Test Coverage

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
Severity: Major
Found in attendance_check.php - About 3 hrs to fix

    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
    Severity: Minor
    Found in attendance_check.php - About 1 hr to fix

    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
    Severity: Minor
    Found in attendance_check.php - About 1 hr to fix

      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";
                      }
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Blank line found at start of control structure
      Open

          if(mysql_num_rows($result)!=0){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      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.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line exceeds 120 characters; contains 136 characters
      Open

      //$sql = "SELECT `id`,`firstname`, `lastname` FROM `contact_information` WHERE `active_sem` = '$current_semester' ORDER BY `firstname`";
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

              while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after WHILE keyword; 0 found
      Open

                  while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after IF keyword; 0 found
      Open

          if(mysql_num_rows($result)!=0){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after WHILE keyword; 0 found
      Open

                  while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 12 spaces, found 8
      Open

              echo "<option value='$row[id]'>$row[firstname] $row[lastname]</option>";
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Space before opening parenthesis of function call prohibited
      Open

      require_once ('mysql_access.php');
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 12
      Open

                  while($row = mysql_fetch_array($results)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 16
      Open

                      if($attended == 1){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

                      if($attended == 1){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Closing brace indented incorrectly; expected 12 spaces, found 4
      Open

          }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      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.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 12 spaces, found 3
      Open

         attendance_check($_POST['user_id']);
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after WHILE keyword; 0 found
      Open

              while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 16
      Open

                      }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Closing brace must be on a line by itself
      Open

      echo("</table></div>");}
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Opening brace should be on a new line
      Open

      function attendance_check($user_id){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 0
      Open

      if (isset($_POST['list']) && ('process' == $_POST['list'])) {
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 0
      Open

      }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 0
      Open

      $result = mysql_query($sql);
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after ELSE keyword; 0 found
      Open

                      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 0
      Open

      echo<<<END
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 4 spaces, found 0
      Open

      echo<<<END
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after IF keyword; 0 found
      Open

      if(isset($_SESSION['sessionposition']) != true){echo("You do not have permission to view this page.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing brace; 0 found
      Open

      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 12
      Open

                  }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after WHILE keyword; 0 found
      Open

                  while($row = mysql_fetch_array($results)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 0
      Open

      echo("</table></div>");}
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

                  while($row = mysql_fetch_array($results)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      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.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after WHILE keyword; 0 found
      Open

          while($row = mysql_fetch_array($result)) {
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Opening brace should be on a new line
      Open

      function list_attendance_stats($user_id){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 16
      Open

                      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

                  while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

      if(isset($_SESSION['sessionposition']) != true){echo("You do not have permission to view this page.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Newline required after opening brace
      Open

      if(isset($_SESSION['sessionposition']) != true){echo("You do not have permission to view this page.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Newline required after opening brace
      Open

      if($_SESSION['sessionposition'] != "Webmaster" && $_SESSION['sessionposition'] != "President"){echo("you do not have permission to view this page.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after ELSE keyword; 0 found
      Open

      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Space before opening parenthesis of function call prohibited
      Open

      require_once ('session.php');
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              if($results){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 0
      Open

      $sql = "SELECT `id`,`firstname`, `lastname` FROM `contact_information` WHERE 1 ORDER BY `firstname`";
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after WHILE keyword; 0 found
      Open

              while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

              if($results){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

                  while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing brace; 0 found
      Open

                      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 0
      Open

      echo "      <div style='margin: 0px auto; width: 100%; text-align: center;'>
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 0
      Open

      }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

              while($row = mysql_fetch_array($result)){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after IF keyword; 0 found
      Open

                      if($attended == 1){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after IF keyword; 0 found
      Open

              if($results){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing parenthesis; found 0
      Open

          if(mysql_num_rows($result)!=0){
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 12 spaces, found 0
      Open

      echo "
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after closing brace; 0 found
      Open

      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Closing brace indented incorrectly; expected 12 spaces, found 0
      Open

      }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 0
      Open

      echo<<<END
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 0
      Open

      }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          echo"
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 0
      Open

      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 4 spaces, found 8
      Open

              }
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Expected 1 space after ELSE keyword; 0 found
      Open

      }else{
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      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.");
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          while($row = mysql_fetch_array($result)) {
      Severity: Minor
      Found in attendance_check.php by phpcodesniffer

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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
      Severity: Minor
      Found in attendance_check.php by phpmd

      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

      There are no issues that match your filters.

      Category
      Status