Method __construct
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function __construct(
iterable $companies,
CompanyPlayedQuizzesRepository $companyPlayedQuizzesRepository,
EmployeeParticipationRepository $employeeParticipationRepository,
TopScoreRepository $topScoreRepository,
Method getValues
has 26 lines of code (exceeds 25 allowed). Consider refactoring. Open
private function getValues(Company $company)
{
$data = $this->normalizer->normalize($company);
$values = [];
Method __construct
has 5 arguments (exceeds 4 allowed). Consider refactoring. Open
iterable $companies,
CompanyPlayedQuizzesRepository $companyPlayedQuizzesRepository,
EmployeeParticipationRepository $employeeParticipationRepository,
TopScoreRepository $topScoreRepository,
NormalizerInterface $normalizer
The method flatten uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$result[$parentKey . $key] = $value;
}
- 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
Rename "$headers" which has the same name as the field declared at line 33. Open
$headers = array_fill_keys($this->headers, '');
- Read upRead up
- Exclude checks
Shadowing fields with a local variable is a bad practice that reduces code readability: it makes it confusing to know whether the field or the variable is being used.
Noncompliant Code Example
class Foo { public $myField; public function doSomething() { $myField = 0; ... } }
See
- CERT, DCL51-J. - Do not shadow or obscure identifiers in subscopes
Avoid excessively long variable names like $companyPlayedQuizzesRepository. Keep variable name length under 20. Open
private $companyPlayedQuizzesRepository;
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $employeeParticipationRepository. Keep variable name length under 20. Open
EmployeeParticipationRepository $employeeParticipationRepository,
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid excessively long variable names like $companyPlayedQuizzesRepository. Keep variable name length under 20. Open
CompanyPlayedQuizzesRepository $companyPlayedQuizzesRepository,
- Read upRead up
- Exclude checks
LongVariable
Since: 0.2
Detects when a field, formal or local variable is declared with a long name.
Example
class Something {
protected $reallyLongIntName = -3; // VIOLATION - Field
public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
$otherReallyLongName = -5; // VIOLATION - Local
for ($interestingIntIndex = 0; // VIOLATION - For
$interestingIntIndex < 10;
$interestingIntIndex++ ) {
}
}
}
Source https://phpmd.org/rules/naming.html#longvariable
Avoid variables with short names like $nl. Configured minimum length is 3. Open
$nl = new Language('nl');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Avoid variables with short names like $fr. Configured minimum length is 3. Open
$fr = new Language('fr');
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
TRUE, FALSE and NULL must be lowercase; expected "null" but found "NULL" Open
NULL
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$this->flatten($value, $result, $keySeparator,
- Exclude checks
Only one argument is allowed per line in a multi-line function call Open
$this->flatten($value, $result, $keySeparator,
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$this->flatten($value, $result, $keySeparator,
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$fr);
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$nl);
- Exclude checks
Multi-line function call not indented correctly; expected 16 spaces but found 20 Open
$parentKey . $key . $keySeparator);
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$values['played_quizzes.fr'] = $this->companyPlayedQuizzesRepository->getCount($company->getId(),
- Exclude checks
Opening parenthesis of a multi-line function call must be the last content on the line Open
$values['played_quizzes.nl'] = $this->companyPlayedQuizzesRepository->getCount($company->getId(),
- Exclude checks
Closing parenthesis of a multi-line function call must be on a line by itself Open
$parentKey . $key . $keySeparator);
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 12 Open
$nl);
- Exclude checks
Multi-line function call not indented correctly; expected 8 spaces but found 12 Open
$fr);
- Exclude checks