fisharebest/webtrees

View on GitHub
app/GedcomRecord.php

Summary

Maintainability
F
5 days
Test Coverage

File GedcomRecord.php has 638 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

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

    GedcomRecord has 48 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class GedcomRecord
    {
        public const RECORD_TYPE = 'UNKNOWN';
    
        protected const ROUTE_NAME = GedcomRecordPage::class;
    Severity: Minor
    Found in app/GedcomRecord.php - About 6 hrs to fix

      Function extractNamesFromFacts has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function extractNamesFromFacts(int $level, string $fact_type, Collection $facts): void
          {
              $sublevel    = $level + 1;
              $subsublevel = $sublevel + 1;
              foreach ($facts as $fact) {
      Severity: Minor
      Found in app/GedcomRecord.php - About 3 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 updateFact has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          public function updateFact(string $fact_id, string $gedcom, bool $update_chan): void
          {
              // Not all record types allow a CHAN event.
              $update_chan = $update_chan && in_array(static::RECORD_TYPE, Gedcom::RECORDS_WITH_CHAN, true);
      
      
      Severity: Minor
      Found in app/GedcomRecord.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

      Method updateFact has 51 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function updateFact(string $fact_id, string $gedcom, bool $update_chan): void
          {
              // Not all record types allow a CHAN event.
              $update_chan = $update_chan && in_array(static::RECORD_TYPE, Gedcom::RECORDS_WITH_CHAN, true);
      
      
      Severity: Major
      Found in app/GedcomRecord.php - About 2 hrs to fix

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

            public function facts(
                array $filter = [],
                bool $sort = false,
                int $access_level = null,
                bool $ignore_deleted = false
        Severity: Minor
        Found in app/GedcomRecord.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 facts has 37 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function facts(
                array $filter = [],
                bool $sort = false,
                int $access_level = null,
                bool $ignore_deleted = false
        Severity: Minor
        Found in app/GedcomRecord.php - About 1 hr to fix

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

              public function getSecondaryName(): int
              {
                  if ($this->getSecondaryName === null) {
                      // Generally, the primary and secondary names are the same
                      $this->getSecondaryName = $this->getPrimaryName();
          Severity: Minor
          Found in app/GedcomRecord.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 canShowRecord has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
          Open

              private function canShowRecord(int $access_level): bool
              {
                  // This setting would better be called "$ENABLE_PRIVACY"
                  if (!$this->tree->getPreference('HIDE_LIVE_PEOPLE')) {
                      return true;
          Severity: Minor
          Found in app/GedcomRecord.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 parseFacts has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
          Open

              private function parseFacts(): array
              {
                  // Split the record into facts
                  if ($this->gedcom !== '') {
                      $gedcom_facts = preg_split('/\n(?=1)/', $this->gedcom);
          Severity: Minor
          Found in app/GedcomRecord.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 parseFacts has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function parseFacts(): array
              {
                  // Split the record into facts
                  if ($this->gedcom !== '') {
                      $gedcom_facts = preg_split('/\n(?=1)/', $this->gedcom);
          Severity: Minor
          Found in app/GedcomRecord.php - About 1 hr to fix

            Method canShowRecord has 27 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function canShowRecord(int $access_level): bool
                {
                    // This setting would better be called "$ENABLE_PRIVACY"
                    if (!$this->tree->getPreference('HIDE_LIVE_PEOPLE')) {
                        return true;
            Severity: Minor
            Found in app/GedcomRecord.php - About 1 hr to fix

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

                  public function updateRecord(string $gedcom, bool $update_chan): void
                  {
                      // Not all record types allow a CHAN event.
                      $update_chan = $update_chan && in_array(static::RECORD_TYPE, Gedcom::RECORDS_WITH_CHAN, true);
              
              
              Severity: Minor
              Found in app/GedcomRecord.php - About 1 hr to fix

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

                    public function lastChangeTimestamp(): TimestampInterface
                    {
                        $chan = $this->facts(['CHAN'])->first();
                
                        if ($chan instanceof Fact) {
                Severity: Minor
                Found in app/GedcomRecord.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 getPrimaryName has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getPrimaryName(): int
                    {
                        static $language_script;
                
                        $language_script ??= I18N::locale()->script()->code();
                Severity: Minor
                Found in app/GedcomRecord.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 removeLinks has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function removeLinks(string $xref, bool $update_chan): void
                    {
                        $value = '@' . $xref . '@';
                
                        foreach ($this->facts() as $fact) {
                Severity: Minor
                Found in app/GedcomRecord.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 getAllNames has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function getAllNames(): array
                    {
                        if ($this->getAllNames === []) {
                            if ($this->canShowName()) {
                                // Ask the record to extract its names
                Severity: Minor
                Found in app/GedcomRecord.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 $this->canShowByType($access_level);
                Severity: Major
                Found in app/GedcomRecord.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

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

                    Avoid too many return statements within this method.
                    Open

                                return $individual_privacy[$this->xref()] >= $access_level;
                    Severity: Major
                    Found in app/GedcomRecord.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

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

                        Function updateRecord has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function updateRecord(string $gedcom, bool $update_chan): void
                            {
                                // Not all record types allow a CHAN event.
                                $update_chan = $update_chan && in_array(static::RECORD_TYPE, Gedcom::RECORDS_WITH_CHAN, true);
                        
                        
                        Severity: Minor
                        Found in app/GedcomRecord.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

                        Function getAllEventPlaces has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public function getAllEventPlaces(array $events): array
                            {
                                $places = [];
                                foreach ($this->facts($events) as $event) {
                                    if (preg_match_all('/\n(?:2 PLAC|3 (?:ROMN|FONE|_HEB)) +(.+)/', $event->gedcom(), $ged_places)) {
                        Severity: Minor
                        Found in app/GedcomRecord.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

                        There are no issues that match your filters.

                        Category
                        Status