fisharebest/webtrees

View on GitHub
app/Services/GedcomExportService.php

Summary

Maintainability
D
2 days
Test Coverage

Function export has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    public function export(
        Tree $tree,
        bool $sort_by_xref = false,
        string $encoding = UTF8::NAME,
        int $access_level = Auth::PRIV_HIDE,
Severity: Minor
Found in app/Services/GedcomExportService.php - About 4 hrs 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 GedcomExportService.php has 315 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2023 webtrees development team
Severity: Minor
Found in app/Services/GedcomExportService.php - About 3 hrs to fix

    Method export has 73 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function export(
            Tree $tree,
            bool $sort_by_xref = false,
            string $encoding = UTF8::NAME,
            int $access_level = Auth::PRIV_HIDE,
    Severity: Major
    Found in app/Services/GedcomExportService.php - About 2 hrs to fix

      Function wrapLongLines has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
      Open

          public function wrapLongLines(string $gedcom, int $max_line_length): string
          {
              $lines = [];
      
              foreach (explode("\n", $gedcom) as $line) {
      Severity: Minor
      Found in app/Services/GedcomExportService.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 downloadResponse has 34 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function downloadResponse(
              Tree $tree,
              bool $sort_by_xref,
              string $encoding,
              string $privacy,
      Severity: Minor
      Found in app/Services/GedcomExportService.php - About 1 hr to fix

        Method createHeader has 32 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function createHeader(Tree $tree, string $encoding, bool $include_sub): string
            {
                // Force a ".ged" suffix
                $filename = $tree->name();
        
        
        Severity: Minor
        Found in app/Services/GedcomExportService.php - About 1 hr to fix

          Method downloadResponse has 8 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  Tree $tree,
                  bool $sort_by_xref,
                  string $encoding,
                  string $privacy,
                  string $line_endings,
          Severity: Major
          Found in app/Services/GedcomExportService.php - About 1 hr to fix

            Method export has 8 arguments (exceeds 4 allowed). Consider refactoring.
            Open

                    Tree $tree,
                    bool $sort_by_xref = false,
                    string $encoding = UTF8::NAME,
                    int $access_level = Auth::PRIV_HIDE,
                    string $line_endings = 'CRLF',
            Severity: Major
            Found in app/Services/GedcomExportService.php - About 1 hr to fix

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

                  public function createHeader(Tree $tree, string $encoding, bool $include_sub): string
                  {
                      // Force a ".ged" suffix
                      $filename = $tree->name();
              
              
              Severity: Minor
              Found in app/Services/GedcomExportService.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 downloadResponse has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function downloadResponse(
                      Tree $tree,
                      bool $sort_by_xref,
                      string $encoding,
                      string $privacy,
              Severity: Minor
              Found in app/Services/GedcomExportService.php - About 25 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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                  private function familyQuery(Tree $tree, bool $sort_by_xref): Builder
                  {
                      $query = DB::table('families')
                          ->where('f_file', '=', $tree->id())
                          ->select(['f_gedcom', 'f_id']);
              Severity: Major
              Found in app/Services/GedcomExportService.php and 3 other locations - About 30 mins to fix
              app/Services/GedcomExportService.php on lines 409..422
              app/Services/GedcomExportService.php on lines 430..443
              app/Services/GedcomExportService.php on lines 451..464

              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 90.

              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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                  private function sourceQuery(Tree $tree, bool $sort_by_xref): Builder
                  {
                      $query = DB::table('sources')
                          ->where('s_file', '=', $tree->id())
                          ->select(['s_gedcom', 's_id']);
              Severity: Major
              Found in app/Services/GedcomExportService.php and 3 other locations - About 30 mins to fix
              app/Services/GedcomExportService.php on lines 387..401
              app/Services/GedcomExportService.php on lines 409..422
              app/Services/GedcomExportService.php on lines 451..464

              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 90.

              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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                  private function individualQuery(Tree $tree, bool $sort_by_xref): Builder
                  {
                      $query = DB::table('individuals')
                          ->where('i_file', '=', $tree->id())
                          ->select(['i_gedcom', 'i_id']);
              Severity: Major
              Found in app/Services/GedcomExportService.php and 3 other locations - About 30 mins to fix
              app/Services/GedcomExportService.php on lines 387..401
              app/Services/GedcomExportService.php on lines 430..443
              app/Services/GedcomExportService.php on lines 451..464

              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 90.

              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

              Similar blocks of code found in 4 locations. Consider refactoring.
              Open

                  private function mediaQuery(Tree $tree, bool $sort_by_xref): Builder
                  {
                      $query = DB::table('media')
                          ->where('m_file', '=', $tree->id())
                          ->select(['m_gedcom', 'm_id']);
              Severity: Major
              Found in app/Services/GedcomExportService.php and 3 other locations - About 30 mins to fix
              app/Services/GedcomExportService.php on lines 387..401
              app/Services/GedcomExportService.php on lines 409..422
              app/Services/GedcomExportService.php on lines 430..443

              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 90.

              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