VSVverkeerskunde/gvq-api

View on GitHub
src/Dashboard/Service/DashboardService.php

Summary

Maintainability
A
0 mins
Test Coverage

Missing class import via use statement (line '154', column '23').
Open

            throw new \InvalidArgumentException('Unknown company');

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;

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')),

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(),

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')),

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) {

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,

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);

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 = [];

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) {

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;

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);

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')),

Line exceeds 120 characters; contains 129 characters
Open

            'quiz_total_nl' => $this->employeeParticipationRepository->countByCompanyAndLanguage($companyId, new Language('nl')),

Line exceeds 120 characters; contains 129 characters
Open

            'quiz_total_fr' => $this->employeeParticipationRepository->countByCompanyAndLanguage($companyId, new Language('fr')),

Line exceeds 120 characters; contains 135 characters
Open

            'quiz_total_fr' => $this->employeeParticipationRepository->countPassedByCompanyAndLanguage($companyId, new Language('fr')),

Line exceeds 120 characters; contains 143 characters
Open

            'quiz_total_fr' => $this->employeeParticipationRepository->getAverageTopScoreForCompanyAndLanguage($companyId, new Language('fr')),

Line exceeds 120 characters; contains 135 characters
Open

            'quiz_total_nl' => $this->employeeParticipationRepository->countPassedByCompanyAndLanguage($companyId, new Language('nl')),

Multi-line function call not indented correctly; expected 16 spaces but found 20
Open

                    ) * 100;

Multi-line function call not indented correctly; expected 20 spaces but found 24
Open

                        2

Multi-line function call not indented correctly; expected 20 spaces but found 24
Open

                        (float)$passedUniqueParticipantCounts[$key] / (float)$uniqueParticipantsCounts[$key],

There are no issues that match your filters.

Category
Status