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'];
- 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
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]);
- 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
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)
);
}
- Read upRead up
- Exclude checks
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`
- Read upRead up
- Exclude checks
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(),
- Read upRead up
- Exclude checks
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;
- Exclude checks
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
- Exclude checks
Possible parse error: class missing opening or closing brace Open
final class ShoutRepository extends BaseRepository implements ShoutRepositoryInterface
- Exclude checks
Possible parse error: class missing opening or closing brace Open
final class ShoutRepository extends BaseRepository implements ShoutRepositoryInterface
- Exclude checks
Inline control structures are not allowed Open
} else {
- Exclude checks
Inline control structures are not allowed Open
foreach ($types as $type) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
protected function getTableName(): string
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
private LoggerInterface $logger;
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 8 Open
if ($objectType !== null) {
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
while ($shout = $result->fetch()) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
protected function getPrototypeParameters(): array
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 8 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 12 Open
if (in_array($objectType, $types)) {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function __construct(
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 12 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
}
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
protected DatabaseConnectionInterface $connection;
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
protected function getModelClass(): string
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function getBy(
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 4 Open
public function collectGarbage(
- Exclude checks
Line indented incorrectly; expected 4 spaces, found 12 Open
} else {
- Exclude checks
Line indented incorrectly; expected 0 spaces, found 8 Open
} else {
- Exclude checks