Function stats
has a Cognitive Complexity of 47 (exceeds 5 allowed). Consider refactoring. Open
public static function stats(array $input, User $user): bool
{
if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
return false;
}
- Read upRead up
Cognitive Complexity
Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.
A method's cognitive complexity is based on a few simple rules:
- Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
- Code is considered more complex for each "break in the linear flow of the code"
- Code is considered more complex when "flow breaking structures are nested"
Further reading
Avoid too many return
statements within this method. Open
return false;
Avoid too many return
statements within this method. Open
return true;
The method stats() has 213 lines of code. Current threshold is set to 100. Avoid really long methods. Open
public static function stats(array $input, User $user): bool
{
if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
return false;
}
- Exclude checks
The method stats() has an NPath complexity of 201600. The configured NPath complexity threshold is 200. Open
public static function stats(array $input, User $user): bool
{
if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
return false;
}
- Read upRead up
- Exclude checks
NPathComplexity
Since: 0.1
The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.
Example
class Foo {
function bar() {
// lots of complicated code
}
}
Source https://phpmd.org/rules/codesize.html#npathcomplexity
The method stats() has a Cyclomatic Complexity of 43. The configured cyclomatic complexity threshold is 10. Open
public static function stats(array $input, User $user): bool
{
if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
return false;
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
This function "stats" has 212 lines, which is greater than the 150 lines authorized. Split it into smaller functions. Open
public static function stats(array $input, User $user): bool
- Read upRead up
- Exclude checks
A function that grows too large tends to aggregate too many responsibilities.
Such functions inevitably become harder to understand and therefore harder to maintain.
Above a specific threshold, it is strongly advised to refactor into smaller functions which focus on well-defined tasks.
Those smaller functions will not only be easier to understand, but also probably easier to test.
Refactor this function to reduce its Cognitive Complexity from 34 to the 15 allowed. Open
public static function stats(array $input, User $user): 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
Reduce the number of returns of this function 6, down to the maximum allowed 3. Open
public static function stats(array $input, User $user): bool
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
The class Stats5Method has a coupling between objects value of 15. Consider to reduce the number of dependencies under 13. Open
final class Stats5Method
{
public const ACTION = 'stats';
/**
- 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
Define a constant instead of duplicating this literal "video" 4 times. Open
if (!AmpConfig::get('allow_video') && $type == '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 "album" 3 times. Open
if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', '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 "api_format" 11 times. Open
Api5::error(T_('Enable: video'), ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);
- 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
if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', '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 "podcast_episode" 4 times. Open
if (!AmpConfig::get('podcast') && ($type == 'podcast' || $type == '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 "username" 3 times. Open
if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
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
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 "artist" 3 times. Open
if (!in_array(strtolower($type), array('song', 'album', 'artist', 'video', 'playlist', 'podcast', '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 "podcast" 5 times. Open
if (!AmpConfig::get('podcast') && ($type == 'podcast' || $type == '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.
Call to method albums
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::albums($results, array(), $user);
- Exclude checks
Call to method error
from undeclared class \Ampache\Module\Api\Api5
Open
Api5::error(T_('Enable: podcast'), ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method get_recently_played
from undeclared class \Ampache\Repository\Model\User
Open
? $user->get_recently_played($type, $limit, $offset, $newest)
- Exclude checks
Call to deprecated function \Ampache\Module\Api\Method\Api5\Stats5Method::getArtistRepository()
defined at /code/src/Module/Api/Method/Api5/Stats5Method.php:293
Open
$results = static::getArtistRepository()->getRandom(
- Exclude checks
Call to method artists
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::artists($results, array(), $user);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method songs
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::songs($results, $user);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to method playlists
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::playlists($results, $user);
- Exclude checks
Reference to instance property id
from undeclared class \Ampache\Repository\Model\User
Open
$user_id = $user->id;
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\User
Open
$userTwo = new User($user_id);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method videos
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::videos($results, $user);
- Exclude checks
Call to method extend
from undeclared class \Ampache\Module\System\Session
Open
Session::extend($input['auth'], 'api');
- Exclude checks
Call to method podcasts
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::podcasts($results, $user);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method check_parameter
from undeclared class \Ampache\Module\Api\Api5
Open
if (!Api5::check_parameter($input, array('type'), self::ACTION)) {
- Exclude checks
Call to method empty
from undeclared class \Ampache\Module\Api\Api5
Open
Api5::empty($type, $input['api_format']);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to method get_from_username
from undeclared class \Ampache\Repository\Model\User
Open
if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\User
Open
$user = new User($user_id);
- Exclude checks
Call to method podcast_episodes
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::podcast_episodes($results, $user);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to method songs
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::songs($results, $user);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method podcast_episodes
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::podcast_episodes($results, $user);
- Exclude checks
Call to method get_latest
from undeclared class \Ampache\Repository\Model\Userflag
Open
$results = Userflag::get_latest($type, $user_id, $limit, $offset);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method podcasts
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::podcasts($results, $user);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to deprecated function \Ampache\Module\Api\Method\Api5\Stats5Method::getAlbumRepository()
defined at /code/src/Module/Api/Method/Api5/Stats5Method.php:283
Open
$results = static::getAlbumRepository()->getRandom(
- Exclude checks
Call to method artists
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::artists($results, array(), $user);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method albums
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
echo Xml5_Data::albums($results, array(), $user);
- Exclude checks
Reference to instance property id
from undeclared class \Ampache\Repository\Model\User
Open
$results = ($user->id)
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method get_newest
from undeclared class \Ampache\Module\Statistics\Stats
Open
$results = Stats::get_newest($type, $limit, $offset, 0, $user_id);
- Exclude checks
Call to method get_recent
from undeclared class \Ampache\Module\Statistics\Stats
Open
: Stats::get_recent($type, $limit, $offset, $newest);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method error
from undeclared class \Ampache\Module\Api\Api5
Open
Api5::error(T_('Enable: video'), ErrorCodeEnum::ACCESS_DENIED, self::ACTION, 'system', $input['api_format']);
- Exclude checks
Call to method get_highest
from undeclared class \Ampache\Repository\Model\Rating
Open
$results = Rating::get_highest($type, $limit, $offset, $user_id);
- Exclude checks
Parameter $user
has undeclared type \Ampache\Repository\Model\User
Open
public static function stats(array $input, User $user): bool
- Exclude checks
Call to method error
from undeclared class \Ampache\Module\Api\Api5
Open
Api5::error(sprintf(T_('Bad Request: %s'), $type), ErrorCodeEnum::BAD_REQUEST, self::ACTION, 'type', $input['api_format']);
- Exclude checks
Call to method getBrowse
from undeclared class \Ampache\Module\Api\Api
Open
$browse = Api::getBrowse();
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_offset($offset);
- Exclude checks
Call to method set_offset
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_offset($offset);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Xml5_Data
Open
Xml5_Data::set_limit($limit);
- Exclude checks
Call to method isNew
from undeclared class \Ampache\Repository\Model\User
Open
if (!$userTwo->isNew()) {
- Exclude checks
Call to method get_top
from undeclared class \Ampache\Module\Statistics\Stats
Open
$results = Stats::get_top($type, $limit, $threshold, $offset);
- Exclude checks
Call to method get_from_username
from undeclared class \Ampache\Repository\Model\User
Open
$user = User::get_from_username($input['username']);
- Exclude checks
Call to method set_limit
from undeclared class \Ampache\Module\Api\Json5_Data
Open
Json5_Data::set_limit($limit);
- Exclude checks
Call to method playlists
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::playlists($results, $user);
- Exclude checks
Call to method videos
from undeclared class \Ampache\Module\Api\Json5_Data
Open
echo Json5_Data::videos($results, $user);
- Exclude checks
Identical blocks of code found in 2 locations. Consider refactoring. Open
switch ($type) {
case 'song':
switch ($input['api_format']) {
case 'json':
Json5_Data::set_offset($offset);
- 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 639.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
if (array_key_exists('username', $input) && User::get_from_username($input['username'])) {
$user = User::get_from_username($input['username']);
$user_id = $user->id;
} elseif (array_key_exists('user_id', $input)) {
$userTwo = new User($user_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 122.
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
Identical blocks of code found in 2 locations. Consider refactoring. Open
case 'playlist':
$playlists = Playlist::get_playlists($user_id, '', true, true, false);
$searches = Playlist::get_smartlists($user_id, '', true, true, false);
$results = array_merge($playlists, $searches);
shuffle($results);
- 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 102.
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