File Search.php
has 1412 lines of code (exceeds 500 allowed). Consider refactoring. Open
<?php
declare(strict_types=0);
/**
Function _get_rule_name
has a Cognitive Complexity of 45 (exceeds 5 allowed). Consider refactoring. Open
private function _get_rule_name($name): string
{
// check that the rule you sent is not an alias (needed for pulling details from the rule)
switch ($this->objectType) {
case 'song':
- 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
Search
has 43 functions (exceeds 20 allowed). Consider refactoring. Open
class Search extends playlist_object
{
protected const DB_TABLENAME = 'search';
public const VALID_TYPES = array(
'song',
Function __construct
has a Cognitive Complexity of 30 (exceeds 5 allowed). Consider refactoring. Open
public function __construct($search_id = 0, $object_type = 'song', ?User $user = null)
{
$this->search_user = $user;
if (!$this->search_user instanceof User) {
$this->search_user = User::get_from_global() ?? new User(-1);
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
The class Search has an overall complexity of 243 which is very high. The configured complexity threshold is 50. Open
class Search extends playlist_object
{
protected const DB_TABLENAME = 'search';
public const VALID_TYPES = array(
'song',
- Exclude checks
The class Search has 28 non-getter- and setter-methods. Consider refactoring Search to keep number of methods under 25. Open
class Search extends playlist_object
{
protected const DB_TABLENAME = 'search';
public const VALID_TYPES = array(
'song',
- Read upRead up
- Exclude checks
TooManyMethods
Since: 0.1
A class with too many methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.
By default it ignores methods starting with 'get' or 'set'.
The default was changed from 10 to 25 in PHPMD 2.3.
Example
Source https://phpmd.org/rules/codesize.html#toomanymethods
Method _set_basetypes
has 232 lines of code (exceeds 200 allowed). Consider refactoring. Open
private function _set_basetypes(): void
{
$this->basetypes['numeric'][] = array(
'name' => 'gte',
'description' => T_('is greater than or equal to'),
Function _filter_request
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private static function _filter_request($data): array
{
$request = array();
foreach ($data as $key => $value) {
$prefix = substr($key, 0, 4);
- 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_rules
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public function set_rules($data): void
{
if (isset($data['playlist_name'])) {
$this->name = (string)$data['playlist_name'];
}
- 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_types_song
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
private function _set_types_song(): void
{
$this->_add_type_text('anywhere', T_('Any searchable text'));
$t_song_data = T_('Song Data');
- 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 run
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public static function run($data, $user = null, $require_rules = false): array
{
$limit = (int)($data['limit'] ?? 0);
$offset = (int)($data['offset'] ?? 0);
$random = ((int)($data['random'] ?? 0) > 0) ? 1 : 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
Function _set_types_album
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
private function _set_types_album(): void
{
$t_album_data = T_('Album Data');
$this->_add_type_text('title', T_('Title'), $t_album_data);
$this->_add_type_text('artist', T_('Album Artist'), $t_album_data);
- 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 _add_type_select
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
private function _add_type_select($name, $label, $type, $array, $group = ''): void
Function _set_types_artist
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
private function _set_types_artist(): void
{
$t_artist_data = T_('Artist Data');
$this->_add_type_text('title', T_('Name'), $t_artist_data);
$this->_add_type_text('album', T_('Album Title'), $t_artist_data);
- 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_songs
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function get_songs(): array
{
$results = array();
if ($this->isNew()) {
return $results;
- 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_items
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function get_items(): array
{
$results = array();
if ($this->isNew()) {
return $results;
- 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_random_items
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function get_random_items($limit = ''): array
{
$results = array();
$sqltbl = $this->to_sql();
$sql = $sqltbl['base'] . ' ' . $sqltbl['table_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 class Search has 1847 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Search extends playlist_object
{
protected const DB_TABLENAME = 'search';
public const VALID_TYPES = array(
'song',
- Exclude checks
The method _set_types_song() has 134 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function _set_types_song(): void
{
$this->_add_type_text('anywhere', T_('Any searchable text'));
$t_song_data = T_('Song Data');
- Exclude checks
The method set_rules() has an NPath complexity of 624. The configured NPath complexity threshold is 200. Open
public function set_rules($data): void
{
if (isset($data['playlist_name'])) {
$this->name = (string)$data['playlist_name'];
}
- 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 method __construct() has an NPath complexity of 1848. The configured NPath complexity threshold is 200. Open
public function __construct($search_id = 0, $object_type = 'song', ?User $user = null)
{
$this->search_user = $user;
if (!$this->search_user instanceof User) {
$this->search_user = User::get_from_global() ?? new User(-1);
- 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 method _filter_request() has an NPath complexity of 1440. The configured NPath complexity threshold is 200. Open
private static function _filter_request($data): array
{
$request = array();
foreach ($data as $key => $value) {
$prefix = substr($key, 0, 4);
- 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 method run() has an NPath complexity of 432. The configured NPath complexity threshold is 200. Open
public static function run($data, $user = null, $require_rules = false): array
{
$limit = (int)($data['limit'] ?? 0);
$offset = (int)($data['offset'] ?? 0);
$random = ((int)($data['random'] ?? 0) > 0) ? 1 : 0;
- 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 method _get_rule_name() has 148 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function _get_rule_name($name): string
{
// check that the rule you sent is not an alias (needed for pulling details from the rule)
switch ($this->objectType) {
case 'song':
- Exclude checks
The method __construct() has 111 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public function __construct($search_id = 0, $object_type = 'song', ?User $user = null)
{
$this->search_user = $user;
if (!$this->search_user instanceof User) {
$this->search_user = User::get_from_global() ?? new User(-1);
- Exclude checks
The method _set_basetypes() has 276 lines of code. Current threshold is set to 100. Avoid really long methods. Open
private function _set_basetypes(): void
{
$this->basetypes['numeric'][] = array(
'name' => 'gte',
'description' => T_('is greater than or equal to'),
- Exclude checks
The method __construct() has a Cyclomatic Complexity of 24. The configured cyclomatic complexity threshold is 10. Open
public function __construct($search_id = 0, $object_type = 'song', ?User $user = null)
{
$this->search_user = $user;
if (!$this->search_user instanceof User) {
$this->search_user = User::get_from_global() ?? new User(-1);
- 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_rules() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public function set_rules($data): void
{
if (isset($data['playlist_name'])) {
$this->name = (string)$data['playlist_name'];
}
- 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 run() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public static function run($data, $user = null, $require_rules = false): array
{
$limit = (int)($data['limit'] ?? 0);
$offset = (int)($data['offset'] ?? 0);
$random = ((int)($data['random'] ?? 0) > 0) ? 1 : 0;
- 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_rule_name() has a Cyclomatic Complexity of 58. The configured cyclomatic complexity threshold is 10. Open
private function _get_rule_name($name): string
{
// check that the rule you sent is not an alias (needed for pulling details from the rule)
switch ($this->objectType) {
case 'song':
- 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 _filter_request() has a Cyclomatic Complexity of 23. The configured cyclomatic complexity threshold is 10. Open
private static function _filter_request($data): array
{
$request = array();
foreach ($data as $key => $value) {
$prefix = substr($key, 0, 4);
- 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_random_items() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public function get_random_items($limit = ''): array
{
$results = array();
$sqltbl = $this->to_sql();
$sql = $sqltbl['base'] . ' ' . $sqltbl['table_sql'];
- 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 class Search has a coupling between objects value of 21. Consider to reduce the number of dependencies under 13. Open
class Search extends playlist_object
{
protected const DB_TABLENAME = 'search';
public const VALID_TYPES = array(
'song',
- 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 __construct uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$this->$key = $value;
}
- Read upRead up
- Exclude checks
ElseExpression
Since: 1.4.0
An if expression with an else branch is basically not necessary. You can rewrite the conditions in a way that the else clause is not necessary and the code becomes simpler to read. To achieve this, use early return statements, though you may need to split the code it several smaller methods. For very simple assignments you could also use the ternary operations.
Example
class Foo
{
public function bar($flag)
{
if ($flag) {
// one branch
} else {
// another branch
}
}
}
Source https://phpmd.org/rules/cleancode.html#elseexpression
Avoid unused local variables such as '$value'. Open
foreach ($data as $rule => $value) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST)
Open
public ?string $type = 'public';
- Exclude checks
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (AmpConfig::get('ratings')) {
$this->_add_type_select('myrating', T_('My Rating'), 'numeric', $this->stars, $t_ratings);
$this->_add_type_select('rating', T_('Rating (Average)'), 'numeric', $this->stars, $t_ratings);
$this->_add_type_select('songrating', T_('My Rating (Song)'), 'numeric', $this->stars, $t_ratings);
$this->_add_type_select('albumrating', T_('My Rating (Album)'), 'numeric', $this->stars, $t_ratings);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 195.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Similar blocks of code found in 2 locations. Consider refactoring. Open
if (AmpConfig::get('ratings')) {
$this->_add_type_select('myrating', T_('My Rating'), 'numeric', $this->stars, $t_ratings);
$this->_add_type_select('rating', T_('Rating (Average)'), 'numeric', $this->stars, $t_ratings);
$this->_add_type_select('songrating', T_('My Rating (Song)'), 'numeric', $this->stars, $t_ratings);
$this->_add_type_select('artistrating', T_('My Rating (Artist)'), 'numeric', $this->stars, $t_ratings);
- Read upRead up
Duplicated Code
Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:
Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.
When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).
Tuning
This issue has a mass of 195.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
The parameter $object_type is not named in camelCase. Open
public function __construct($search_id = 0, $object_type = 'song', ?User $user = null)
{
$this->search_user = $user;
if (!$this->search_user instanceof User) {
$this->search_user = User::get_from_global() ?? new User(-1);
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $user_id is not named in camelCase. Open
public static function get_search_array($user_id = 0): array
{
if ($user_id === 0) {
$user = Core::get_global('user');
$user_id = $user->id ?? 0;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $require_rules is not named in camelCase. Open
public static function run($data, $user = null, $require_rules = false): array
{
$limit = (int)($data['limit'] ?? 0);
$offset = (int)($data['offset'] ?? 0);
$random = ((int)($data['random'] ?? 0) > 0) ? 1 : 0;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $user_id is not named in camelCase. Open
public static function get_searches($user_id = null): array
{
if ($user_id === null) {
$user = Core::get_global('user');
$user_id = $user->id ?: 0;
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The parameter $search_id is not named in camelCase. Open
public function __construct($search_id = 0, $object_type = 'song', ?User $user = null)
{
$this->search_user = $user;
if (!$this->search_user instanceof User) {
$this->search_user = User::get_from_global() ?? new User(-1);
- 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 "_set_types_video" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_video(): void
- Exclude checks
CASE statements must be defined using a colon Open
case 'album':
- Exclude checks
Method name "_set_types_song" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_song(): void
- Exclude checks
Method name "_set_types_podcast_episode" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_podcast_episode(): void
- Exclude checks
Method name "_add_type_text" should not be prefixed with an underscore to indicate visibility Open
private function _add_type_text($name, $label, $group = ''): void
- Exclude checks
Method name "_set_types_podcast" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_podcast(): void
- Exclude checks
Method name "_set_basetypes" should not be prefixed with an underscore to indicate visibility Open
private function _set_basetypes(): void
- Exclude checks
Method name "_add_type_date" should not be prefixed with an underscore to indicate visibility Open
private function _add_type_date($name, $label, $group = ''): void
- Exclude checks
CASE statements must be defined using a colon Open
case 'album_disk':
- Exclude checks
Method name "_set_types_label" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_label(): void
- Exclude checks
CASE statements must be defined using a colon Open
case 'artist':
- Exclude checks
Method name "_add_type_numeric" should not be prefixed with an underscore to indicate visibility Open
private function _add_type_numeric($name, $label, $type = 'numeric', $group = ''): void
- Exclude checks
Method name "_set_types_album" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_album(): void
- Exclude checks
Method name "_add_type_select" should not be prefixed with an underscore to indicate visibility Open
private function _add_type_select($name, $label, $type, $array, $group = ''): void
- Exclude checks
Method name "_set_types_artist" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_artist(): void
- Exclude checks
Method name "_set_types_user" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_user(): void
- Exclude checks
Method name "_set_types_playlist" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_playlist(): void
- Exclude checks
Method name "_add_type_boolean" should not be prefixed with an underscore to indicate visibility Open
private function _add_type_boolean($name, $label, $type = 'boolean', $group = ''): void
- Exclude checks
Method name "_filter_request" should not be prefixed with an underscore to indicate visibility Open
private static function _filter_request($data): array
- Exclude checks
Method name "_set_types_tag" should not be prefixed with an underscore to indicate visibility Open
private function _set_types_tag(): void
- Exclude checks
Method name "_get_rule_name" should not be prefixed with an underscore to indicate visibility Open
private function _get_rule_name($name): string
- Exclude checks