eidng8/sttbot

View on GitHub
src/Wiki/Analyst.php

Summary

Maintainability
A
3 hrs
Test Coverage

Method stepBestCrew has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function stepBestCrew(
        MissionStep $step,
        int $idxStep,
        int $idxMission,
        int $idxEpisode,
Severity: Minor
Found in src/Wiki/Analyst.php - About 1 hr to fix

Function stepBestCrew has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
Open

    public function stepBestCrew(
        MissionStep $step,
        int $idxStep,
        int $idxMission,
        int $idxEpisode,
Severity: Minor
Found in src/Wiki/Analyst.php - About 55 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

Method stepBestCrew has 5 arguments (exceeds 4 allowed). Consider refactoring.
Open

        MissionStep $step,
        int $idxStep,
        int $idxMission,
        int $idxEpisode,
        string $type
Severity: Minor
Found in src/Wiki/Analyst.php - About 35 mins to fix

The method bestMember has a boolean flag argument $lock, which is a certain sign of a Single Responsibility Principle violation.
Open

        bool $lock = false
Severity: Minor
Found in src/Wiki/Analyst.php by phpmd

BooleanArgumentFlag

Since: 1.4.0

A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

Example

class Foo {
    public function bar($flag = true) {
    }
}

Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

The method stepBestCrew uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

        } else {
            $member = $this->bestMember(
                $step->getCrew()['pass'],
                $skills,
                $member
Severity: Minor
Found in src/Wiki/Analyst.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

Avoid using static access to class '\eidng8\Log\Log' in method 'computeCrossRating'.
Open

        Log::info("cross rating calculated in {$elapsed}s");
Severity: Minor
Found in src/Wiki/Analyst.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

Avoid using static access to class '\eidng8\Log\Log' in method 'computeBestCrew'.
Open

        Log::info("best crew calculated in {$elapsed}s");
Severity: Minor
Found in src/Wiki/Analyst.php by phpmd

StaticAccess

Since: 1.4.0

Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

Example

class Foo
{
    public function bar()
    {
        Bar::baz();
    }
}

Source https://phpmd.org/rules/cleancode.html#staticaccess

The method rateStep uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
Open

                } else {
                    $this->rateCrew($step, $member);
                }
Severity: Minor
Found in src/Wiki/Analyst.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

Avoid unused parameters such as '$episode'.
Open

            function (Mission $mission, $index, $episode, string $type) {
Severity: Minor
Found in src/Wiki/Analyst.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

Avoid unused parameters such as '$index'.
Open

            function (Mission $mission, $index, $episode, string $type) {
Severity: Minor
Found in src/Wiki/Analyst.php by phpmd

UnusedFormalParameter

Since: 0.2

Avoid passing parameters to methods or constructors and then not using those parameters.

Example

class Foo
{
    private function bar($howdy)
    {
        // $howdy is not used
    }
}

Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

There are no issues that match your filters.

Category
Status