ampache/ampache

View on GitHub
src/Repository/VideoRepository.php

Summary

Maintainability
A
0 mins
Test Coverage

Avoid assigning values to variables in if clauses and the like (line '62', column '13').
Open

    public function getItemCount(string $type): int
    {
        $type = ObjectTypeToClassNameMapper::VIDEO_TYPES[$type];

        $sql        = 'SELECT COUNT(*) AS `count` FROM `' . strtolower((string) $type) . '`;';
Severity: Minor
Found in src/Repository/VideoRepository.php by phpmd

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

            if (array_key_exists('count', $results)) {

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

        $db_results = Dba::read($sql);
Severity: Critical
Found in src/Repository/VideoRepository.php by phan

Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
Open

        while ($row = Dba::fetch_assoc($db_results)) {
Severity: Critical
Found in src/Repository/VideoRepository.php by phan

Call to method fetch_assoc from undeclared class \Ampache\Module\System\Dba
Open

        if ($results = Dba::fetch_assoc($db_results)) {
Severity: Critical
Found in src/Repository/VideoRepository.php by phan

Call to method read from undeclared class \Ampache\Module\System\Dba
Open

        $db_results = Dba::read($sql);
Severity: Critical
Found in src/Repository/VideoRepository.php by phan

Call to method get_catalogs from undeclared class \Ampache\Repository\Model\Catalog
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);
Severity: Critical
Found in src/Repository/VideoRepository.php by phan

There are no issues that match your filters.

Category
Status