Function sanitizeFileSystem
has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring. Open
public function sanitizeFileSystem(array $patches)
{
foreach ($patches as $patchGroup) {
foreach ($patchGroup as $patchInfo) {
if (!isset($patchInfo[Patch::TMP]) || !$patchInfo[Patch::TMP]) {
- 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
Function applyDefinitionKeyValueFilter
has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring. Open
public function applyDefinitionKeyValueFilter(array $patches, $filter, $key)
{
foreach ($patches as &$packagePatches) {
foreach ($packagePatches as &$patchInfo) {
if (!isset($patchInfo[$key])) {
- 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
Function applyDefinitionFilter
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function applyDefinitionFilter(array $patches, \Closure $logicProvider)
{
foreach ($patches as &$packagePatches) {
foreach ($packagePatches as &$patchData) {
$result = $logicProvider($patchData);
- 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
Function filterListByTargets
has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring. Open
public function filterListByTargets(array $patches, array $targets)
{
foreach ($patches as $target => $group) {
foreach ($group as $path => $patch) {
if (array_intersect($patch[Patch::TARGETS], $targets)) {
- 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
Reduce the number of returns of this function 4, down to the maximum allowed 3. Open
private function shouldIncludePatch($value, $filter)
- Read upRead up
- Exclude checks
Having too many return statements in a function increases the function's essential complexity because the flow of execution is broken each time a return statement is encountered. This makes it harder to read and understand the logic of the function.
Noncompliant Code Example
With the default threshold of 3:
function myFunction(){ // Noncompliant as there are 4 return statements if (condition1) { return true; } else { if (condition2) { return false; } else { return true; } } return false; }
Refactor this function to reduce its Cognitive Complexity from 16 to the 15 allowed. Open
public function sanitizeFileSystem(array $patches)
- 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 '47', column '33'). Open
$iterator = new \FilesystemIterator($dirName);
- 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();
}