Variable $hide_columns
is undeclared Open
$hide_year = in_array('cel_year', $hide_columns);
- Exclude checks
Call to method __construct
from undeclared class \Ampache\Repository\Model\Song
Open
$libitem = new Song($song_id);
- Exclude checks
Expected an object instance when accessing an instance property, but saw an expression with type string
Open
<table id="top_tracks_<?php echo $artist->id; ?>" class="tabledata striped-rows">
- Exclude checks
Call to method build_cache
from undeclared class \Ampache\Repository\Model\Userflag
Open
Userflag::build_cache('song', $object_ids);
- Exclude checks
Call to method isNew
from undeclared class \Ampache\Repository\Model\Song
Open
if ($libitem->isNew()) {
- Exclude checks
Variable $hide_columns
is undeclared Open
$hide_album = in_array('cel_album', $hide_columns);
- Exclude checks
Call to method build_cache
from undeclared class \Ampache\Repository\Model\Rating
Open
Rating::build_cache('song', $object_ids);
- Exclude checks
Reference to instance property id
from undeclared class \Ampache\Repository\Model\Song
Open
<tr id="song_<?php echo $libitem->id; ?>">
- Exclude checks
Variable $hide_columns
is undeclared Open
$hide_drag = in_array('cel_drag', $hide_columns);
- Exclude checks
Call to method is_registered
from undeclared class \Ampache\Repository\Model\User
Open
$show_ratings = User::is_registered() && (AmpConfig::get('ratings'));
- Exclude checks
Call to method format
from undeclared class \Ampache\Repository\Model\Song
Open
$libitem->format(); ?>
- Exclude checks
Reference to instance property enabled
from undeclared class \Ampache\Repository\Model\Song
Open
if ($libitem->enabled || Access::check('interface', 50)) {
- Exclude checks
Call to method is_registered
from undeclared class \Ampache\Repository\Model\User
Open
->setContext('USER_IS_REGISTERED', User::is_registered())
- Exclude checks
Possibly zero references to use statement for classlike/namespace Artist
(\Ampache\Repository\Model\Artist)
Open
use Ampache\Repository\Model\Artist;
- Exclude checks
Call to method is_registered
from undeclared class \Ampache\Repository\Model\User
Open
->setContext('USING_RATINGS', User::is_registered() && (AmpConfig::get('ratings')))
- Exclude checks
Variable $hide_columns
is undeclared Open
$hide_artist = in_array('cel_artist', $hide_columns);
- Exclude checks
Expected an object instance when accessing an instance property, but saw an expression with type string
Open
var indexes = $("#top_tracks_<?php echo $artist->id; ?> .cel_play_content").each(function() {
- Exclude checks
Call to deprecated function \Ampache\Module\Authorization\Access::check()
defined at /code/src/Module/Authorization/Access.php:154
Open
if ($libitem->enabled || Access::check('interface', 50)) {
- Exclude checks
Define a constant instead of duplicating this literal "ratings" 3 times. Open
$show_ratings = User::is_registered() && (AmpConfig::get('ratings'));
- 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.
Similar blocks of code found in 2 locations. Consider refactoring. Open
<?php
declare(strict_types=0);
/**
- 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 745.
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
Line indented incorrectly; expected 24 spaces, found 8 Open
if ($libitem->enabled || Access::check('interface', 50)) {
- Exclude checks
Closing brace indented incorrectly; expected 8 spaces, found 12 Open
<?php } ?>
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$talFactory = $dic->get(TalFactoryInterface::class);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
foreach ($object_ids as $song_id) {
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 4 Open
$libitem->format(); ?>
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_SHOW_TRACK', !empty($argument))
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_SHOW_LICENSE', $show_license)
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->render();
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('USER_IS_REGISTERED', User::is_registered())
- Exclude checks
Line indented incorrectly; expected at least 12 spaces, found 4 Open
$libitem = new Song($song_id);
- Exclude checks
Line indented incorrectly; expected 8 spaces, found 0 Open
} ?>
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$guiFactory = $dic->get(GuiFactoryInterface::class);
- Exclude checks
Line indented incorrectly; expected at least 8 spaces, found 0 Open
$gatekeeper = $dic->get(GatekeeperFactoryInterface::class)->createGuiGatekeeper();
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_HIDE_GENRE', $hide_genres)
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_TABLE_VIEW', $is_table)
- Exclude checks
Closing brace indented incorrectly; expected 8 spaces, found 12 Open
<?php } ?>
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 12 Open
$content = $talFactory->createTalView()
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('SONG', $guiFactory->createSongViewAdapter($gatekeeper, $libitem))
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('USING_RATINGS', User::is_registered() && (AmpConfig::get('ratings')))
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('ARGUMENT_PARAM', '')
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 8 Open
} ?>
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_HIDE_ARTIST', $hide_artist)
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_HIDE_DRAG', (empty($argument) || $hide_drag))
- Exclude checks
Line indented incorrectly; expected 24 spaces, found 8 Open
} ?>
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_ALBUM_GROUP', $is_group)
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_HIDE_YEAR', $hide_year)
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setTemplate('song_row.xhtml')
- Exclude checks
Line indented incorrectly; expected 12 spaces, found 4 Open
if ($libitem->isNew()) {
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('CONFIG', $guiFactory->createConfigViewAdapter())
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 16 Open
->setContext('IS_HIDE_ALBUM', $hide_album)
- Exclude checks
Line indented incorrectly; expected at least 16 spaces, found 8 Open
continue;
- Exclude checks
Line indented incorrectly; expected at least 28 spaces, found 12 Open
echo $content;
- Exclude checks