show_active accesses the super-global variable $_FILES. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active accesses the super-global variable $_SESSION. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active accesses the super-global variable $_FILES. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active accesses the super-global variable $_FILES. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active accesses the super-global variable $_FILES. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active accesses the super-global variable $_FILES. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active accesses the super-global variable $_FILES. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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
Function show_active
has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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 show_active
has 52 lines of code (exceeds 25 allowed). Consider refactoring. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
The function show_active() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Avoid using undefined variables such as '$db' which will lead to PHP notices. Open
$stmt = $db->prepare($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 show_active uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
switch($_FILES['user_photo']['error']){
case UPLOAD_ERR_INI_SIZE:
$msg = 'The uploaded file exceeds the upload_max_filesize directive in php.ini';
case UPLOAD_ERR_FORM_SIZE:
- 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_active uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$msg = "Sorry, that file is too large. The maximum file size is " . $maxsize/1000000 . "megabytes.";
}
- 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_active uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$msg = "File upload unsuccessful.";
}
- 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_active uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
}else{
$msg = "Sorry, that file is not an image";
}
- 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_active uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$msg = "Success";
}
- 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
$stmt = $db->prepare($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
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 9 and the first side effect is on line 2. Open
<?php
- Exclude checks
Blank line found at start of control structure Open
if(strpos(finfo_file($finfo, $_FILES['user_photo']['tmp_name']),"image")===0) {
- Exclude checks
Blank line found at start of control structure Open
if($_FILES['user_photo']['error']==UPLOAD_ERR_OK) {
- Exclude checks
Blank line found at end of control structure Open
- Exclude checks
Blank line found at start of control structure Open
if( $_FILES['user_photo']['size'] < $maxsize) {
- Exclude checks
Blank line found at start of control structure Open
if(is_uploaded_file($_FILES['user_photo']['tmp_name'])) {
- Exclude checks
Line exceeds 120 characters; contains 139 characters Open
$sql = "INSERT INTO user_photos (user_id, content) VALUES (?, ?) ON DUPLICATE KEY UPDATE content=VALUES(content);";
- Exclude checks
End of line character is invalid; expected "\n" but found "\r\n" Open
<?php
- Exclude checks
Line exceeds 120 characters; contains 128 characters Open
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
- Exclude checks
Whitespace found at end of line Open
if( $_FILES['user_photo']['size'] < $maxsize) {
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
switch($_FILES['user_photo']['error']){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(!$stmt->execute()) {
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_PARTIAL:
- Exclude checks
Expected 1 space after closing parenthesis; found 0 Open
} catch (Exception $e){
- Exclude checks
Whitespace found at end of line Open
if(is_uploaded_file($_FILES['user_photo']['tmp_name'])) {
- Exclude checks
No space found after comma in function call Open
if(strpos(finfo_file($finfo, $_FILES['user_photo']['tmp_name']),"image")===0) {
- Exclude checks
Whitespace found at end of line Open
if(strpos(finfo_file($finfo, $_FILES['user_photo']['tmp_name']),"image")===0) {
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_NO_TMP_DIR:
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_CANT_WRITE:
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(is_uploaded_file($_FILES['user_photo']['tmp_name'])) {
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Expected 1 space after SWITCH keyword; 0 found Open
switch($_FILES['user_photo']['error']){
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if( $_FILES['user_photo']['size'] < $maxsize) {
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_INI_SIZE:
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_NO_FILE:
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_EXTENSION:
- Exclude checks
Expected 0 spaces after opening bracket; 1 found Open
if( $_FILES['user_photo']['size'] < $maxsize) {
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
Opening brace should be on a new line Open
function show_active() {
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
There must be a comment when fall-through is intentional in a non-empty case body Open
case UPLOAD_ERR_FORM_SIZE:
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if($_FILES['user_photo']['error']==UPLOAD_ERR_OK) {
- Exclude checks
Expected 1 space after IF keyword; 0 found Open
if(strpos(finfo_file($finfo, $_FILES['user_photo']['tmp_name']),"image")===0) {
- Exclude checks
Expected 1 space after closing brace; 0 found Open
}else{
- Exclude checks
Expected 1 space after ELSE keyword; 0 found Open
}else{
- Exclude checks
The variable $user_id is not named in camelCase. Open
function show_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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_active() {
//Code based on example at https://vikasmahajan.wordpress.com/2010/07/07/inserting-and-displaying-images-in-mysql-using-php/
include('../mysql_access.php');
$user_id = $_SESSION['sessionID'];
$maxsize = 3000000;
- 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();
}
}