fisharebest/webtrees

View on GitHub
app/Fact.php

Summary

Maintainability
F
3 days
Test Coverage

File Fact.php has 514 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2022 webtrees development team
Severity: Major
Found in app/Fact.php - About 1 day to fix

    Fact has 29 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Fact
    {
        private const FACT_ORDER = [
            'BIRT',
            '_HNM',
    Severity: Minor
    Found in app/Fact.php - About 3 hrs to fix

      Function summary has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
      Open

          public function summary(): string
          {
              $attributes = [];
              $target     = $this->target();
              if ($target instanceof GedcomRecord) {
      Severity: Minor
      Found in app/Fact.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

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

          public function label(): string
          {
              // Marriages
              if ($this->tag() === 'FAM:MARR') {
                  $element = Registry::elementFactory()->make('FAM:MARR:TYPE');
      Severity: Minor
      Found in app/Fact.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 target has 37 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function target()
          {
              if (!preg_match('/^@(' . Gedcom::REGEX_XREF . ')@$/', $this->value(), $match)) {
                  return null;
              }
      Severity: Minor
      Found in app/Fact.php - About 1 hr to fix

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

            public static function typeComparator(): Closure
            {
                static $factsort = [];
        
                if ($factsort === []) {
        Severity: Minor
        Found in app/Fact.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 typeComparator has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function typeComparator(): Closure
            {
                static $factsort = [];
        
                if ($factsort === []) {
        Severity: Minor
        Found in app/Fact.php - About 1 hr to fix

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

              public static function sortFacts(Collection $unsorted): Collection
              {
                  $dated    = [];
                  $nondated = [];
                  $sorted   = [];
          Severity: Minor
          Found in app/Fact.php - About 1 hr to fix

            Method summary has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function summary(): string
                {
                    $attributes = [];
                    $target     = $this->target();
                    if ($target instanceof GedcomRecord) {
            Severity: Minor
            Found in app/Fact.php - About 1 hr to fix

              Function sortFacts has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
              Open

                  public static function sortFacts(Collection $unsorted): Collection
                  {
                      $dated    = [];
                      $nondated = [];
                      $sorted   = [];
              Severity: Minor
              Found in app/Fact.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

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

                  public function name(): string
                  {
                      $items  = [$this->label()];
                      $target = $this->target();
              
              
              Severity: Minor
              Found in app/Fact.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 getNotes has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function getNotes(): array
                  {
                      $notes = [];
                      preg_match_all('/\n2 NOTE ?(.*(?:\n3.*)*)/', $this->gedcom(), $matches);
                      foreach ($matches[1] as $match) {
              Severity: Minor
              Found in app/Fact.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 canShow has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  public function canShow(int $access_level = null): bool
                  {
                      $access_level = $access_level ?? Auth::accessLevel($this->record->tree());
              
                      // Does this record have an explicit restriction notice?
              Severity: Minor
              Found in app/Fact.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

              Function dateComparator has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
              Open

                  private static function dateComparator(): Closure
                  {
                      return static function (Fact $a, Fact $b): int {
                          if ($a->date()->isOK() && $b->date()->isOK()) {
                              // If both events have dates, compare by date
              Severity: Minor
              Found in app/Fact.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 too many return statements within this method.
              Open

                              return Registry::submissionFactory()->make($xref, $this->record()->tree());
              Severity: Major
              Found in app/Fact.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return Registry::repositoryFactory()->make($xref, $this->record()->tree());
                Severity: Major
                Found in app/Fact.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                          return true;
                  Severity: Major
                  Found in app/Fact.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                    return Registry::submitterFactory()->make($xref, $this->record()->tree());
                    Severity: Major
                    Found in app/Fact.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                      return Registry::locationFactory()->make($xref, $this->record()->tree());
                      Severity: Major
                      Found in app/Fact.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $fact_privacy[$this->tag] >= $access_level;
                        Severity: Major
                        Found in app/Fact.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return Registry::gedcomRecordFactory()->make($xref, $this->record()->tree());
                          Severity: Major
                          Found in app/Fact.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return Registry::sourceFactory()->make($xref, $this->record()->tree());
                            Severity: Major
                            Found in app/Fact.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                              return Registry::noteFactory()->make($xref, $this->record()->tree());
                              Severity: Major
                              Found in app/Fact.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                                return Registry::mediaFactory()->make($xref, $this->record()->tree());
                                Severity: Major
                                Found in app/Fact.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return $individual_fact_privacy[$xref][$this->tag] >= $access_level;
                                  Severity: Major
                                  Found in app/Fact.php - About 30 mins to fix

                                    There are no issues that match your filters.

                                    Category
                                    Status