jon48/webtrees-lib

View on GitHub
app/Module/GeoDispersion/Schema/Migration2.php

Summary

Maintainability
B
4 hrs
Test Coverage

Function upgrade has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
Open

    public function upgrade(): void
    {
        if (!DB::schema()->hasTable('maj_geodispersion')) {
            return;
        }
Severity: Minor
Found in app/Module/GeoDispersion/Schema/Migration2.php - About 1 hr 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

Method upgrade has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function upgrade(): void
    {
        if (!DB::schema()->hasTable('maj_geodispersion')) {
            return;
        }
Severity: Minor
Found in app/Module/GeoDispersion/Schema/Migration2.php - About 1 hr to fix

    Method migrateGeoAnalysisMap has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function migrateGeoAnalysisMap(
            stdClass $old_view,
            Tree $tree,
            GeoAnalysisViewDataService $geoview_data_service
        ): bool {
    Severity: Minor
    Found in app/Module/GeoDispersion/Schema/Migration2.php - About 1 hr to fix

      The class Migration2 has a coupling between objects value of 18. Consider to reduce the number of dependencies under 13.
      Open

      class Migration2 implements MigrationInterface
      {
          /**
           * Mapping from old map definitions to new ones
           * @var array<string,mixed> MAPS_XML_MAPPING

      CouplingBetweenObjects

      Since: 1.1.0

      A class with too many dependencies has negative impacts on several quality aspects of a class. This includes quality criteria like stability, maintainability and understandability

      Example

      class Foo {
          /**
           * @var \foo\bar\X
           */
          private $x = null;
      
          /**
           * @var \foo\bar\Y
           */
          private $y = null;
      
          /**
           * @var \foo\bar\Z
           */
          private $z = null;
      
          public function setFoo(\Foo $foo) {}
          public function setBar(\Bar $bar) {}
          public function setBaz(\Baz $baz) {}
      
          /**
           * @return \SplObjectStorage
           * @throws \OutOfRangeException
           * @throws \InvalidArgumentException
           * @throws \ErrorException
           */
          public function process(\Iterator $it) {}
      
          // ...
      }

      Source https://phpmd.org/rules/design.html#couplingbetweenobjects

      Avoid using static access to class '\Spatie\Color\Hex' in method 'colorsFromMap'.
      Open

              $default = Hex::fromString('#f5f5f5');

      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 '\Spatie\Color\Hex' in method 'colorsFromMap'.
      Open

              $stroke = Hex::fromString('#d5d5d5');

      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 upgrade uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                      } else {
                          DB::connection()->rollBack();
                      }

      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 using static access to class '\Spatie\Color\Hex' in method 'colorsFromMap'.
      Open

                      return new MapColorsConfig($default, $stroke, Hex::fromString('#e2a61d'), $hover);

      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 '\Spatie\Color\Hex' in method 'colorsFromMap'.
      Open

                      return new MapColorsConfig($default, $stroke, Hex::fromString('#44aa00'), $hover);

      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 '\Fisharebest\Webtrees\FlashMessages' in method 'upgrade'.
      Open

              FlashMessages::addMessage(I18N::translate(
                  'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.'
              ));

      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 '\Spatie\Color\Hex' in method 'colorsFromMap'.
      Open

                      return new MapColorsConfig($default, $stroke, Hex::fromString('#0493ab'), $hover);

      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 '\Spatie\Color\Hex' in method 'colorsFromMap'.
      Open

              $hover = Hex::fromString('#ff6600');

      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 upgrade uses an else expression. Else clauses are basically not necessary and you can simplify the code by not using them.
      Open

                  } else {
                      DB::connection()->beginTransaction();
                      if ($this->migrateGeoAnalysisMap($old_view, $tree, $geoview_data_service)) {
                          DB::connection()->commit();
                      } else {

      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 using static access to class '\Fisharebest\Webtrees\I18N' in method 'upgrade'.
      Open

              FlashMessages::addMessage(I18N::translate(
                  'The geographical dispersion analyses have been migrated for webtrees 2. Please review their settings.'
              ));

      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 excessively long variable names like $map_definition_service. Keep variable name length under 20.
      Open

              $map_definition_service = app(MapDefinitionsService::class);

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#longvariable

      Avoid excessively long variable names like $mapadapter_data_service. Keep variable name length under 20.
      Open

              $mapadapter_data_service = app(MapAdapterDataService::class);

      LongVariable

      Since: 0.2

      Detects when a field, formal or local variable is declared with a long name.

      Example

      class Something {
          protected $reallyLongIntName = -3; // VIOLATION - Field
          public static function main( array $interestingArgumentsList[] ) { // VIOLATION - Formal
              $otherReallyLongName = -5; // VIOLATION - Local
              for ($interestingIntIndex = 0; // VIOLATION - For
                   $interestingIntIndex < 10;
                   $interestingIntIndex++ ) {
              }
          }
      }

      Source https://phpmd.org/rules/naming.html#longvariable

      There are no issues that match your filters.

      Category
      Status