src/Patch/Definition/NormalizerComponents/BasePathComponent.php
Method normalize
has 55 lines of code (exceeds 25 allowed). Consider refactoring. Open
Open
public function normalize($target, $label, array $data, array $ownerConfig)
{
if ($this->shouldSkip($ownerConfig, $data)) {
return array();
}
Avoid too many return
statements within this method. Open
Open
return $templates;
Reduce the number of returns of this function 5, down to the maximum allowed 3. Open
Open
private function resolveTemplate($ownerConfig, $packageName)
- 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; }
Missing class import via use statement (line '21', column '36'). Open
Open
$this->templateUtils = new \Vaimo\ComposerPatches\Utils\TemplateUtils();
- 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
Define a constant instead of duplicating this literal "label" 3 times. Open
Open
'label' => $label
- Read upRead up
- Exclude checks
Duplicated string literals make the process of refactoring error-prone, since you must be sure to update all occurrences.
On the other hand, constants can be referenced from many places, but only need to be updated in a single place.
Noncompliant Code Example
With the default threshold of 3:
function run() { prepare('action1'); // Non-Compliant - 'action1' is duplicated 3 times execute('action1'); release('action1'); }
Compliant Solution
ACTION_1 = 'action1'; function run() { prepare(ACTION_1); execute(ACTION_1); release(ACTION_1); }
Exceptions
To prevent generating some false-positives, literals having less than 5 characters are excluded.