get_photo.php
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
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
The method getPhotoLink uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
Open
}else{
return "/user_photo.php?user_id=" . $user_id;
}
- 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
Open
$result = $db->query($sql);
- 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 parameter $user_id is not named in camelCase. Open
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){
- 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
Line exceeds 120 characters; contains 125 characters Open
Open
//Based off example code at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
Open
if(mysqli_num_rows($result) == 0){
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 6 Open
Open
}
- Exclude checks
Expected 1 space after closing brace; 0 found Open
Open
}else{
- Exclude checks
Opening brace should be on a new line Open
Open
function getPhotoLink($user_id){
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
Open
}else{
- Exclude checks
A closing tag is not permitted at the end of a PHP file Open
Open
?>
- Exclude checks
Space before opening parenthesis of function call prohibited Open
Open
include ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
Open
$sql = "SELECT user_id FROM user_photos WHERE user_id=$user_id;";
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
Open
if(mysqli_num_rows($result) == 0){
- Exclude checks
Line indented incorrectly; expected at least 4 spaces, found 2 Open
Open
include ('mysql_access.php');
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 6 Open
Open
}else{
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 6 Open
Open
if(mysqli_num_rows($result) == 0){
- Exclude checks
The variable $user_id is not named in camelCase. Open
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){
- 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
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){
- 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();
}
}