fisharebest/webtrees

View on GitHub
app/Individual.php

Summary

Maintainability
F
1 wk
Test Coverage

Function getEstimatedBirthDate has a Cognitive Complexity of 76 (exceeds 5 allowed). Consider refactoring.
Open

    public function getEstimatedBirthDate(): Date
    {
        if ($this->estimated_birth_date === null) {
            foreach ($this->getAllBirthDates() as $date) {
                if ($date->isOK()) {
Severity: Minor
Found in app/Individual.php - About 1 day 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 Individual.php has 669 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

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

    Function isDead has a Cognitive Complexity of 62 (exceeds 5 allowed). Consider refactoring.
    Open

        public function isDead(): bool
        {
            $MAX_ALIVE_AGE = (int) $this->tree->getPreference('MAX_ALIVE_AGE');
            $today_jd      = Registry::timestampFactory()->now()->julianDay();
    
    
    Severity: Minor
    Found in app/Individual.php - About 1 day 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 isRelated has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

        private static function isRelated(Individual $target, int $distance): bool
        {
            static $cache = null;
    
            $user_individual = Registry::individualFactory()->make($target->tree->getUserPreference(Auth::user(), UserInterface::PREF_TREE_ACCOUNT_XREF), $target->tree);
    Severity: Minor
    Found in app/Individual.php - About 1 day 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 getStepFamilyLabel has a Cognitive Complexity of 34 (exceeds 5 allowed). Consider refactoring.
    Open

        public function getStepFamilyLabel(Family $step_family): string
        {
            foreach ($this->childFamilies() as $family) {
                if ($family !== $step_family) {
                    // Must be a step-family
    Severity: Minor
    Found in app/Individual.php - About 5 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

    Individual has 35 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Individual extends GedcomRecord
    {
        public const RECORD_TYPE = 'INDI';
    
        // Placeholders to indicate unknown names
    Severity: Minor
    Found in app/Individual.php - About 4 hrs to fix

      Function canShowByType has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

          protected function canShowByType(int $access_level): bool
          {
              // Dead people...
              if ((int) $this->tree->getPreference('SHOW_DEAD_PEOPLE') >= $access_level && $this->isDead()) {
                  $keep_alive             = false;
      Severity: Minor
      Found in app/Individual.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

      Method getEstimatedBirthDate has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getEstimatedBirthDate(): Date
          {
              if ($this->estimated_birth_date === null) {
                  foreach ($this->getAllBirthDates() as $date) {
                      if ($date->isOK()) {
      Severity: Major
      Found in app/Individual.php - About 3 hrs to fix

        Method isDead has 67 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function isDead(): bool
            {
                $MAX_ALIVE_AGE = (int) $this->tree->getPreference('MAX_ALIVE_AGE');
                $today_jd      = Registry::timestampFactory()->now()->julianDay();
        
        
        Severity: Major
        Found in app/Individual.php - About 2 hrs to fix

          Method addName has 62 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function addName(string $type, string $value, string $gedcom): void
              {
                  ////////////////////////////////////////////////////////////////////////////
                  // Extract the structured name parts - use for "sortable" names and indexes
                  ////////////////////////////////////////////////////////////////////////////
          Severity: Major
          Found in app/Individual.php - About 2 hrs to fix

            Function addName has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function addName(string $type, string $value, string $gedcom): void
                {
                    ////////////////////////////////////////////////////////////////////////////
                    // Extract the structured name parts - use for "sortable" names and indexes
                    ////////////////////////////////////////////////////////////////////////////
            Severity: Minor
            Found in app/Individual.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 isRelated has 51 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private static function isRelated(Individual $target, int $distance): bool
                {
                    static $cache = null;
            
                    $user_individual = Registry::individualFactory()->make($target->tree->getUserPreference(Auth::user(), UserInterface::PREF_TREE_ACCOUNT_XREF), $target->tree);
            Severity: Major
            Found in app/Individual.php - About 2 hrs to fix

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

                  public function getEstimatedDeathDate(): Date
                  {
                      if ($this->estimated_death_date === null) {
                          foreach ($this->getAllDeathDates() as $date) {
                              if ($date->isOK()) {
              Severity: Minor
              Found in app/Individual.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 canShowByType has 34 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function canShowByType(int $access_level): bool
                  {
                      // Dead people...
                      if ((int) $this->tree->getPreference('SHOW_DEAD_PEOPLE') >= $access_level && $this->isDead()) {
                          $keep_alive             = false;
              Severity: Minor
              Found in app/Individual.php - About 1 hr to fix

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

                    public function childStepFamilies(): Collection
                    {
                        $step_families = new Collection();
                        $families      = $this->childFamilies();
                        foreach ($families as $family) {
                Severity: Minor
                Found in app/Individual.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 spouseStepFamilies has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                Open

                    public function spouseStepFamilies(): Collection
                    {
                        $step_families = [];
                        $families      = $this->spouseFamilies();
                
                
                Severity: Minor
                Found in app/Individual.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 createPrivateGedcomRecord has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function createPrivateGedcomRecord(int $access_level): string
                    {
                        $SHOW_PRIVATE_RELATIONSHIPS = (bool) $this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS');
                
                        $rec = '0 @' . $this->xref . '@ INDI';
                Severity: Minor
                Found in app/Individual.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

                Avoid too many return statements within this method.
                Open

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

                  Avoid too many return statements within this method.
                  Open

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

                    Avoid too many return statements within this method.
                    Open

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

                      Avoid too many return statements within this method.
                      Open

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

                        Avoid too many return statements within this method.
                        Open

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

                          Avoid too many return statements within this method.
                          Open

                                  return I18N::translate('Family with parents');
                          Severity: Major
                          Found in app/Individual.php - About 30 mins to fix

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

                                public function childFamilies(int $access_level = null): Collection
                                {
                                    $access_level ??= Auth::accessLevel($this->tree);
                            
                                    if ($this->tree->getPreference('SHOW_PRIVATE_RELATIONSHIPS') === '1') {
                            Severity: Major
                            Found in app/Individual.php and 1 other location - About 2 hrs to fix
                            app/Family.php on lines 219..238

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

                            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 2 locations. Consider refactoring.
                            Open

                                        if ($KEEP_ALIVE_YEARS_DEATH !== 0) {
                                            preg_match_all('/\n1 (?:' . implode('|', Gedcom::DEATH_EVENTS) . ').*(?:\n[2-9].*)*\n2 DATE (.+)/', $this->gedcom, $matches, PREG_SET_ORDER);
                                            foreach ($matches as $match) {
                                                $date = new Date($match[1]);
                                                if ($date->isOK() && $date->gregorianYear() + $KEEP_ALIVE_YEARS_DEATH > date('Y')) {
                            Severity: Major
                            Found in app/Individual.php and 1 other location - About 1 hr to fix
                            app/Individual.php on lines 105..114

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

                            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 2 locations. Consider refactoring.
                            Open

                                        if ($KEEP_ALIVE_YEARS_BIRTH !== 0) {
                                            preg_match_all('/\n1 (?:' . implode('|', Gedcom::BIRTH_EVENTS) . ').*(?:\n[2-9].*)*\n2 DATE (.+)/', $this->gedcom, $matches, PREG_SET_ORDER);
                                            foreach ($matches as $match) {
                                                $date = new Date($match[1]);
                                                if ($date->isOK() && $date->gregorianYear() + $KEEP_ALIVE_YEARS_BIRTH > date('Y')) {
                            Severity: Major
                            Found in app/Individual.php and 1 other location - About 1 hr to fix
                            app/Individual.php on lines 116..125

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

                            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