ampache/ampache

View on GitHub
src/Repository/ShoutRepository.php

Summary

Maintainability
A
1 hr
Test Coverage

Function collectGarbage has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    public function collectGarbage(
        ?string $objectType = null,
        ?int $objectId = null
    ): void {
        $types = ['song', 'album', 'artist', 'label'];
Severity: Minor
Found in src/Repository/ShoutRepository.php - About 35 mins to fix

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 getTop has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
Open

    public function getTop(int $limit, ?string $username = null): Generator
    {
        $result = $this->connection->query('SELECT * FROM `user_shout` WHERE `sticky` = 1 ORDER BY `date` DESC');

        $result->setFetchMode(PDO::FETCH_CLASS, Shoutbox::class, [$this]);
Severity: Minor
Found in src/Repository/ShoutRepository.php - About 25 mins to fix

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 collectGarbage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

            } else {
                $this->logger->critical(
                    sprintf('Garbage collect on type `%s` is not supported.', $objectType)
                );
            }
Severity: Minor
Found in src/Repository/ShoutRepository.php by phpmd

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 collectGarbage uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            foreach ($types as $type) {
                $query = <<<SQL
                    DELETE FROM
                        `user_shout`
Severity: Minor
Found in src/Repository/ShoutRepository.php by phpmd

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 persist uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $this->connection->query(
                'UPDATE `user_shout` SET `user` = ?, `date` = ?, `text` = ?, `sticky` = ?, `object_id` = ?, `object_type` = ?, `data` = ? WHERE `id` = ?',
                [
                    $shout->getUserId(),
Severity: Minor
Found in src/Repository/ShoutRepository.php by phpmd

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 'DatabaseConnectionInterface' (T_STRING), expecting function (T_FUNCTION) or const (T_CONST)
Open

    protected DatabaseConnectionInterface $connection;
Severity: Critical
Found in src/Repository/ShoutRepository.php by phan

A file should declare new symbols (classes, functions, constants, etc.) and cause no other side effects, or it should execute logic with side effects, but should not do both. The first symbol is defined on line 47 and the first side effect is on line 41.
Open

<?php

Possible parse error: class missing opening or closing brace
Open

final class ShoutRepository extends BaseRepository implements ShoutRepositoryInterface

Possible parse error: class missing opening or closing brace
Open

final class ShoutRepository extends BaseRepository implements ShoutRepositoryInterface

Inline control structures are not allowed
Open

        } else {

Inline control structures are not allowed
Open

            foreach ($types as $type) {

Line indented incorrectly; expected 0 spaces, found 4
Open

    protected function getTableName(): string

Line indented incorrectly; expected 0 spaces, found 4
Open

    private LoggerInterface $logger;

Line indented incorrectly; expected 0 spaces, found 8
Open

        if ($objectType !== null) {

Line indented incorrectly; expected 4 spaces, found 8
Open

        while ($shout = $result->fetch()) {

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

Line indented incorrectly; expected 0 spaces, found 4
Open

    protected function getPrototypeParameters(): array

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

Line indented incorrectly; expected 4 spaces, found 8
Open

        }

Line indented incorrectly; expected 4 spaces, found 12
Open

            if (in_array($objectType, $types)) {

Line indented incorrectly; expected 0 spaces, found 4
Open

    public function __construct(

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

Line indented incorrectly; expected 4 spaces, found 12
Open

            }

Line indented incorrectly; expected 0 spaces, found 4
Open

    }

Line indented incorrectly; expected 0 spaces, found 4
Open

    protected DatabaseConnectionInterface $connection;

Line indented incorrectly; expected 0 spaces, found 4
Open

    protected function getModelClass(): string

Line indented incorrectly; expected 0 spaces, found 4
Open

    public function getBy(

Line indented incorrectly; expected 0 spaces, found 4
Open

    public function collectGarbage(

Line indented incorrectly; expected 4 spaces, found 12
Open

            } else {

Line indented incorrectly; expected 0 spaces, found 8
Open

        } else {

There are no issues that match your filters.

Category
Status