get_current_path accesses the super-global variable $_SERVER. Open
function get_current_path(): string
{
if (strlen((string) $_SERVER['PHP_SELF'])) {
$root = $_SERVER['PHP_SELF'];
} else {
- 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
get_current_path accesses the super-global variable $_SERVER. Open
function get_current_path(): string
{
if (strlen((string) $_SERVER['PHP_SELF'])) {
$root = $_SERVER['PHP_SELF'];
} else {
- 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
apache_request_headers accesses the super-global variable $_SERVER. Open
function apache_request_headers(): array
{
$headers = array();
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
- 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
get_current_path accesses the super-global variable $_SERVER. Open
function get_current_path(): string
{
if (strlen((string) $_SERVER['PHP_SELF'])) {
$root = $_SERVER['PHP_SELF'];
} else {
- 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
catalog_worker accesses the super-global variable $_POST. Open
function catalog_worker($action, $catalogs = null, $options = null): void
{
if (AmpConfig::get('ajax_load')) {
$sse_url = AmpConfig::get('web_path') . "/server/sse.server.php?worker=catalog&action=" . $action . "&catalogs=" . urlencode(json_encode($catalogs));
if ($options) {
- 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 get_languages
has a Cognitive Complexity of 59 (exceeds 5 allowed). Consider refactoring. Open
function get_languages(): array
{
/* Open the locale directory */
$handle = opendir(__DIR__ . '/../../locale');
- 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
File functions.php
has 779 lines of code (exceeds 500 allowed). Consider refactoring. Open
<?php
declare(strict_types=0);
/**
Function apache_request_headers
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
function apache_request_headers(): array
{
$headers = array();
foreach ($_SERVER as $name => $value) {
if (substr($name, 0, 5) == 'HTTP_') {
- 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
Function ampache_error_handler
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
function ampache_error_handler(int $errno, string $errstr, string $errfile, int $errline): bool
{
$level = 1;
switch ($errno) {
- 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
Function check_config_values
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
function check_config_values($conf): bool
{
if (!is_array($conf)) {
return false;
}
- 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
Function show_album_select
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $album_id_cnt = 0;
// Generate key to use for HTML element ID
- 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
Function show_license_select
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
function show_license_select($name, $license_id = 0, $song_id = 0): void
{
static $license_id_cnt = 0;
// Generate key to use for HTML element ID
- 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
Function show_catalog_select
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function show_catalog_select($name, $catalog_id, $style = '', $allow_none = false, $filter_type = ''): void
{
echo "<select name=\"$name\" style=\"$style\">\n";
$params = array();
- 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
Function show_tvshow_season_select
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function show_tvshow_season_select($name, $season_id, $allow_add = false, $video_id = 0, $allow_none = false): bool
{
if (!$season_id) {
return false;
}
- 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_artist_select
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
Function get_themes
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
function get_themes(): array
{
/* Open the themes dir and start reading it */
$handle = opendir(__DIR__ . '/../../public/themes');
- 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_album_select
has 6 arguments (exceeds 4 allowed). Consider refactoring. Open
function show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
Method show_tvshow_season_select
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function show_tvshow_season_select($name, $season_id, $allow_add = false, $video_id = 0, $allow_none = false): bool
Method show_catalog_select
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function show_catalog_select($name, $catalog_id, $style = '', $allow_none = false, $filter_type = ''): void
Method show_tvshow_select
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
function show_tvshow_select($name, $tvshow_id = 0, $allow_add = false, $season_id = 0, $allow_none = false): void
Function show_tvshow_select
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function show_tvshow_select($name, $tvshow_id = 0, $allow_add = false, $season_id = 0, $allow_none = false): void
{
static $tvshow_id_cnt = 0;
// Generate key to use for HTML element ID
if ($season_id) {
- 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
Function show_artist_select
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
function show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $artist_id_cnt = 0;
// Generate key to use for HTML element ID
if ($song_id) {
- 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
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
Function get_theme
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function get_theme($name)
{
static $_mapcache = array();
if (strlen((string) $name) < 1) {
- 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
Function show_table_render
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
function show_table_render($render = false, $force = false): void
{
// Include table render javascript only once
if ($force || !defined('TABLE_RENDERED')) {
if (!defined('TABLE_RENDERED')) {
- 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
The function check_config_values() has an NPath complexity of 768. The configured NPath complexity threshold is 200. Open
function check_config_values($conf): bool
{
if (!is_array($conf)) {
return false;
}
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The function get_languages() has 194 lines of code. Current threshold is set to 100. Avoid really long methods. Open
function get_languages(): array
{
/* Open the locale directory */
$handle = opendir(__DIR__ . '/../../locale');
- Exclude checks
The function get_languages() has a Cyclomatic Complexity of 58. The configured cyclomatic complexity threshold is 10. Open
function get_languages(): array
{
/* Open the locale directory */
$handle = opendir(__DIR__ . '/../../locale');
- 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
The function ampache_error_handler() has a Cyclomatic Complexity of 14. The configured cyclomatic complexity threshold is 10. Open
function ampache_error_handler(int $errno, string $errstr, string $errfile, int $errline): bool
{
$level = 1;
switch ($errno) {
- 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
The function check_config_values() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
function check_config_values($conf): bool
{
if (!is_array($conf)) {
return false;
}
- 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
This function "get_languages" has 193 lines, which is greater than the 150 lines authorized. Split it into smaller functions. Open
function get_languages(): array
- Read upRead up
- Exclude checks
A function that grows too large tends to aggregate too many responsibilities.
Such functions inevitably become harder to understand and therefore harder to maintain.
Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.
Those smaller functions will not only be easier to understand, but also probably easier to test.
Reduce the number of switch cases from 53 to at most 30. Open
switch ($file) {
- Read upRead up
- Exclude checks
When switch
statements have large sets of case
clauses, it is usually an attempt to map two sets of data. A real map
structure would be more readable and maintainable, and should be used instead.
Reduce the number of returns of this function 10, down to the maximum allowed 3. Open
function check_config_values($conf): bool
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
function make_bool($string): bool
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Missing class import via use statement (line '442', column '19'). Open
$format = new IntlDateFormatter($locale, $date_type, $time_type, $timezone, null, $pattern);
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method catalog_worker uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
Catalog::process_action($action, $catalogs, $options);
}
- 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_tvshow_season_select uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$key = $name . "_select_c" . ++$season_id_cnt;
}
- 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 get_theme uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$results = null;
}
- 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 scrub_in uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$results = array();
foreach ($input as $item) {
$results[] = scrub_in((string) $item);
}
- 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 apache_request_headers uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($name == "CONTENT_TYPE") {
$headers["Content-Type"] = $value;
} else {
if ($name == "CONTENT_LENGTH") {
- 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_album_select uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$key = "album_select_c" . ++$album_id_cnt;
}
- 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 get_current_path uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$root = $_SERVER['REQUEST_URI'];
}
- 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_artist_select uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$key = $name . "_select_c" . ++$artist_id_cnt;
}
- 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 xoutput_headers uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
header("Content-type: application/json; charset=" . AmpConfig::get('site_charset'));
}
- 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 apache_request_headers uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
if ($name == "CONTENT_LENGTH") {
$headers["Content-Length"] = $value;
}
}
- 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_tvshow_select uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$key = $name . "_select_c" . ++$tvshow_id_cnt;
}
- 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_license_select uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$key = "license_select_c" . ++$license_id_cnt;
}
- 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 return_referer uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$file = basename($referer);
/* Strip off the filename */
$referer = substr($referer, 0, strlen((string) $referer) - strlen((string) $file));
}
- 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 xoutput_from_array uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return json_encode($array) ?: '';
}
- 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
Define a constant instead of duplicating this literal "fullname" 4 times. Open
$row['fullname'] = $row['fullname'] ? $row['fullname'] : $row['username'];
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "/../../public/rest/.htaccess" 3 times. Open
return ((file_exists(__DIR__ . '/../../public/rest/.htaccess') && is_writeable(__DIR__ . '/../../public/rest/.htaccess')) ||
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Merge this if statement with the enclosing one. Open
if (!isset($conf['log_path'])) {
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Define a constant instead of duplicating this literal "\n" 7 times. Open
echo "</select>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "selected=\"selected\"" 6 times. Open
$selected = "selected=\"selected\"";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Remove this commented out code. Open
* if (!$conf['database_password']) {
- Read upRead up
- Exclude checks
Programmers should not comment out code as it bloats programs and reduces readability.
Unused code should be deleted and can be retrieved from source control history if required.
See
- MISRA C:2004, 2.4 - Sections of code should not be "commented out".
- MISRA C++:2008, 2-7-2 - Sections of code shall not be "commented out" using C-style comments.
- MISRA C++:2008, 2-7-3 - Sections of code should not be "commented out" using C++ comments.
- MISRA C:2012, Dir. 4.4 - Sections of code should not be "commented out"
Merge this if statement with the enclosing one. Open
if ($artist->user !== null && $userId == $artist->user) {
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Define a constant instead of duplicating this literal "xoutput" 4 times. Open
$output = (Core::get_request('xoutput') !== '') ? Core::get_request('xoutput') : 'xml';
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "_select_c" 3 times. Open
$key = $name . "_select_c" . ++$artist_id_cnt;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "TABLE_RENDERED" 3 times. Open
if ($force || !defined('TABLE_RENDERED')) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "\t<option value='\"-2\"'></option>\n" 4 times. Open
echo "\t<option value=\"-2\"></option>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "/../../public/play/.htaccess" 3 times. Open
return ((file_exists(__DIR__ . '/../../public/play/.htaccess') && is_writeable(__DIR__ . '/../../public/play/.htaccess')) ||
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "site_charset" 5 times. Open
return stripslashes(htmlspecialchars(strip_tags((string) $input), ENT_NOQUOTES, AmpConfig::get('site_charset')));
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Add a "case default" clause to this "switch" statement. Open
switch ($last) {
- Read upRead up
- Exclude checks
The requirement for a final case default
clause is defensive programming. The clause should either take appropriate action, or contain
a suitable comment as to why no action is taken. Even when the switch
covers all current values of an enum
, a default case
should still be used because there is no guarantee that the enum
won't be extended.
Noncompliant Code Example
switch ($param) { //missing default clause case 0: do_something(); break; case 1: do_something_else(); break; } switch ($param) { default: // default clause should be the last one error(); break; case 0: do_something(); break; case 1: do_something_else(); break; }
Compliant Solution
switch ($param) { case 0: do_something(); break; case 1: do_something_else(); break; default: error(); break; }
See
- MISRA C:2004, 15.0 - The MISRA C switch syntax shall be used.
- MISRA C:2004, 15.3 - The final clause of a switch statement shall be the default clause
- MISRA C++:2008, 6-4-3 - A switch statement shall be a well-formed switch statement.
- MISRA C++:2008, 6-4-6 - The final clause of a switch statement shall be the default-clause
- MISRA C:2012, 16.1 - All switch statements shall be well-formed
- MISRA C:2012, 16.4 - Every switch statement shall have a default label
- MISRA C:2012, 16.5 - A default label shall appear as either the first or the last switch label of a switch statement
- MITRE, CWE-478 - Missing Default Case in Switch Statement
- CERT, MSC01-C. - Strive for logical completeness
- CERT, MSC01-CPP. - Strive for logical completeness
Define a constant instead of duplicating this literal "/../../config/ampache.cfg.php" 3 times. Open
return ((file_exists(__DIR__ . '/../../config/ampache.cfg.php') && is_writeable(__DIR__ . '/../../config/ampache.cfg.php')) ||
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "\t<option value='\""' times.></option> Open
echo "\t<option value=\"" . $row['id'] . "\" $selected>" . scrub_out($album_name) . "</option>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "...\n" 4 times. Open
echo "\t<option value=\"-1\">" . T_('Add New') . "...</option>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "Add New" 4 times. Open
echo "\t<option value=\"-1\">" . T_('Add New') . "...</option>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "\n" 10 times. Open
echo "\t<option value=\"" . $row['id'] . "\" $selected>" . scrub_out($album_name) . "</option>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "\t<option value='\"-1\"'>" 6 times.</option> Open
echo "\t<option value=\"-1\">" . T_('Add New') . "...</option>\n";
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "_select_" 3 times. Open
$key = $name . "_select_" . $song_id;
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "en_US" 4 times. Open
case 'en_US':
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Avoid unused local variables such as '$results'. Open
$results = Stream::get_now_playing();
- 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
Avoid unused local variables such as '$web_path'. Open
$web_path = AmpConfig::get('web_path');
- 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
Call to method loadTranslations
from undeclared class \Gettext\Translator
Open
$gettext->loadTranslations($translations);
- Exclude checks
Call to method garbage_collection
from undeclared class \Ampache\Module\System\Session
Open
Session::garbage_collection();
- Exclude checks
Call to method __construct
from undeclared class \Gettext\Translator
Open
$gettext = new Translator();
- Exclude checks
Call to undeclared function \__()
(Did you mean _() or \T_()) Open
return __($msgid);
- Exclude checks
Call to method fromMoFile
from undeclared class \Gettext\Translations
Open
$translations = Gettext\Translations::fromMoFile($mopath);
- Exclude checks
Call to method format_bytes
from undeclared class \Ampache\Module\Util\Ui
Open
return Ui::format_bytes($value);
- Exclude checks
Function getallheaders
defined at /code/src/Config/functions.php:388
was previously defined internally Open
function getallheaders(): array
- Exclude checks
Call to deprecated function \debug_event()
defined at /code/src/Config/functions.php:651
Open
debug_event('log.lib', $log_line, $level, 'ampache');
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql, $params);
- Exclude checks
Call to method num_rows
from undeclared class \Ampache\Module\System\Dba
Open
$count = Dba::num_rows($db_results);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\TVShow_Season
Open
$season = new TVShow_Season($season_id);
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to deprecated function \debug_event()
defined at /code/src/Config/functions.php:651
Open
debug_event('themes', "Checking $file", 5);
- Exclude checks
Call to method unformat_bytes
from undeclared class \Ampache\Module\Util\Ui
Open
$new_limit = Ui::unformat_bytes($new_limit);
- Exclude checks
Call to method process_action
from undeclared class \Ampache\Repository\Model\Catalog
Open
Catalog::process_action($action, $catalogs, $options);
- Exclude checks
Call to method find_template
from undeclared class \Ampache\Module\Util\Ui
Open
require_once Ui::find_template('show_now_playing.inc.php');
- Exclude checks
Call to method register
from undeclared class \Gettext\Translator
Open
$gettext->register();
- Exclude checks
Call to deprecated function \debug_event()
defined at /code/src/Config/functions.php:651
Open
debug_event('themes', 'Failed to open /themes directory', 2);
- Exclude checks
Returning type array<int>|array{}</int>
but scrub_in()
is declared to return TType
Open
return $results;
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql, array($season->tvshow));
- Exclude checks
Reference to instance property tvshow
from undeclared class \Ampache\Repository\Model\TVShow_Season
Open
$db_results = Dba::read($sql, array($season->tvshow));
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to deprecated function \debug_event()
defined at /code/src/Config/functions.php:651
Open
debug_event('general.lib', 'Error unable to open locale directory', 1);
- Exclude checks
Call to undeclared function \n__()
(Did you mean \nT_()) Open
return n__($original, $plural, (string)$value);
- Exclude checks
Parameter $artist
has undeclared type \Ampache\Repository\Model\Artist
Open
function canEditArtist(
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to deprecated function \Ampache\Module\System\Core::get_request()
defined at /code/src/Module/System/Core.php:61
Open
$outputnode = Core::get_request('xoutputnode');
- Exclude checks
Call to method unformat_bytes
from undeclared class \Ampache\Module\Util\Ui
Open
$current_limit = Ui::unformat_bytes($current_limit);
- Exclude checks
Call to method num_rows
from undeclared class \Ampache\Module\System\Dba
Open
$count = Dba::num_rows($db_results);
- Exclude checks
Reference to instance property user
from undeclared class \Ampache\Repository\Model\Artist
Open
if ($artist->user !== null && $userId == $artist->user) {
- Exclude checks
Reference to constant class
from undeclared class \Psr\Log\LoggerInterface
Open
$logger = $dic->get(LoggerInterface::class);
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql, $params);
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to deprecated function \Ampache\Module\System\Core::get_request()
defined at /code/src/Module/System/Core.php:61
Open
$output = (Core::get_request('xoutput') !== '') ? Core::get_request('xoutput') : 'xml';
- Exclude checks
Returning type string
but scrub_in()
is declared to return TType
Open
return stripslashes(htmlspecialchars(strip_tags((string) $input), ENT_NOQUOTES, AmpConfig::get('site_charset')));
- Exclude checks
Function apache_request_headers
defined at /code/src/Config/functions.php:363
was previously defined internally Open
function apache_request_headers(): array
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql, $params);
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to deprecated function \Ampache\Module\System\Core::get_request()
defined at /code/src/Module/System/Core.php:61
Open
$output = (Core::get_request('xoutput') !== '') ? Core::get_request('xoutput') : 'xml';
- Exclude checks
Call to method output_xml_from_array
from undeclared class \Ampache\Module\Api\Xml_Data
Open
return Xml_Data::output_xml_from_array($array, $callback, $type);
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
This case's code block is the same as the block for the case on line 500. Open
case 'm':
$val = (int)$val * 1024;
- Read upRead up
- Exclude checks
Having two cases
in a switch
statement or two branches in an if
chain with the same implementation is at
best duplicate code, and at worst a coding error. If the same logic is truly needed for both instances, then in an if
chain they should
be combined, or for a switch
, one should fall through to the other.
Noncompliant Code Example
switch ($i) { case 1: doSomething(); break; case 2: doSomethingDifferent(); break; case 3: // Noncompliant; duplicates case 1's implementation doSomething(); break; default: doTheRest(); } if ($a >= 0 && $a < 10) { doTheThing(); else if ($a >= 10 && $a < 20) { doTheOtherThing(); } else if ($a >= 20 && $a < 50) { doTheThing(); // Noncompliant; duplicates first condition } else { doTheRest(); } if ($b == 0) { doOneMoreThing(); } else { doOneMoreThing(); // Noncompliant; duplicates then-branch } var b = a ? 12 > 4 : 4; // Noncompliant; always results in the same value
Compliant Solution
switch ($i) { case 1: case 3: doSomething(); break; case 2: doSomethingDifferent(); break; default: doTheRest(); } if (($a >= 0 && $a < 10) || ($a >= 20 && $a < 50)) { doTheThing(); else if ($a >= 10 && $a < 20) { doTheOtherThing(); } else { doTheRest(); } doOneMoreThing(); b = 4;
or
switch ($i) { case 1: doSomething(); break; case 2: doSomethingDifferent(); break; case 3: doThirdThing(); break; default: doTheRest(); } if ($a >= 0 && $a < 10) { doTheThing(); else if ($a >= 10 && $a < 20) { doTheOtherThing(); } else if ($a >= 20 && $a < 50) { doTheThirdThing(); } else { doTheRest(); } if ($b == 0) { doOneMoreThing(); } else { doTheRest(); } int b = a ? 12 > 4 : 8;
Exceptions
Blocks in an if
chain that contain a single line of code are ignored, as are blocks in a switch
statement that contain a
single line of code with or without a following break
.
Similar blocks of code found in 2 locations. Consider refactoring. Open
function debug_result($status = false, $value = null, $comment = ''): string
{
$class = $status ? 'success' : 'danger';
if ($value === null) {
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 114.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid using short method names like ::T_(). The configured minimum method name length is 3. Open
function T_(string $msgid): string
{
if (function_exists('__')) {
return __($msgid);
}
- Read upRead up
- Exclude checks
ShortMethodName
Since: 0.2
Detects when very short method names are used.
Example
class ShortMethod {
public function a( $index ) { // Violation
}
}
Source https://phpmd.org/rules/naming.html#shortmethodname
The parameter $season_id is not named in camelCase. Open
function show_tvshow_season_select($name, $season_id, $allow_add = false, $video_id = 0, $allow_none = false): bool
{
if (!$season_id) {
return false;
}
- 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 $catalog_id is not named in camelCase. Open
function show_catalog_select($name, $catalog_id, $style = '', $allow_none = false, $filter_type = ''): void
{
echo "<select name=\"$name\" style=\"$style\">\n";
$params = array();
- 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 $license_id is not named in camelCase. Open
function show_license_select($name, $license_id = 0, $song_id = 0): void
{
static $license_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $season_id is not named in camelCase. Open
function show_tvshow_select($name, $tvshow_id = 0, $allow_add = false, $season_id = 0, $allow_none = false): void
{
static $tvshow_id_cnt = 0;
// Generate key to use for HTML element ID
if ($season_id) {
- 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 show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $album_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $allow_add is not named in camelCase. Open
function show_tvshow_select($name, $tvshow_id = 0, $allow_add = false, $season_id = 0, $allow_none = false): void
{
static $tvshow_id_cnt = 0;
// Generate key to use for HTML element ID
if ($season_id) {
- 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 $artist_id is not named in camelCase. Open
function show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $artist_id_cnt = 0;
// Generate key to use for HTML element ID
if ($song_id) {
- 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 $song_id is not named in camelCase. Open
function show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $album_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $date_format is not named in camelCase. Open
function get_datetime($time, $date_format = 'short', $time_format = 'short', $overwrite = ''): string
{
if ($time instanceof DateTimeInterface) {
$time = $time->getTimestamp();
}
- 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 $song_id is not named in camelCase. Open
function show_license_select($name, $license_id = 0, $song_id = 0): void
{
static $license_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $new_limit is not named in camelCase. Open
function set_memory_limit($new_limit): void
{
$current_limit = ini_get('memory_limit');
if ($current_limit == -1) {
return;
- 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 $allow_add is not named in camelCase. Open
function show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $album_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $allow_none is not named in camelCase. Open
function show_tvshow_season_select($name, $season_id, $allow_add = false, $video_id = 0, $allow_none = false): bool
{
if (!$season_id) {
return false;
}
- 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 $filter_type is not named in camelCase. Open
function show_catalog_select($name, $catalog_id, $style = '', $allow_none = false, $filter_type = ''): void
{
echo "<select name=\"$name\" style=\"$style\">\n";
$params = array();
- 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 $allow_add is not named in camelCase. Open
function show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $artist_id_cnt = 0;
// Generate key to use for HTML element ID
if ($song_id) {
- 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 $allow_none is not named in camelCase. Open
function show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $album_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $tvshow_id is not named in camelCase. Open
function show_tvshow_select($name, $tvshow_id = 0, $allow_add = false, $season_id = 0, $allow_none = false): void
{
static $tvshow_id_cnt = 0;
// Generate key to use for HTML element ID
if ($season_id) {
- 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 $album_id is not named in camelCase. Open
function show_album_select($name, $album_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $album_id_cnt = 0;
// Generate key to use for HTML element ID
- 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 $song_id is not named in camelCase. Open
function show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $artist_id_cnt = 0;
// Generate key to use for HTML element ID
if ($song_id) {
- 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 show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $artist_id_cnt = 0;
// Generate key to use for HTML element ID
if ($song_id) {
- 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 $time_format is not named in camelCase. Open
function get_datetime($time, $date_format = 'short', $time_format = 'short', $overwrite = ''): string
{
if ($time instanceof DateTimeInterface) {
$time = $time->getTimestamp();
}
- 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 $allow_none is not named in camelCase. Open
function show_artist_select($name, $artist_id = 0, $allow_add = false, $song_id = 0, $allow_none = false, $user_id = null): void
{
static $artist_id_cnt = 0;
// Generate key to use for HTML element ID
if ($song_id) {
- 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 $allow_none is not named in camelCase. Open
function show_catalog_select($name, $catalog_id, $style = '', $allow_none = false, $filter_type = ''): void
{
echo "<select name=\"$name\" style=\"$style\">\n";
$params = array();
- 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 $allow_add is not named in camelCase. Open
function show_tvshow_season_select($name, $season_id, $allow_add = false, $video_id = 0, $allow_none = false): bool
{
if (!$season_id) {
return false;
}
- 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 $video_id is not named in camelCase. Open
function show_tvshow_season_select($name, $season_id, $allow_add = false, $video_id = 0, $allow_none = false): bool
{
if (!$season_id) {
return false;
}
- 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 $allow_none is not named in camelCase. Open
function show_tvshow_select($name, $tvshow_id = 0, $allow_add = false, $season_id = 0, $allow_none = false): void
{
static $tvshow_id_cnt = 0;
// Generate key to use for HTML element ID
if ($season_id) {
- 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 indented incorrectly; expected 0 spaces, found 8 Open
}
- Exclude checks