eidng8/sttbot

View on GitHub
src/Wiki/Templates/CrewList.php

Summary

Maintainability
C
1 day
Test Coverage

The class CrewList has 16 public methods. Consider refactoring CrewList to keep number of public methods under 10.
Open

class CrewList extends Template
{
    /**
     * Maximum skills statistics
     *
Severity: Minor
Found in src/Wiki/Templates/CrewList.php by phpmd

TooManyPublicMethods

Since: 0.1

A class with too many public methods is probably a good suspect for refactoring, in order to reduce its complexity and find a way to have more fine grained objects.

By default it ignores methods starting with 'get' or 'set'.

Example

Source https://phpmd.org/rules/codesize.html#toomanypublicmethods

File CrewList.php has 251 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Created by PhpStorm.
 * User: JC
 * Date: 2016-10-23
Severity: Minor
Found in src/Wiki/Templates/CrewList.php - About 2 hrs to fix

Function skillValue has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
Open

    public function skillValue(string $table, array $skills): ?array
    {
        $regex = '/^\s*\|\s*\d+\s*$(.+?)\|[}-].*?$/imsu';
        if (!preg_match_all($regex, $table, $levels)) {
            return null;
Severity: Minor
Found in src/Wiki/Templates/CrewList.php - About 1 hr 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

Function fetchPictures has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

    public function fetchPictures(array $crew): array
    {
        if (empty($this->query)) {
            return $crew;
        }
Severity: Minor
Found in src/Wiki/Templates/CrewList.php - About 1 hr 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 skillValue has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function skillValue(string $table, array $skills): ?array
    {
        $regex = '/^\s*\|\s*\d+\s*$(.+?)\|[}-].*?$/imsu';
        if (!preg_match_all($regex, $table, $levels)) {
            return null;
Severity: Minor
Found in src/Wiki/Templates/CrewList.php - About 1 hr to fix

Method fetchPictures has 27 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function fetchPictures(array $crew): array
    {
        if (empty($this->query)) {
            return $crew;
        }
Severity: Minor
Found in src/Wiki/Templates/CrewList.php - About 1 hr to fix

Function stats has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

    protected function stats(CrewMember $member)
    {
        foreach ($member->skills as $skill => $val) {
            if (empty($val)) {
                continue;
Severity: Minor
Found in src/Wiki/Templates/CrewList.php - About 35 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

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

                    } else {
                        $pics = $member['picture'];
                        $pics[] = $images[$member->name] ?? null;
                        $member['picture'] = $pics;
                        // Because we are actually access the `$picture` through
Severity: Minor
Found in src/Wiki/Templates/CrewList.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

There are no issues that match your filters.

Category
Status