songs accesses the super-global variable $_REQUEST. Open
public static function songs($songs, $user, $encode = true)
{
if ((count($songs) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
democratic accesses the super-global variable $_REQUEST. Open
public static function democratic($object_ids, $user): string
{
if (!is_array($object_ids)) {
$object_ids = array();
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
songs accesses the super-global variable $_REQUEST. Open
public static function songs($songs, $user, $encode = true)
{
if ((count($songs) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
- Read upRead up
- Exclude checks
Superglobals
Since: 0.2
Accessing a super-global variable directly is considered a bad practice. These variables should be encapsulated in objects that are provided by a framework, for instance.
Example
class Foo {
public function bar() {
$name = $_POST['foo'];
}
}
Source
File Json4_Data.php
has 792 lines of code (exceeds 500 allowed). Consider refactoring. Open
<?php
declare(strict_types=0);
/**
* vim:set softtabstop=4 shiftwidth=4 expandtab:
Function playlists
has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring. Open
public static function playlists($playlists, $user, $songs = false): string
{
if ((count($playlists) > self::$limit || self::$offset > 0) && self::$limit) {
$playlists = array_slice($playlists, self::$offset, self::$limit);
}
- 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 Json4_Data has an overall complexity of 141 which is very high. The configured complexity threshold is 50. Open
class Json4_Data
{
// This is added so that we don't pop any webservers
private static ?int $limit = 5000;
private static int $offset = 0;
- Exclude checks
The class Json4_Data has 19 public methods. Consider refactoring Json4_Data to keep number of public methods under 10. Open
class Json4_Data
{
// This is added so that we don't pop any webservers
private static ?int $limit = 5000;
private static int $offset = 0;
- Read upRead up
- Exclude checks
TooManyPublicMethods
Since: 0.1
A class with too many public 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'.
Example
Source https://phpmd.org/rules/codesize.html#toomanypublicmethods
Json4_Data
has 27 functions (exceeds 20 allowed). Consider refactoring. Open
class Json4_Data
{
// This is added so that we don't pop any webservers
private static ?int $limit = 5000;
private static int $offset = 0;
Function songs
has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring. Open
public static function songs($songs, $user, $encode = true)
{
if ((count($songs) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
- 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 artists
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
public static function artists($artists, $include, $user, $encode = true)
{
if ((count($artists) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$artists = array_splice($artists, self::$offset, self::$limit);
}
- 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 albums
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
public static function albums($albums, $include, $user, $encode = true)
{
if ((count($albums) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$albums = array_splice($albums, self::$offset, self::$limit);
}
- 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 tags_array
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private static function tags_array($tags, $simple = false): array
{
$JSON = array();
if (is_array($tags)) {
- 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 podcasts
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function podcasts($podcasts, $user, $episodes = false): string
{
if ((count($podcasts) > self::$limit || self::$offset > 0) && self::$limit) {
$podcasts = array_splice($podcasts, self::$offset, self::$limit);
}
- 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 podcast_episodes
has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring. Open
public static function podcast_episodes($podcast_episodes, $user, $encode = true, $object = true)
{
if ((count($podcast_episodes) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$podcast_episodes = array_splice($podcast_episodes, self::$offset, self::$limit);
}
- 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 catalogs
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function catalogs($catalogs): string
{
if ((count($catalogs) > self::$limit || self::$offset > 0) && self::$limit) {
$catalogs = array_splice($catalogs, self::$offset, self::$limit);
}
- 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 videos
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public static function videos($videos, $user): string
{
if ((count($videos) > self::$limit || self::$offset > 0) && self::$limit) {
$videos = array_slice($videos, self::$offset, self::$limit);
}
- 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 self::podcasts($objects, $user, $include);
Avoid too many return
statements within this method. Open
return self::podcast_episodes($objects, $user, true, false);
Avoid too many return
statements within this method. Open
return self::shares($objects);
Avoid too many return
statements within this method. Open
return self::videos($objects, $user);
Avoid too many return
statements within this method. Open
return self::error('401', T_('Wrong object type ' . $object_type));
Function licenses
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public static function licenses($licenses): string
{
if ((count($licenses) > self::$limit || self::$offset > 0) && self::$limit) {
$licenses = array_splice($licenses, self::$offset, self::$limit);
}
- 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 songs() has an NPath complexity of 250. The configured NPath complexity threshold is 200. Open
public static function songs($songs, $user, $encode = true)
{
if ((count($songs) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
- 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 albums() has an NPath complexity of 330. The configured NPath complexity threshold is 200. Open
public static function albums($albums, $include, $user, $encode = true)
{
if ((count($albums) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$albums = array_splice($albums, self::$offset, self::$limit);
}
- 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 songs() has 109 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function songs($songs, $user, $encode = true)
{
if ((count($songs) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
- Exclude checks
The class Json4_Data has 1092 lines of code. Current threshold is 1000. Avoid really long classes. Open
class Json4_Data
{
// This is added so that we don't pop any webservers
private static ?int $limit = 5000;
private static int $offset = 0;
- Exclude checks
The method playlists() has an NPath complexity of 316. The configured NPath complexity threshold is 200. Open
public static function playlists($playlists, $user, $songs = false): string
{
if ((count($playlists) > self::$limit || self::$offset > 0) && self::$limit) {
$playlists = array_slice($playlists, self::$offset, self::$limit);
}
- 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 podcast_episodes() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10. Open
public static function podcast_episodes($podcast_episodes, $user, $encode = true, $object = true)
{
if ((count($podcast_episodes) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$podcast_episodes = array_splice($podcast_episodes, self::$offset, self::$limit);
}
- 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 indexes() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public static function indexes($objects, $object_type, $user, $include = false)
{
// here is where we call the object type
switch ($object_type) {
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 playlists() has a Cyclomatic Complexity of 17. The configured cyclomatic complexity threshold is 10. Open
public static function playlists($playlists, $user, $songs = false): string
{
if ((count($playlists) > self::$limit || self::$offset > 0) && self::$limit) {
$playlists = array_slice($playlists, self::$offset, self::$limit);
}
- 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 artists() has a Cyclomatic Complexity of 11. The configured cyclomatic complexity threshold is 10. Open
public static function artists($artists, $include, $user, $encode = true)
{
if ((count($artists) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$artists = array_splice($artists, self::$offset, self::$limit);
}
- 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 albums() has a Cyclomatic Complexity of 13. The configured cyclomatic complexity threshold is 10. Open
public static function albums($albums, $include, $user, $encode = true)
{
if ((count($albums) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$albums = array_splice($albums, self::$offset, self::$limit);
}
- 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 songs() has a Cyclomatic Complexity of 12. The configured cyclomatic complexity threshold is 10. Open
public static function songs($songs, $user, $encode = true)
{
if ((count($songs) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$songs = array_slice($songs, self::$offset, self::$limit);
}
- 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 Json4_Data has a coupling between objects value of 26. Consider to reduce the number of dependencies under 13. Open
class Json4_Data
{
// This is added so that we don't pop any webservers
private static ?int $limit = 5000;
private static int $offset = 0;
- 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 tags_array uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$atags[$data['id']] = array(
'name' => $data['name'],
'count' => 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
The method songs uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$licenseLink = '';
}
- 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 playlists uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$playlist = new Playlist($playlist_id);
if ($playlist->isNew()) {
continue;
}
- 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 playlists uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$items = ($playitem_total ?? 0);
}
- 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 artists uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$albums = $artist->album_count;
}
- 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 albums uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$songs = $album->song_count;
}
- 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 tags_array uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$JSON[] = array(
"id" => (string)$tag_id,
"name" => $data['name']
);
- 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 artists uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$songs = $artist->song_count;
}
- 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 user uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$JSON['user'] = array(
"id" => (string) $user->getId(),
"username" => $user->username,
"create_date" => $user->create_date,
- 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
syntax error, unexpected '?', expecting function (T_FUNCTION) or const (T_CONST)
Open
private static ?int $limit = 5000;
- Exclude checks
Identical blocks of code found in 5 locations. Consider refactoring. Open
if ((int)$playlist_id === 0) {
$playlist = new Search((int) str_replace('smart_', '', (string) $playlist_id), 'song', $user);
if (
$playlist->isNew() ||
($hide_dupe_searches && $playlist->user == $user->getId() && in_array($playlist->name, $playlist_names))
- 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 251.
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 3 locations. Consider refactoring. Open
foreach ($tags as $tag_id) {
$tag = new Tag($tag_id);
$counts = $tag->count();
$TAGS[] = array(
"id" => (string)$tag_id,
- 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 144.
We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.
The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.
If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.
See codeclimate-duplication
's documentation for more information about tuning the mass threshold in your .codeclimate.yml
.
Refactorings
- Extract Method
- Extract Class
- Form Template Method
- Introduce Null Object
- Pull Up Method
- Pull Up Field
- Substitute Algorithm
Further Reading
- Don't Repeat Yourself on the C2 Wiki
- Duplicated Code on SourceMaking
- Refactoring: Improving the Design of Existing Code by Martin Fowler. Duplicated Code, p76
Avoid excessively long variable names like $catalog_rename_pattern. Keep variable name length under 20. Open
$catalog_rename_pattern = $catalog->rename_pattern;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
The parameter $object_type is not named in camelCase. Open
public static function indexes($objects, $object_type, $user, $include = false)
{
// here is where we call the object type
switch ($object_type) {
case 'song':
- 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 $podcast_episodes is not named in camelCase. Open
public static function podcast_episodes($podcast_episodes, $user, $encode = true, $object = true)
{
if ((count($podcast_episodes) > self::$limit || self::$offset > 0) && (self::$limit && $encode)) {
$podcast_episodes = array_splice($podcast_episodes, self::$offset, self::$limit);
}
- 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 static function democratic($object_ids, $user): string
{
if (!is_array($object_ids)) {
$object_ids = array();
}
- Read upRead up
- Exclude checks
CamelCaseParameterName
Since: 0.2
It is considered best practice to use the camelCase notation to name parameters.
Example
class ClassName {
public function doSomething($user_name) {
}
}
Source
The class Json4_Data is not named in CamelCase. Open
class Json4_Data
{
// This is added so that we don't pop any webservers
private static ?int $limit = 5000;
private static int $offset = 0;
- Read upRead up
- Exclude checks
CamelCaseClassName
Since: 0.2
It is considered best practice to use the CamelCase notation to name classes.
Example
class class_name {
}
Source
Expected 0 spaces after opening bracket; newline found Open
if (
- Exclude checks
Class name "Json4_Data" is not in camel caps format Open
class Json4_Data
- Exclude checks
Expected 0 spaces after opening bracket; newline found Open
if (
- Exclude checks