fisharebest/webtrees

View on GitHub
app/Report/RightToLeftSupport.php

Summary

Maintainability
F
3 wks
Test Coverage

Function finishCurrentSpan has a Cognitive Complexity of 342 (exceeds 5 allowed). Consider refactoring.
Open

    private static function finishCurrentSpan(string &$result, bool $theEnd = false): void
    {
        $textSpan = substr($result, self::$posSpanStart);
        $result   = substr($result, 0, self::$posSpanStart);

Severity: Minor
Found in app/Report/RightToLeftSupport.php - About 1 wk 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 spanLtrRtl has a Cognitive Complexity of 223 (exceeds 5 allowed). Consider refactoring.
Open

    public static function spanLtrRtl(string $inputText): string
    {
        if ($inputText === '') {
            // Nothing to do
            return '';
Severity: Minor
Found in app/Report/RightToLeftSupport.php - About 4 days 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

File RightToLeftSupport.php has 886 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2022 webtrees development team
Severity: Major
Found in app/Report/RightToLeftSupport.php - About 2 days to fix

    Method finishCurrentSpan has 424 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function finishCurrentSpan(string &$result, bool $theEnd = false): void
        {
            $textSpan = substr($result, self::$posSpanStart);
            $result   = substr($result, 0, self::$posSpanStart);
    
    
    Severity: Major
    Found in app/Report/RightToLeftSupport.php - About 2 days to fix

      Method spanLtrRtl has 321 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function spanLtrRtl(string $inputText): string
          {
              if ($inputText === '') {
                  // Nothing to do
                  return '';
      Severity: Major
      Found in app/Report/RightToLeftSupport.php - About 1 day to fix

        Function starredName has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

            private static function starredName(string $textSpan, string $direction): string
            {
                // To avoid a TCPDF bug that mixes up the word order, insert those <u> and </u> tags
                // only when page and span directions are identical.
                if ($direction === strtoupper(I18N::direction())) {
        Severity: Minor
        Found in app/Report/RightToLeftSupport.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 starredName has 31 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private static function starredName(string $textSpan, string $direction): string
            {
                // To avoid a TCPDF bug that mixes up the word order, insert those <u> and </u> tags
                // only when page and span directions are identical.
                if ($direction === strtoupper(I18N::direction())) {
        Severity: Minor
        Found in app/Report/RightToLeftSupport.php - About 1 hr to fix

          Avoid deeply nested control flow statements.
          Open

                                      while ($tempText !== '') {
                                          $nextCharArray = self::getChar($tempText, 0);
                                          $nextLetter    = $nextCharArray['letter'];
                                          $nextLen       = $nextCharArray['length'];
                                          $tempText      = substr($tempText, $nextLen);
          Severity: Major
          Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                        if (self::$currentState === '') {
                                            $newState = 'RTL';
                                            break;
                                        }
            Severity: Major
            Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if (str_ends_with($textSpan, ' ')) {
                                          $trailingSeparator = ' ' . $trailingSeparator;
                                          $textSpan          = substr($textSpan, 0, -1);
                                          continue;
                                      }
              Severity: Major
              Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                            if (self::$currentState === 'RTL') {
                                                $currentLetter = self::UTF8_LRE . $currentLetter;
                                            }
                Severity: Major
                Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if (str_ends_with($textSpan, ' ')) {
                                              $trailingBlanks = ' ' . $trailingBlanks;
                                              $textSpan       = substr($textSpan, 0, -1);
                                              continue;
                                          }
                  Severity: Major
                  Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                while (true) {
                                                    if ($workingText === '') {
                                                        break;
                                                    }
                                                    if (str_starts_with($workingText, ' ')) {
                    Severity: Major
                    Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if (str_ends_with($textSpan, '&nbsp;')) {
                                                  $trailingSeparator = '&nbsp;' . $trailingSeparator;
                                                  $textSpan          = substr($textSpan, 0, -6);
                                                  continue;
                                              }
                      Severity: Major
                      Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if (str_ends_with($textSpan, '&nbsp;')) {
                                                    $trailingString = '&nbsp;' . $trailingString;
                                                    $textSpan       = substr($textSpan, 0, -1);
                                                    continue;
                                                }
                        Severity: Major
                        Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                                      if (substr($workingText . "\n", $offset, 6) === '&nbsp;') {
                                                          $offset += 6; // This could be numeric punctuation
                                                      } elseif (str_contains(self::NUMBER_PUNCTUATION, $charArray['letter'])) {
                                                          $offset += $charArray['length']; // This could be numeric punctuation
                                                      }
                          Severity: Major
                          Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                                    if (str_ends_with($textSpan, '-')) {
                                                        $trailingSeparator = '-' . $trailingSeparator;
                                                        $textSpan          = substr($textSpan, 0, -1);
                                                        continue;
                                                    }
                            Severity: Major
                            Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                      if (str_ends_with($textSpan, '&nbsp;')) {
                                                          $trailingBlanks = '&nbsp;' . $trailingBlanks;
                                                          $textSpan       = substr($textSpan, 0, -1);
                                                          continue;
                                                      }
                              Severity: Major
                              Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                Avoid deeply nested control flow statements.
                                Open

                                                        if (str_ends_with($textSpan, ' ')) {
                                                            $trailingString = ' ' . $trailingString;
                                                            $textSpan       = substr($textSpan, 0, -1);
                                                            continue;
                                                        }
                                Severity: Major
                                Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                  Avoid deeply nested control flow statements.
                                  Open

                                                              if (!str_contains(self::NUMBERS, $charArray['letter'])) {
                                                                  // This is not a digit. End the run of digits and punctuation.
                                                                  $numberState = false;
                                                                  if (self::$currentState === 'RTL') {
                                                                      if (!str_contains(self::NUMBER_PREFIX, $currentLetter)) {
                                  Severity: Major
                                  Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                    Avoid deeply nested control flow statements.
                                    Open

                                                                if (self::$currentState === 'RTL') {
                                                                    break;
                                                                }
                                    Severity: Major
                                    Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                      Avoid deeply nested control flow statements.
                                      Open

                                                                  if (!empty($openParDirection[$closeParIndex]) && $openParDirection[$closeParIndex] !== '?') {
                                                                      $newState = $openParDirection[$closeParIndex];
                                                                  }
                                      Severity: Major
                                      Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                        Avoid deeply nested control flow statements.
                                        Open

                                                                if (str_ends_with($textSpan, '&nbsp;')) {
                                                                    $trailingString = '&nbsp;' . $trailingString;
                                                                    $textSpan       = substr($textSpan, 0, -1);
                                                                    continue;
                                                                }
                                        Severity: Major
                                        Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                          Avoid deeply nested control flow statements.
                                          Open

                                                                  if (str_ends_with($textSpan, ' ')) {
                                                                      $trailingString = ' ' . $trailingString;
                                                                      $textSpan       = substr($textSpan, 0, -1);
                                                                      continue;
                                                                  }
                                          Severity: Major
                                          Found in app/Report/RightToLeftSupport.php - About 45 mins to fix

                                            Identical blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        if (I18N::direction() === 'rtl' && self::$previousState === 'RTL' && !$theEnd) {
                                                            $trailingString = '';
                                                            $savedSpan      = $textSpan;
                                                            while ($textSpan !== '') {
                                                                // Look for trailing spaces and tentatively move them
                                            Severity: Major
                                            Found in app/Report/RightToLeftSupport.php and 1 other location - About 1 day to fix
                                            app/Report/RightToLeftSupport.php on lines 1010..1057

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 358.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Identical blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        if (!$theEnd && I18N::direction() !== 'rtl') {
                                                            $trailingString = '';
                                                            $savedSpan      = $textSpan;
                                                            while ($textSpan !== '') {
                                                                // Look for trailing spaces and tentatively move them
                                            Severity: Major
                                            Found in app/Report/RightToLeftSupport.php and 1 other location - About 1 day to fix
                                            app/Report/RightToLeftSupport.php on lines 742..789

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 358.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Identical blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        while ($textSpan !== '') {
                                                            if (str_ends_with($textSpan, ' ')) {
                                                                $trailingBlanks = ' ' . $trailingBlanks;
                                                                $textSpan       = substr($textSpan, 0, -1);
                                                                continue;
                                            Severity: Major
                                            Found in app/Report/RightToLeftSupport.php and 1 other location - About 1 hr to fix
                                            app/Report/RightToLeftSupport.php on lines 986..998

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 111.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            Identical blocks of code found in 2 locations. Consider refactoring.
                                            Open

                                                        while ($textSpan !== '') {
                                                            if (str_ends_with($textSpan, ' ')) {
                                                                $trailingBlanks = ' ' . $trailingBlanks;
                                                                $textSpan       = substr($textSpan, 0, -1);
                                                                continue;
                                            Severity: Major
                                            Found in app/Report/RightToLeftSupport.php and 1 other location - About 1 hr to fix
                                            app/Report/RightToLeftSupport.php on lines 793..805

                                            Duplicated Code

                                            Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                            Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                            When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                            Tuning

                                            This issue has a mass of 111.

                                            We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                            The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                            If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                            See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                            Refactorings

                                            Further Reading

                                            There are no issues that match your filters.

                                            Category
                                            Status