APO-Epsilon/apo-website

View on GitHub
get_photo.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid using undefined variables such as '$db' which will lead to PHP notices.
Open

      $result = $db->query($sql);
Severity: Minor
Found in get_photo.php by phpmd

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 getPhotoLink uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

      }else{
        return "/user_photo.php?user_id=" . $user_id;
      }
Severity: Minor
Found in get_photo.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

Avoid unused local variables such as '$db'.
Open

      $result = $db->query($sql);
Severity: Minor
Found in get_photo.php by phpmd

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 parameter $user_id is not named in camelCase.
Open

function getPhotoLink($user_id){
  include ('mysql_access.php');
  $sql = "SELECT user_id FROM user_photos WHERE user_id=$user_id;";
      $result = $db->query($sql);
      if(mysqli_num_rows($result) == 0){
Severity: Minor
Found in get_photo.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

Line exceeds 120 characters; contains 125 characters
Open

//Based off example code at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
Severity: Minor
Found in get_photo.php by phpcodesniffer

Expected 1 space after IF keyword; 0 found
Open

      if(mysqli_num_rows($result) == 0){
Severity: Minor
Found in get_photo.php by phpcodesniffer

Line indented incorrectly; expected 4 spaces, found 6
Open

      }
Severity: Minor
Found in get_photo.php by phpcodesniffer

Expected 1 space after closing brace; 0 found
Open

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

Opening brace should be on a new line
Open

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

Expected 1 space after ELSE keyword; 0 found
Open

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

A closing tag is not permitted at the end of a PHP file
Open

?>
Severity: Minor
Found in get_photo.php by phpcodesniffer

Space before opening parenthesis of function call prohibited
Open

  include ('mysql_access.php');
Severity: Minor
Found in get_photo.php by phpcodesniffer

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

  $sql = "SELECT user_id FROM user_photos WHERE user_id=$user_id;";
Severity: Minor
Found in get_photo.php by phpcodesniffer

Expected 1 space after closing parenthesis; found 0
Open

      if(mysqli_num_rows($result) == 0){
Severity: Minor
Found in get_photo.php by phpcodesniffer

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

  include ('mysql_access.php');
Severity: Minor
Found in get_photo.php by phpcodesniffer

Line indented incorrectly; expected 4 spaces, found 6
Open

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

Line indented incorrectly; expected 4 spaces, found 6
Open

      if(mysqli_num_rows($result) == 0){
Severity: Minor
Found in get_photo.php by phpcodesniffer

The variable $user_id is not named in camelCase.
Open

function getPhotoLink($user_id){
  include ('mysql_access.php');
  $sql = "SELECT user_id FROM user_photos WHERE user_id=$user_id;";
      $result = $db->query($sql);
      if(mysqli_num_rows($result) == 0){
Severity: Minor
Found in get_photo.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 getPhotoLink($user_id){
  include ('mysql_access.php');
  $sql = "SELECT user_id FROM user_photos WHERE user_id=$user_id;";
      $result = $db->query($sql);
      if(mysqli_num_rows($result) == 0){
Severity: Minor
Found in get_photo.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