File Query.php
has 888 lines of code (exceeds 500 allowed). Consider refactoring. Open
<?php
declare(strict_types=0);
/**
Query
has 51 functions (exceeds 20 allowed). Consider refactoring. Open
class Query
{
private const SORT_STATE = [
'last_update' => 'ASC',
'original_year' => 'ASC',
Function set_type
has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring. Open
public function set_type($type, $custom_base = ''): void
{
switch ($type) {
case 'album':
$this->queryType = new AlbumQuery();
- 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 class Query has an overall complexity of 288 which is very high. The configured complexity threshold is 50. Open
class Query
{
private const SORT_STATE = [
'last_update' => 'ASC',
'original_year' => 'ASC',
- Exclude checks
Function set_filter
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public function set_filter($key, $value): bool
{
switch ($key) {
case 'album_artist':
case 'album_disk':
- 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 sql_sort_video
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function sql_sort_video(string $field, string $order, ?string $table = 'video'): string
{
$sql = "";
switch ($field) {
case 'addition_time':
- 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 set_join_and_and
has 9 arguments (exceeds 4 allowed). Consider refactoring. Open
public function set_join_and_and($type, $table, $source1, $dest1, $source2, $dest2, $source3, $dest3, $priority): void
Function _resort_objects
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function _resort_objects(): bool
{
// There are two ways to do this.. the easy way...
// and the vollmer way, hopefully we don't have to
// do it the vollmer way
- 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 _set_base_sql
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function _set_base_sql($force = false, $custom_base = ''): void
{
// Only allow it to be set once
if (!empty((string)$this->_state['base']) && !$force) {
return;
- 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 set_join_and
has 7 arguments (exceeds 4 allowed). Consider refactoring. Open
public function set_join_and($type, $table, $source1, $dest1, $source2, $dest2, $priority): void
Function _get_filter_sql
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function _get_filter_sql(): string
{
if (!is_array($this->_state['filter'])) {
return '';
}
- 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 __construct
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($query_id = 0, $cached = true)
{
$sid = session_id();
if (!$cached) {
- 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 set_join
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
public function set_join($type, $table, $source, $dest, $priority): void
Function _get_limit_sql
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function _get_limit_sql(): string
{
$offset = $this->get_offset();
if ($this->_state['limit'] > 0) {
if ($offset > 0) {
- 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 LiveStreamQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PlaylistLocalplayQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PvmsgQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PodcastEpisodeQuery::FILTERS;
Avoid too many return
statements within this method. Open
return SmartPlaylistQuery::FILTERS;
Avoid too many return
statements within this method. Open
return UserQuery::FILTERS;
Avoid too many return
statements within this method. Open
return SongQuery::FILTERS;
Avoid too many return
statements within this method. Open
return WantedQuery::FILTERS;
Avoid too many return
statements within this method. Open
return SongPreviewQuery::FILTERS;
Avoid too many return
statements within this method. Open
return TvshowEpisodeQuery::FILTERS;
Avoid too many return
statements within this method. Open
return TagQuery::FILTERS;
Avoid too many return
statements within this method. Open
return LabelQuery::FILTERS;
Avoid too many return
statements within this method. Open
return MovieQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PlaylistSearchQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PlaylistMediaQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PodcastQuery::FILTERS;
Avoid too many return
statements within this method. Open
return TvshowQuery::FILTERS;
Avoid too many return
statements within this method. Open
return [];
Avoid too many return
statements within this method. Open
return;
Avoid too many return
statements within this method. Open
return FollowerQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PersonalVideoQuery::FILTERS;
Avoid too many return
statements within this method. Open
return TvshowSeasonQuery::FILTERS;
Avoid too many return
statements within this method. Open
return ClipQuery::FILTERS;
Avoid too many return
statements within this method. Open
return LicenseQuery::FILTERS;
Avoid too many return
statements within this method. Open
return ShoutboxQuery::FILTERS;
Avoid too many return
statements within this method. Open
return PlaylistQuery::FILTERS;
Avoid too many return
statements within this method. Open
return ShareQuery::FILTERS;
Avoid too many return
statements within this method. Open
return CatalogQuery::FILTERS;
Avoid too many return
statements within this method. Open
return DemocraticQuery::FILTERS;
Avoid too many return
statements within this method. Open
return VideoQuery::FILTERS;
Function _post_process
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function _post_process($data): array
{
$tags = $this->_state['filter']['tag'] ?? '';
if (!is_array($tags) || sizeof($tags) < 2) {
- 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 _get_sql
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function _get_sql($limit = true): string
{
if ($this->_state['custom']) {
// custom queries are set by base and should not be added to
$final_sql = $this->_get_base_sql();
- 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 method set_type() has 107 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function set_type($type, $custom_base = ''): void
{
switch ($type) {
case 'album':
$this->queryType = new AlbumQuery();
- Exclude checks
The method _get_filter_sql() has an NPath complexity of 528. The configured NPath complexity threshold is 200. Open
private function _get_filter_sql(): string
{
if (!is_array($this->_state['filter'])) {
return '';
}
- 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 class Query has 1338 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Query
{
private const SORT_STATE = [
'last_update' => 'ASC',
'original_year' => 'ASC',
- Exclude checks
The method get_allowed_filters() has a Cyclomatic Complexity of 34. The configured cyclomatic complexity threshold is 10. Open
public static function get_allowed_filters($type): array
{
switch ($type) {
case 'album':
return AlbumQuery::FILTERS;
- 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 method _get_filter_sql() has a Cyclomatic Complexity of 28. The configured cyclomatic complexity threshold is 10. Open
private function _get_filter_sql(): string
{
if (!is_array($this->_state['filter'])) {
return '';
}
- 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 method sql_sort_video() has a Cyclomatic Complexity of 16. The configured cyclomatic complexity threshold is 10. Open
public function sql_sort_video(string $field, string $order, ?string $table = 'video'): string
{
$sql = "";
switch ($field) {
case 'addition_time':
- 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 method set_filter() has a Cyclomatic Complexity of 54. The configured cyclomatic complexity threshold is 10. Open
public function set_filter($key, $value): bool
{
switch ($key) {
case 'album_artist':
case 'album_disk':
- 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 method set_type() has a Cyclomatic Complexity of 35. The configured cyclomatic complexity threshold is 10. Open
public function set_type($type, $custom_base = ''): void
{
switch ($type) {
case 'album':
$this->queryType = new AlbumQuery();
- 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
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
private function _get_limit_sql(): string
- 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 33, down to the maximum allowed 3. Open
public static function get_allowed_filters($type): array
- 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; }
This function has 9 parameters, which is greater than the 7 authorized. Open
public function set_join_and_and($type, $table, $source1, $dest1, $source2, $dest2, $source3, $dest3, $priority): void
- Read upRead up
- Exclude checks
A long parameter list can indicate that a new structure should be created to wrap the numerous parameters or that the function is doing too many things.
Noncompliant Code Example
With a maximum number of 4 parameters:
function doSomething($param1, $param2, $param3, $param4, $param5) { ... }
Compliant Solution
function doSomething($param1, $param2, $param3, $param4) { ... }
Reduce the number of returns of this function 5, down to the maximum allowed 3. Open
public function __construct($query_id = 0, $cached = true)
- 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; }
Refactor this function to reduce its Cognitive Complexity from 17 to the 15 allowed. Open
public function set_filter($key, $value): bool
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Class "Query" has 51 methods, which is greater than 20 authorized. Split it into smaller classes. Open
class Query
- Read upRead up
- Exclude checks
A class that grows too much tends to aggregate too many responsibilities and inevitably becomes harder to understand and therefore to maintain. Above a specific threshold, it is strongly advised to refactor the class into smaller ones which focus on well defined topics.
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
public function get_saved(): array
- 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 switch cases from 33 to at most 30. Open
switch ($type) {
- 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 switch cases from 33 to at most 30. Open
switch ($type) {
- 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 switch cases from 47 to at most 30. Open
switch ($key) {
- 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.
The class Query has a coupling between objects value of 38. Consider to reduce the number of dependencies under 13. Open
class Query
{
private const SORT_STATE = [
'last_update' => 'ASC',
'original_year' => 'ASC',
- Read upRead up
- Exclude checks
CouplingBetweenObjects
Since: 1.1.0
A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability
Example
class Foo {
/**
* @var \foo\bar\X
*/
private $x = null;
/**
* @var \foo\bar\Y
*/
private $y = null;
/**
* @var \foo\bar\Z
*/
private $z = null;
public function setFoo(\Foo $foo) {}
public function setBar(\Bar $bar) {}
public function setBaz(\Baz $baz) {}
/**
* @return \SplObjectStorage
* @throws \OutOfRangeException
* @throws \InvalidArgumentException
* @throws \ErrorException
*/
public function process(\Iterator $it) {}
// ...
}
Source https://phpmd.org/rules/design.html#couplingbetweenobjects
The method _get_limit_sql uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
return ' LIMIT ' . (string)($this->_state['limit']);
}
- 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 _set_base_sql uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// TODO we should remove this default fallback and rely on set_type()
if ($this->queryType === null) {
$this->queryType = new SongQuery();
}
- 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 set_filter uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->_state['filter'][$key] = 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
The method set_sort uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// if the sort already exists you want the reverse
$state = (array_key_exists($sort, $this->_state['sort']))
? $this->_state['sort'][$sort]
: self::SORT_STATE[$sort] ?? 'DESC';
- 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 set_filter uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->_state['filter'][$key] = 1;
}
- 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 assigning values to variables in if clauses and the like (line '177', column '17'). Open
public function __construct($query_id = 0, $cached = true)
{
$sid = session_id();
if (!$cached) {
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
The method _get_sql uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// filter and sort set joins as well as group so make sure you run those first
$filter_sql = $this->_get_filter_sql();
$sort_sql = $this->_get_sort_sql();
// regular queries need to be joined with all the other parts
- 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 _resort_objects uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
// FIXME: this is fragile for large browses
// First pull the objects
$objects = $this->get_saved();
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$sql = 'SELECT `data` FROM `tmp_browse` WHERE `id` = ? AND `sid` = ?';
$db_results = Dba::read($sql, array($query_id, $sid));
if ($results = Dba::fetch_assoc($db_results)) {
- 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 "tvshow_season" 3 times. Open
case 'tvshow_season':
- 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 "playlist" 3 times. Open
case 'playlist':
- 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 "start" 3 times. Open
'start' => 0,
- 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 "simple" 3 times. Open
'simple' => false,
- 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 "video" 6 times. Open
case 'video':
- 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 "regex_not_match" 3 times. Open
case 'regex_not_match':
- 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 "album_disk" 5 times. Open
case 'album_disk':
- 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 "share" 3 times. Open
case 'share':
- 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 "live_stream" 3 times. Open
case 'live_stream':
- 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 "podcast_episode" 3 times. Open
case 'podcast_episode':
- 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 "catalog" 4 times. Open
case 'catalog':
- 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 "total" 7 times. Open
'total' => null,
- 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 "artist" 6 times. Open
case 'artist':
- 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 "extended_key_name" 4 times. Open
'extended_key_name' => null,
- 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.
Take the required action to fix the issue indicated by this "FIXME" comment. Open
// FIXME: this is fragile for large browses
- Read upRead up
- Exclude checks
FIXME
tags are commonly used to mark places where a bug is suspected, but which the developer wants to deal with later.
Sometimes the developer will not have the time or will simply forget to get back to that tag.
This rule is meant to track those tags and to ensure that they do not go unnoticed.
Noncompliant Code Example
function divide($numerator, $denominator) { return $numerator / $denominator; // FIXME denominator value might be 0 }
See
- MITRE, CWE-546 - Suspicious Comment
Define a constant instead of duplicating this literal ".
id`" 3 times. Open
$dis = Catalog::get_enable_filter($type, '`' . $type . '`.`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 "limit" 5 times. Open
'limit' => 0,
- 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 "tvshow" 3 times. Open
case 'tvshow':
- 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 "label" 4 times. Open
case 'label':
- 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 "regex_match" 3 times. Open
case 'regex_match':
- 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 "nocache" 3 times. Open
$this->id = 'nocache';
- 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 " LIMIT " 3 times. Open
return ' LIMIT ' . (string)($this->_state['limit']) . ', ' . (string)($offset);
- 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 "song_artist" 3 times. Open
'song_artist' => null, // Used by $browse->set_type() to filter artists
- 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 "custom" 3 times. Open
'custom' => false,
- 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 "filter" 19 times. Open
'filter' => array(),
- 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 the unused function parameter "$object_id". Open
private function _logic_filter($object_id): bool
- Read upRead up
- Exclude checks
Unused parameters are misleading. Whatever the value passed to such parameters is, the behavior will be the same.
Noncompliant Code Example
function doSomething($a, $b) { // "$a" is unused return compute($b); }
Compliant Solution
function doSomething($b) { return compute($b); }
Exceptions
Functions in classes that override a class or implement interfaces are ignored.
class C extends B { function doSomething($a, $b) { // no issue reported on $b compute($a); } }
See
- MISRA C++:2008, 0-1-11 - There shall be no unused parameters (named or unnamed) in nonvirtual functions.
- MISRA C:2012, 2.7 - There should be no unused parameters in functions
- CERT, MSC12-C. - Detect and remove code that has no effect or is never executed
- CERT, MSC12-CPP. - Detect and remove code that has no effect
Define a constant instead of duplicating this literal "tvshow_episode" 3 times. Open
case 'tvshow_episode':
- 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" 5 times. Open
'select' => array(),
- 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 "tag_hidden" 3 times. Open
case 'tag_hidden':
- 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 "podcast" 4 times. Open
case 'podcast':
- 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 "having" 4 times. Open
'having' => '', // HAVING is not currently used in Query SQL
- 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 "license" 3 times. Open
case 'license':
- 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 "hidden" 3 times. Open
case 'hidden':
- 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 "ORDER BY " 3 times. Open
$sql = 'ORDER BY ';
- 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 "static" 3 times. Open
'static' => false,
- 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 "movie" 3 times. Open
case 'movie':
- 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 "video
.id
" 3 times. Open
$this->set_join_and_and('LEFT', "`rating`", "`rating`.`object_id`", "`video`.`id`", "`rating`.`object_type`", "'video'", "`rating`.`user`", (string)$this->user_id, 100);
- 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 "group" 5 times. Open
'group' => array(),
- 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 ($field) {
- 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
Add a "case default" clause to this "switch" statement. Open
switch ($type) {
- 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 "offset" 3 times. Open
'offset' => 0,
- 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
//debug_event(self::class, "_resort_objects: " . $sql, 5);
- 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"
Remove this commented out code. Open
//debug_event(self::class, 'get_objects query: ' . $sql, 5);
- 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"
Add a "case default" clause to this "switch" statement. Open
switch ($type) {
- 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 "album" 6 times. Open
case 'album':
- 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 "personal_video" 3 times. Open
case 'personal_video':
- 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 ($type) {
- 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
Remove this commented out code. Open
//debug_event(self::class, "get_sql: " . $final_sql, 5);
- 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"
TODO found Open
// TODO we should remove this default fallback and rely on set_type()
- Exclude checks
TODO found Open
* before returning them. TODO this is only for tags/genres? should do this in the select/return if possible
- Exclude checks
TODO found Open
return true; // TODO, this must be old so probably not needed
- Exclude checks
FIXME found Open
// FIXME: this is fragile for large browses
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\ArtistQuery
Open
return ArtistQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\DemocraticQuery
Open
return DemocraticQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\BroadcastQuery
Open
return BroadcastQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\ClipQuery
Open
return ClipQuery::FILTERS;
- Exclude checks
Returning type null
but get_total()
is declared to return int
Open
return $this->_state['total'];
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($this->_get_sql(false));
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql, array($query_id, $sid));
- Exclude checks
Call to method write
from undeclared class \Ampache\Module\System\Dba
Open
Dba::write($sql);
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\CatalogQuery
Open
return CatalogQuery::FILTERS;
- Exclude checks
Call to deprecated function \debug_event()
defined at /code/src/Config/functions.php:651
Open
debug_event(self::class, 'IGNORED set_filter ' . $this->get_type() . ': ' . $key, 5);
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\FollowerQuery
Open
return FollowerQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\AlbumQuery
Open
return AlbumQuery::FILTERS;
- Exclude checks
Call to method insert_id
from undeclared class \Ampache\Module\System\Dba
Open
$insert_id = Dba::insert_id();
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\AlbumDiskQuery
Open
return AlbumDiskQuery::FILTERS;
- Exclude checks
Call to method write
from undeclared class \Ampache\Module\System\Dba
Open
Dba::write($sql, array($sid, $data));
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
if ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Invalid offset "playlist_type"
of array type array{}
Open
$this->_state['filter'][$key] = ($this->_state['filter'][$key] == 1) ? 0 : 1;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\LabelQuery
Open
return LabelQuery::FILTERS;
- Exclude checks
Call to method num_rows
from undeclared class \Ampache\Module\System\Dba
Open
$num_rows = Dba::num_rows($db_results);
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\TvshowEpisodeQuery
Open
return TvshowEpisodeQuery::FILTERS;
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\ArtistQuery
Open
$this->queryType = new ArtistQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\DemocraticQuery
Open
$this->queryType = new DemocraticQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\FollowerQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new FollowerQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PersonalVideoQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PersonalVideoQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PlaylistLocalplayQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PlaylistLocalplayQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\ShoutboxQuery
Open
$this->queryType = new ShoutboxQuery();
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\SongQuery
Open
$this->queryType = new SongQuery();
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PvmsgQuery
Open
return PvmsgQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\ShoutboxQuery
Open
return ShoutboxQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\AlbumQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new AlbumQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\AlbumDiskQuery
Open
$this->queryType = new AlbumDiskQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\FollowerQuery
Open
$this->queryType = new FollowerQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PlaylistMediaQuery
Open
$this->queryType = new PlaylistMediaQuery();
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PlaylistQuery
Open
return PlaylistQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\SongPreviewQuery
Open
return SongPreviewQuery::FILTERS;
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\BroadcastQuery
Open
$this->queryType = new BroadcastQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\LicenseQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new LicenseQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PodcastQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PodcastQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\ShoutboxQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new ShoutboxQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\WantedQuery
Open
$this->queryType = new WantedQuery();
- Exclude checks
null
passed to foreach instead of array Open
foreach ($this->_state['join'] as $joins) {
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\SongQuery
Open
return SongQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\AlbumDiskQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new AlbumDiskQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PlaylistLocalplayQuery
Open
$this->queryType = new PlaylistLocalplayQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PlaylistMediaQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PlaylistMediaQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PvmsgQuery
Open
$this->queryType = new PvmsgQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\SongPreviewQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new SongPreviewQuery();
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($data = Dba::fetch_assoc($db_results)) {
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PodcastEpisodeQuery
Open
return PodcastEpisodeQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PodcastQuery
Open
return PodcastQuery::FILTERS;
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PlaylistQuery
Open
$this->queryType = new PlaylistQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PodcastQuery
Open
$this->queryType = new PodcastQuery();
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
$results = Dba::fetch_assoc($db_results);
- Exclude checks
Assigning \Ampache\Module\Database\Query\SongQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new SongQuery();
- Exclude checks
Invalid offset "tag"
of array type array{}
Open
$tags = $this->_state['filter']['tag'] ?? '';
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\CatalogQuery
Open
$this->queryType = new CatalogQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\LabelQuery
Open
$this->queryType = new LabelQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\SongQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new SongQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\SongQuery
Open
$this->queryType = new SongQuery();
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\LicenseQuery
Open
return LicenseQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\BroadcastQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new BroadcastQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\ClipQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new ClipQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\MovieQuery
Open
$this->queryType = new MovieQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PodcastEpisodeQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PodcastEpisodeQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\VideoQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new VideoQuery();
- Exclude checks
Call to deprecated function \debug_event()
defined at /code/src/Config/functions.php:651
Open
debug_event(self::class, 'IGNORED set_sort ' . $this->get_type() . ': ' . $sort, 5);
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Assigning \Ampache\Module\Database\Query\MovieQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new MovieQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PvmsgQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PvmsgQuery();
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql, array(session_id(), $this->id));
- Exclude checks
Call to method get_user_filter
from undeclared class \Ampache\Repository\Model\Catalog
Open
$dis = Catalog::get_user_filter($type, $this->user_id);
- Exclude checks
Call to method write
from undeclared class \Ampache\Module\System\Dba
Open
Dba::write($sql, array($data, session_id(), $browse_id));
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PersonalVideoQuery
Open
return PersonalVideoQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\CatalogQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new CatalogQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\ClipQuery
Open
$this->queryType = new ClipQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PlaylistSearchQuery
Open
$this->queryType = new PlaylistSearchQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\ShareQuery
Open
$this->queryType = new ShareQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\TvshowEpisodeQuery
Open
$this->queryType = new TvshowEpisodeQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\TvshowQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new TvshowQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\UserQuery
Open
$this->queryType = new UserQuery();
- Exclude checks
Call to method get_enable_filter
from undeclared class \Ampache\Repository\Model\Catalog
Open
$dis = Catalog::get_enable_filter($type, '`' . $type . '`.`id`');
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\LiveStreamQuery
Open
return LiveStreamQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\VideoQuery
Open
return VideoQuery::FILTERS;
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\LicenseQuery
Open
$this->queryType = new LicenseQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PersonalVideoQuery
Open
$this->queryType = new PersonalVideoQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\TvshowSeasonQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new TvshowSeasonQuery();
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PlaylistMediaQuery
Open
return PlaylistMediaQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PlaylistSearchQuery
Open
return PlaylistSearchQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\SmartplaylistQuery
Open
return SmartPlaylistQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\TagQuery
Open
return TagQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\TvshowSeasonQuery
Open
return TvshowSeasonQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\DemocraticQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new DemocraticQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\LiveStreamQuery
Open
$this->queryType = new LiveStreamQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\SmartplaylistQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new SmartPlaylistQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\SmartplaylistQuery
Open
$this->queryType = new SmartPlaylistQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\TvshowQuery
Open
$this->queryType = new TvshowQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\UserQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new UserQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\VideoQuery
Open
$this->queryType = new VideoQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\WantedQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new WantedQuery();
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to method write
from undeclared class \Ampache\Module\System\Dba
Open
Dba::write($sql, array($data, session_id(), $browse_id));
- Exclude checks
Assigning \Ampache\Module\Database\Query\PlaylistSearchQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PlaylistSearchQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\PlaylistQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new PlaylistQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\SongPreviewQuery
Open
$this->queryType = new SongPreviewQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\TagQuery
Open
$this->queryType = new TagQuery();
- Exclude checks
Suspicious type null
of a variable or expression used to build a string. (Expected type to be able to cast to a string) Open
$key .= '_' . $this->_state['extended_key_name'];
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\PlaylistLocalplayQuery
Open
return PlaylistLocalplayQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\ShareQuery
Open
return ShareQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\ArtistQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new ArtistQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\LiveStreamQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new LiveStreamQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\PodcastEpisodeQuery
Open
$this->queryType = new PodcastEpisodeQuery();
- Exclude checks
Call to method escape
from undeclared class \Ampache\Module\System\Dba
Open
$object_id = Dba::escape($object_id);
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\MovieQuery
Open
return MovieQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\TvshowQuery
Open
return TvshowQuery::FILTERS;
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\WantedQuery
Open
return WantedQuery::FILTERS;
- Exclude checks
Assigning \Ampache\Module\Database\Query\TagQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new TagQuery();
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\TvshowSeasonQuery
Open
$this->queryType = new TvshowSeasonQuery();
- Exclude checks
Reference to constant FILTERS
from undeclared class \Ampache\Module\Database\Query\UserQuery
Open
return UserQuery::FILTERS;
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Module\Database\Query\AlbumQuery
Open
$this->queryType = new AlbumQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\LabelQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new LabelQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\ShareQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new ShareQuery();
- Exclude checks
Assigning \Ampache\Module\Database\Query\TvshowEpisodeQuery
to property but \Ampache\Repository\Model\Query->queryType
is \Ampache\Module\Database\Query\QueryInterface|null
Open
$this->queryType = new TvshowEpisodeQuery();
- Exclude checks
The parameter $query_id is not named in camelCase. Open
public function __construct($query_id = 0, $cached = true)
{
$sid = session_id();
if (!$cached) {
- 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 $object_id is not named in camelCase. Open
private function _logic_filter($object_id): bool
{
return true; // TODO, this must be old so probably not needed
}
- 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
Avoid variables with short names like $id. Configured minimum length is 3. Open
public $id;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
The parameter $custom_base is not named in camelCase. Open
public function set_type($type, $custom_base = ''): void
{
switch ($type) {
case 'album':
$this->queryType = new AlbumQuery();
- 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_number is not named in camelCase. Open
public function set_catalog($catalog_number): void
{
$this->catalog = $catalog_number;
}
- 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 $custom_base is not named in camelCase. Open
private function _set_base_sql($force = false, $custom_base = ''): void
{
// Only allow it to be set once
if (!empty((string)$this->_state['base']) && !$force) {
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 $object_ids is not named in camelCase. Open
public function save_objects($object_ids): bool
{
// Saving these objects has two operations, one holds it in
// a local variable and then second holds it in a row in the
// tmp_browse table
- 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
Method name "_get_having_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_having_sql(): string
- Exclude checks
Method name "_get_group_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_group_sql(): string
- Exclude checks
Property name "$_state" should not be prefixed with an underscore to indicate visibility Open
protected $_state = array(
- Exclude checks
Method name "_serialize" should not be prefixed with an underscore to indicate visibility Open
private static function _serialize($data): string
- Exclude checks
Method name "_get_filter_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_filter_sql(): string
- Exclude checks
Method name "_get_join_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_join_sql(): string
- Exclude checks
Method name "_logic_filter" should not be prefixed with an underscore to indicate visibility Open
private function _logic_filter($object_id): bool
- Exclude checks
Method name "_get_select" should not be prefixed with an underscore to indicate visibility Open
private function _get_select(): string
- Exclude checks
Method name "_get_sort_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_sort_sql(): string
- Exclude checks
Method name "_sql_sort" should not be prefixed with an underscore to indicate visibility Open
private function _sql_sort($field, $order): string
- Exclude checks
Method name "_post_process" should not be prefixed with an underscore to indicate visibility Open
private function _post_process($data): array
- Exclude checks
Method name "_get_base_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_base_sql(): string
- Exclude checks
Method name "_get_limit_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_limit_sql(): string
- Exclude checks
Method name "_get_sql" should not be prefixed with an underscore to indicate visibility Open
private function _get_sql($limit = true): string
- Exclude checks
Method name "_set_base_sql" should not be prefixed with an underscore to indicate visibility Open
private function _set_base_sql($force = false, $custom_base = ''): void
- Exclude checks
Property name "$_cache" should not be prefixed with an underscore to indicate visibility Open
protected $_cache;
- Exclude checks
Method name "_resort_objects" should not be prefixed with an underscore to indicate visibility Open
private function _resort_objects(): bool
- Exclude checks
Method name "_unserialize" should not be prefixed with an underscore to indicate visibility Open
private static function _unserialize($data)
- Exclude checks
Method name "_sql_filter" should not be prefixed with an underscore to indicate visibility Open
private function _sql_filter($filter, $value): string
- Exclude checks
Expected 0 spaces after opening bracket; newline found Open
if (
- Exclude checks