Function getWarnings
has a Cognitive Complexity of 29 (exceeds 5 allowed). Consider refactoring. Open
public static function getWarnings($folders, $active = true)
{
if (empty($folders)) {
return [];
}
- Read upRead up
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 getWarnings
has 34 lines of code (exceeds 25 allowed). Consider refactoring. Open
public static function getWarnings($folders, $active = true)
{
if (empty($folders)) {
return [];
}
Function getFolders
has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring. Open
public static function getFolders()
{
$folders = [];
$i = 0;
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
- Read upRead up
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 getWarnings() has a Cyclomatic Complexity of 15. The configured cyclomatic complexity threshold is 10. Open
public static function getWarnings($folders, $active = true)
{
if (empty($folders)) {
return [];
}
- Read upRead up
- Exclude checks
CyclomaticComplexity
Since: 0.1
Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.
Example
// Cyclomatic Complexity = 11
class Foo {
1 public function example() {
2 if ($a == $b) {
3 if ($a1 == $b1) {
fiddle();
4 } elseif ($a2 == $b2) {
fiddle();
} else {
fiddle();
}
5 } elseif ($c == $d) {
6 while ($c == $d) {
fiddle();
}
7 } elseif ($e == $f) {
8 for ($n = 0; $n < $h; $n++) {
fiddle();
}
} else {
switch ($z) {
9 case 1:
fiddle();
break;
10 case 2:
fiddle();
break;
11 case 3:
fiddle();
break;
default:
fiddle();
break;
}
}
}
}
Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity
Refactor this function to reduce its Cognitive Complexity from 29 to the 15 allowed. Open
public static function getWarnings($folders, $active = true)
- Read upRead up
- Exclude checks
Cognitive Complexity is a measure of how hard the control flow of a function is to understand. Functions with high Cognitive Complexity will be difficult to maintain.
See
Missing class import via use statement (line '32', column '59'). Open
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
- 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 getWarnings has a boolean flag argument $active, which is a certain sign of a Single Responsibility Principle violation. Open
public static function getWarnings($folders, $active = true)
- Read upRead up
- Exclude checks
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
Missing class import via use statement (line '74', column '20'). Open
$iterator = new \DirectoryIterator($dir);
- 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
Missing class import via use statement (line '32', column '28'). Open
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
- 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
Avoid using static access to class 'App\Language' in method 'getFolders'. Open
$folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
- Read upRead up
- 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
Call to undeclared method \RecursiveIteratorIterator::getSubPathName
Open
$subPath = $iterator->getSubPathName();
- Exclude checks
Avoid variables with short names like $i. Configured minimum length is 3. Open
$i = 0;
- Read upRead up
- Exclude checks
ShortVariable
Since: 0.2
Detects when a field, local, or parameter has a very short name.
Example
class Something {
private $q = 15; // VIOLATION - Field
public static function main( array $as ) { // VIOLATION - Formal
$r = 20 + $this->q; // VIOLATION - Local
for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
$r += $this->q;
}
}
}
Source https://phpmd.org/rules/naming.html#shortvariable
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Line exceeds 120 characters; contains 148 characters Open
$folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folder['parent'] = $folders[$parent]['id'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
++$i;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
{
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!is_dir($dir)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folder = str_replace('/', '\\', $folder);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$actions[$instace->getPriority() . $fileName] = $instace;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folder['state']['selected'] = true;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
- Exclude checks
Line exceeds 120 characters; contains 199 characters Open
foreach ($iterator = new \RecursiveIteratorIterator(new \RecursiveDirectoryIterator(self::FOLDERS, \RecursiveDirectoryIterator::SKIP_DOTS), \RecursiveIteratorIterator::SELF_FIRST) as $item) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$parent = rtrim(rtrim($subPath, $fileName), '/');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$className = "\\App\\SystemWarnings\\$folder\\$fileName";
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instace->process();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$active || (!$isIgnored && 1 !== $instace->getStatus())) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$i = 0;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @return array
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getWarnings($folders, $active = true)
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$isIgnored = 2 === $instace->getStatusValue();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instace = new $className();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const FOLDERS = 'app/SystemWarnings';
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($item->isDir()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subPath = str_replace(\DIRECTORY_SEPARATOR, '/', $subPath);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param mixed $active
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$active || !$isIgnored) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
krsort($actions);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folders = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (\in_array($subPath, self::SELECTED_FOLDERS)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (empty($folders)) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!$item->isDot() && !$item->isDir()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if ($instace->preProcess()) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Returns a list of folders warnings.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $folders;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folders = array_keys(static::getFolders());
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($iterator as $item) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileName = $item->getBasename('.php');
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$fileName = $item->getFilename();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* @param array $folders
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*/
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
continue;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$iterator = new \DirectoryIterator($dir);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$instace->setFolder($folder);
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
*
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (!\is_array($folders) && 'all' === $folders) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
const SELECTED_FOLDERS = ['SystemRequirements', 'YetiForce', 'Security', 'Mail'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
public static function getFolders()
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folder = ['id' => $i, 'text' => Language::translate($fileName, 'Settings:SystemWarnings'), 'subPath' => $subPath, 'parent' => '#'];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
if (isset($folders[$parent])) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$folders[$subPath] = $folder;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
* Returns a list of warnings instance.
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$actions = [];
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
return $actions;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$subPath = $iterator->getSubPathName();
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
/**
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
foreach ($folders as $folder) {
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
$dir = self::FOLDERS . '/' . $folder;
- Exclude checks
Spaces must be used to indent lines; tabs are not allowed Open
}
- Exclude checks