kai-jacobsen/kontentblocks

View on GitHub
core/Modules/Core/ModuleGlobalModuleProxy/ModuleGlobalModuleProxy.php

Summary

Maintainability
B
5 hrs
Test Coverage

Method setupModule has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public static function setupModule($module)
    {

        /** @var \Kontentblocks\Modules\ModuleRegistry $moduleRegistry */
        $moduleRegistry = Kontentblocks::getService('registry.modules');

    Method form has 26 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function form()
        {
            $masterId = $this->properties->parentObjectId;
            $translated = false;
            $icl = get_post_meta(get_the_ID(), '_icl_lang_duplicate_of', true);

      Function setupModule has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function setupModule($module)
          {
      
              /** @var \Kontentblocks\Modules\ModuleRegistry $moduleRegistry */
              $moduleRegistry = Kontentblocks::getService('registry.modules');
      Severity: Minor
      Found in core/Modules/Core/ModuleGlobalModuleProxy/ModuleGlobalModuleProxy.php - About 55 mins to fix

      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 validateModule has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function validateModule(Module $module)
          {
      
              if (!$module->properties->globalModule) {
                  return $module;
      Severity: Minor
      Found in core/Modules/Core/ModuleGlobalModuleProxy/ModuleGlobalModuleProxy.php - About 55 mins to fix

      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 setupModuleData has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function setupModuleData($data, $properties)
          {
              if (is_null($properties->parentObject)) {
                  return $data;
              }
      Severity: Minor
      Found in core/Modules/Core/ModuleGlobalModuleProxy/ModuleGlobalModuleProxy.php - About 45 mins to fix

      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 deleteModule has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function deleteModule(Module $module)
          {
              if ($module->properties->globalModule) {
                  $parentId = $module->properties->parentObjectId;
                  $meta = get_post_meta($parentId, '_kb_attached_to', true);
      Severity: Minor
      Found in core/Modules/Core/ModuleGlobalModuleProxy/ModuleGlobalModuleProxy.php - About 35 mins to fix

      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

      Avoid using static access to class '\Kontentblocks\Language\I18n' in method 'setupModuleData'.
      Open

                  if (I18n::wpmlActive()) {

      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 '\Kontentblocks\Kontentblocks' in method 'setupModule'.
      Open

              $moduleRegistry = Kontentblocks::getService('registry.modules');

      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

      The method validateModule uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

              } else {
                  $module->properties->state['valid'] = (get_post_status($parentId) === 'trash') ? false : true;
              }

      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 assigning values to variables in if clauses and the like (line '124', column '25').
      Open

          public static function setupModule($module)
          {
      
              /** @var \Kontentblocks\Modules\ModuleRegistry $moduleRegistry */
              $moduleRegistry = Kontentblocks::getService('registry.modules');

      IfStatementAssignment

      Since: 2.7.0

      Assignments in if clauses and the like are considered a code smell. Assignments in PHP return the right operand as their result. In many cases, this is an expected behavior, but can lead to many difficult to spot bugs, especially when the right operand could result in zero, null or an empty string and the like.

      Example

      class Foo
      {
          public function bar($flag)
          {
              if ($foo = 'bar') { // possible typo
                  // ...
              }
              if ($baz = 0) { // always false
                  // ...
              }
          }
      }

      Source http://phpmd.org/rules/cleancode.html#ifstatementassignment

      Avoid using static access to class '\Kontentblocks\Utils\Utilities' in method 'setupModule'.
      Open

                  $final = \Kontentblocks\Utils\Utilities::arrayMergeRecursive($glued, $module);

      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 unused parameters such as '$data'.
      Open

          public function save($data, $prevData)

      UnusedFormalParameter

      Since: 0.2

      Avoid passing parameters to methods or constructors and then not using those parameters.

      Example

      class Foo
      {
          private function bar($howdy)
          {
              // $howdy is not used
          }
      }

      Source https://phpmd.org/rules/unusedcode.html#unusedformalparameter

      The variable $Storage is not named in camelCase.
      Open

          public static function setupModuleData($data, $properties)
          {
              if (is_null($properties->parentObject)) {
                  return $data;
              }

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      The variable $Storage is not named in camelCase.
      Open

          public static function setupModuleData($data, $properties)
          {
              if (is_null($properties->parentObject)) {
                  return $data;
              }

      CamelCaseVariableName

      Since: 0.2

      It is considered best practice to use the camelCase notation to name variables.

      Example

      class ClassName {
          public function doSomething() {
              $data_module = new DataModule();
          }
      }

      Source

      There are no issues that match your filters.

      Category
      Status