vaimo/composer-patches

View on GitHub
src/Patch/Definition/NormalizerComponents/BasePathComponent.php

Summary

Maintainability
A
2 hrs
Test Coverage

Method normalize has 55 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function normalize($target, $label, array $data, array $ownerConfig)
    {
        if ($this->shouldSkip($ownerConfig, $data)) {
            return array();
        }
Severity: Major
Found in src/Patch/Definition/NormalizerComponents/BasePathComponent.php - About 2 hrs to fix

    Avoid too many return statements within this method.
    Open

            return $templates;
    Severity: Major
    Found in src/Patch/Definition/NormalizerComponents/BasePathComponent.php - About 30 mins to fix

      Reduce the number of returns of this function 5, down to the maximum allowed 3.
      Open

          private function resolveTemplate($ownerConfig, $packageName)

      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

              $this->templateUtils = new \Vaimo\ComposerPatches\Utils\TemplateUtils();

      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

                  'label' => $label

      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.

      There are no issues that match your filters.

      Category
      Status