Missing class import via use statement (line '154', column '23'). Open
throw new \InvalidArgumentException('Unknown company');
- Read upRead up
- Exclude checks
MissingImport
Since: 2.7.0
Importing all external classes in a file through use statements makes them clearly visible.
Example
function make() {
return new \stdClass();
}
Source http://phpmd.org/rules/cleancode.html#MissingImport
The method uniquePassedParticipantsPercentages uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$passedUniqueParticipantPercentage[$key] = round(
(float)$passedUniqueParticipantCounts[$key] / (float)$uniqueParticipantsCounts[$key],
2
) * 100;
- 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
Define a constant instead of duplicating this literal "quiz_total_fr" 3 times. Open
'quiz_total_fr' => $this->employeeParticipationRepository->countByCompanyAndLanguage($companyId, new Language('fr')),
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "quiz_total" 3 times. Open
'quiz_total' => $this->employeeParticipationRepository->countByCompany($companyId)->toNative(),
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Define a constant instead of duplicating this literal "quiz_total_nl" 3 times. Open
'quiz_total_nl' => $this->employeeParticipationRepository->countByCompanyAndLanguage($companyId, new Language('nl')),
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.
Avoid unused local variables such as '$uniqueParticipantsCount'. Open
foreach ($uniqueParticipantsCounts as $key => $uniqueParticipantsCount) {
- Read upRead up
- Exclude checks
UnusedLocalVariable
Since: 0.2
Detects when a local variable is declared and/or assigned, but not used.
Example
class Foo {
public function doSomething()
{
$i = 5; // Unused
}
}
Source https://phpmd.org/rules/unusedcode.html#unusedlocalvariable
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 $uniqueParticipantsCounts. Keep variable name length under 20. Open
$uniqueParticipantsCounts = $this->uniqueParticipants($companyId);
- 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 $passedUniqueParticipantPercentage. Keep variable name length under 20. Open
$passedUniqueParticipantPercentage = [];
- 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 $uniqueParticipantsCount. Keep variable name length under 20. Open
foreach ($uniqueParticipantsCounts as $key => $uniqueParticipantsCount) {
- 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
private $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 $passedUniqueParticipantCounts. Keep variable name length under 20. Open
$passedUniqueParticipantCounts = $this->uniquePassedParticipants($companyId);
- 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
Line exceeds 120 characters; contains 143 characters Open
'quiz_total_nl' => $this->employeeParticipationRepository->getAverageTopScoreForCompanyAndLanguage($companyId, new Language('nl')),
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
'quiz_total_nl' => $this->employeeParticipationRepository->countByCompanyAndLanguage($companyId, new Language('nl')),
- Exclude checks
Line exceeds 120 characters; contains 129 characters Open
'quiz_total_fr' => $this->employeeParticipationRepository->countByCompanyAndLanguage($companyId, new Language('fr')),
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
'quiz_total_fr' => $this->employeeParticipationRepository->countPassedByCompanyAndLanguage($companyId, new Language('fr')),
- Exclude checks
Line exceeds 120 characters; contains 143 characters Open
'quiz_total_fr' => $this->employeeParticipationRepository->getAverageTopScoreForCompanyAndLanguage($companyId, new Language('fr')),
- Exclude checks
Line exceeds 120 characters; contains 135 characters Open
'quiz_total_nl' => $this->employeeParticipationRepository->countPassedByCompanyAndLanguage($companyId, new Language('nl')),
- Exclude checks
Multi-line function call not indented correctly; expected 16 spaces but found 20 Open
) * 100;
- Exclude checks
Multi-line function call not indented correctly; expected 20 spaces but found 24 Open
2
- Exclude checks
Multi-line function call not indented correctly; expected 20 spaces but found 24 Open
(float)$passedUniqueParticipantCounts[$key] / (float)$uniqueParticipantsCounts[$key],
- Exclude checks