fisharebest/webtrees

View on GitHub
app/Fact.php

Summary

Maintainability
F
3 days
Test Coverage

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

<?php

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

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

          public function label(): string
          {
              if (str_ends_with($this->tag(), ':NOTE') && preg_match('/^@' . Gedcom::REGEX_XREF . '@$/', $this->value())) {
                  return I18N::translate('Shared note');
              }
      Severity: Minor
      Found in app/Fact.php - About 2 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

      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

      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 33 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

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

                  public function canShow(int|null $access_level = null): bool
                  {
                      $access_level ??= Auth::accessLevel($this->record->tree());
              
                      // Does this record have an explicit restriction notice?
              Severity: Minor
              Found in app/Fact.php - About 1 hr to fix

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

                    public function canShow(int|null $access_level = null): bool
                    {
                        $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::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::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 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

                        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::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 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 true;
                                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::elementFactory()->make($this->tag())->label();
                                      Severity: Major
                                      Found in app/Fact.php - About 30 mins to fix

                                        There are no issues that match your filters.

                                        Category
                                        Status