The class MissionList has an overall complexity of 57 which is very high. The configured complexity threshold is 50. Open
class MissionList extends WikiBase
{
/**
* List of all missions, organized by episodes/cadet
*
- Create a ticketCreate a ticket
- Exclude checks
File MissionList.php
has 274 lines of code (exceeds 250 allowed). Consider refactoring. Open
<?php
/**
* Created by PhpStorm.
* User: JC
* Date: 2016-11-17
- Create a ticketCreate a ticket
Function fetchImages
has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring. Open
private function fetchImages(array $missions): void
{
foreach ($missions as $mission) {
$mission = $mission->get();
$mission->image = $this->query->imageInfo(
- Read upRead up
- Create a ticketCreate a ticket
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 flattenSteps
has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring. Open
private function flattenSteps(array &$mission): void
{
foreach ($mission['steps'] as &$step) {
if (empty($step['locks'])) {
unset($step['locks']);
- Read upRead up
- Create a ticketCreate a ticket
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 byName
has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring. Open
public function byName(string $name, string $epName = null): ?MissionModel
{
$search = trim(strtolower($name));
$epSearch = trim(strtolower($epName));
foreach ($this->list as $episodes) {
- Read upRead up
- Create a ticketCreate a ticket
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 export
has 30 lines of code (exceeds 25 allowed). Consider refactoring. Open
public function export(): array
{
$epi = 0;
$episodes = [];
$missions = [];
- Create a ticketCreate a ticket
Function eachAway
has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring. Open
public function eachAway(callable $func): void
{
foreach ($this->list as $type => $episodes) {
foreach ($episodes as $episode => $missions) {
foreach ($missions as $index => $mission) {
- Read upRead up
- Create a ticketCreate a ticket
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 get
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function get(string $what = null): array
{
if ($this->models) {
return empty($what) ? $this->models : $this->models[$what];
}
- Read upRead up
- Create a ticketCreate a ticket
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 fetchCadetCrew
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function fetchCadetCrew(array $names, array $cadet)
{
foreach ($cadet as $episode => $missions) {
$this->parse->page($names[$episode], 2);
preg_match_all(
- Read upRead up
- Create a ticketCreate a ticket
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 each
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
public function each(callable $func): void
{
foreach ($this->list as $type => $episodes) {
foreach ($episodes as $episode => $missions) {
foreach ($missions as $index => $mission) {
- Read upRead up
- Create a ticketCreate a ticket
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 parseMissions
has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring. Open
private function parseMissions(array $missions, string $episode): array
{
$info = [];
$adv = 'adv:' == strtolower(substr($episode, 0, 4));
foreach ($missions as $mission) {
- Read upRead up
- Create a ticketCreate a ticket
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 fetchTemplates uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them. Open
} else {
$template = substr(
$text,
$starts[$idx],
$starts[$idx + 1] - $starts[$idx]
- Read upRead up
- Create a ticketCreate a ticket
- 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
Avoid using static access to class 'eidng8\Wiki\Templates\Mission' in method 'parseMissions'. Open
$miss = Mission::load($mission, null, ['advanced' => $adv]);
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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\Wiki\Models\Skills' in method 'flattenSteps'. Open
Skills::skillNames($skill['names'])
- Read upRead up
- Create a ticketCreate a ticket
- Exclude checks
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();
}
}