src/Repository/VideoRepository.php
Avoid assigning values to variables in if clauses and the like (line '62', column '13'). Open
Open
public function getItemCount(string $type): int
{
$type = ObjectTypeToClassNameMapper::VIDEO_TYPES[$type];
$sql = 'SELECT COUNT(*) AS `count` FROM `' . strtolower((string) $type) . '`;';
- Read upRead up
- Exclude checks
IfStatementAssignment
Since: 2.7.0
Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.
Example
class Foo
{
public function bar($flag)
{
if ($foo = 'bar') { // possible typo
// ...
}
if ($baz = 0) { // always false
// ...
}
}
}
Source http://phpmd.org/rules/cleancode.html#ifstatementassignment
Merge this if statement with the enclosing one. Open
Open
if (array_key_exists('count', $results)) {
- Read upRead up
- Exclude checks
Merging collapsible if
statements increases the code's readability.
Noncompliant Code Example
if (condition1) { if (condition2) { ... } }
Compliant Solution
if (condition1 && condition2) { ... }
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
Open
while ($row = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to method fetch_assoc
from undeclared class \Ampache\Module\System\Dba
Open
Open
if ($results = Dba::fetch_assoc($db_results)) {
- Exclude checks
Call to method read
from undeclared class \Ampache\Module\System\Dba
Open
Open
$db_results = Dba::read($sql);
- Exclude checks
Call to method get_catalogs
from undeclared class \Ampache\Repository\Model\Catalog
Open
Open
$sql = "SELECT DISTINCT(`video`.`id`) AS `id` FROM `video` LEFT JOIN `catalog` ON `catalog`.`id` = `video`.`catalog` WHERE `video`.`enabled` = '1' AND `catalog`.`id` IN (" . implode(',', Catalog::get_catalogs('', $userId, true)) . ") ORDER BY RAND() LIMIT " . (string) ($count);
- Exclude checks