fisharebest/webtrees

View on GitHub
app/Statistics/Repository/FamilyRepository.php

Summary

Maintainability
F
1 wk
Test Coverage

File FamilyRepository.php has 1009 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

/**
 * webtrees: online genealogy
 * Copyright (C) 2023 webtrees development team
Severity: Major
Found in app/Statistics/Repository/FamilyRepository.php - About 2 days to fix

    FamilyRepository has 80 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FamilyRepository
    {
        private CenturyService $century_service;
    
        private ColorService $color_service;
    Severity: Major
    Found in app/Statistics/Repository/FamilyRepository.php - About 1 day to fix

      Function ageOfMarriageQuery has a Cognitive Complexity of 37 (exceeds 5 allowed). Consider refactoring.
      Open

          private function ageOfMarriageQuery(string $type, string $age_dir, int $total): string
          {
              $hrows = DB::table('families')
                  ->where('f_file', '=', $this->tree->id())
                  ->join('dates AS married', static function (JoinClause $join): void {
      Severity: Minor
      Found in app/Statistics/Repository/FamilyRepository.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

      Method ageOfMarriageQuery has 136 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function ageOfMarriageQuery(string $type, string $age_dir, int $total): string
          {
              $hrows = DB::table('families')
                  ->where('f_file', '=', $this->tree->id())
                  ->join('dates AS married', static function (JoinClause $join): void {
      Severity: Major
      Found in app/Statistics/Repository/FamilyRepository.php - About 5 hrs to fix

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

            private function marriageQuery(string $type, string $age_dir, string $sex, bool $show_years): string
            {
                if ($sex === 'F') {
                    $sex_field = 'f_wife';
                } else {
        Severity: Major
        Found in app/Statistics/Repository/FamilyRepository.php - About 2 hrs to fix

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

              private function parentsQuery(string $type, string $age_dir, string $sex, bool $show_years): string
              {
                  if ($sex === 'F') {
                      $sex_field = 'WIFE';
                  } else {
          Severity: Major
          Found in app/Statistics/Repository/FamilyRepository.php - About 2 hrs to fix

            Method ageBetweenSpousesQuery has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function ageBetweenSpousesQuery(string $age_dir, int $total): array
                {
                    $query = DB::table('families')
                        ->where('f_file', '=', $this->tree->id())
                        ->join('dates AS wife', static function (JoinClause $join): void {
            Severity: Minor
            Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

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

                  private function marriageQuery(string $type, string $age_dir, string $sex, bool $show_years): string
                  {
                      if ($sex === 'F') {
                          $sex_field = 'f_wife';
                      } else {
              Severity: Minor
              Found in app/Statistics/Repository/FamilyRepository.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 parentsQuery has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
              Open

                  private function parentsQuery(string $type, string $age_dir, string $sex, bool $show_years): string
                  {
                      if ($sex === 'F') {
                          $sex_field = 'WIFE';
                      } else {
              Severity: Minor
              Found in app/Statistics/Repository/FamilyRepository.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 topTenGrandFamilyQuery has 38 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function topTenGrandFamilyQuery(int $total): array
                  {
                      return DB::table('families')
                          ->join('link AS children', static function (JoinClause $join): void {
                              $join
              Severity: Minor
              Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

                Method monthFirstChildQuery has 31 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    public function monthFirstChildQuery(int $year1 = -1, int $year2 = -1): Builder
                    {
                        $first_child_subquery = DB::table('link')
                            ->join('dates', static function (JoinClause $join): void {
                                $join
                Severity: Minor
                Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

                  Method statsMarrAgeQuery has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      public function statsMarrAgeQuery(string $sex, int $year1 = -1, int $year2 = -1): array
                      {
                          $query = DB::table('dates AS married')
                              ->join('families', static function (JoinClause $join): void {
                                  $join
                  Severity: Minor
                  Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

                    Method ageBetweenSiblingsQuery has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function ageBetweenSiblingsQuery(int $total): array
                        {
                            return DB::table('link AS link1')
                                ->join('link AS link2', static function (JoinClause $join): void {
                                    $join
                    Severity: Minor
                    Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

                      Method ageBetweenSiblingsList has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          private function ageBetweenSiblingsList(int $total, bool $one): array
                          {
                              $rows  = $this->ageBetweenSiblingsQuery($total);
                              $top10 = [];
                              $dist  = [];
                      Severity: Minor
                      Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

                        Consider simplifying this complex logical expression.
                        Open

                                    if ($one && !in_array($fam->family, $dist, true)) {
                                        if ($family !== null && $child1 !== null && $child2 !== null && $child1->canShow() && $child2->canShow()) {
                                            $top10[] = [
                                                'child1' => $child1,
                                                'child2' => $child2,
                        Severity: Major
                        Found in app/Statistics/Repository/FamilyRepository.php - About 1 hr to fix

                          Function ageBetweenSiblingsList has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private function ageBetweenSiblingsList(int $total, bool $one): array
                              {
                                  $rows  = $this->ageBetweenSiblingsQuery($total);
                                  $top10 = [];
                                  $dist  = [];
                          Severity: Minor
                          Found in app/Statistics/Repository/FamilyRepository.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

                          Consider simplifying this complex logical expression.
                          Open

                                      if (
                                          $husb instanceof Individual &&
                                          $wife instanceof Individual &&
                                          ($husb->getAllDeathDates() || !$husb->isDead()) &&
                                          ($wife->getAllDeathDates() || !$wife->isDead())
                          Severity: Major
                          Found in app/Statistics/Repository/FamilyRepository.php - About 40 mins to fix

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

                                public function noChildrenFamiliesList(string $type = 'list'): string
                                {
                                    $families = DB::table('families')
                                        ->where('f_file', '=', $this->tree->id())
                                        ->where('f_numchil', '=', 0)
                            Severity: Minor
                            Found in app/Statistics/Repository/FamilyRepository.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 '<a href="' . e($family->url()) . '">' . $family->fullName() . '</a>';
                            Severity: Major
                            Found in app/Statistics/Repository/FamilyRepository.php - About 30 mins to fix

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

                                      $hrows = DB::table('families')
                                          ->where('f_file', '=', $this->tree->id())
                                          ->join('dates AS married', static function (JoinClause $join): void {
                                              $join
                                                  ->on('married.d_file', '=', 'f_file')
                              Severity: Major
                              Found in app/Statistics/Repository/FamilyRepository.php and 1 other location - About 7 hrs to fix
                              app/Statistics/Repository/FamilyRepository.php on lines 1036..1055

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

                              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

                                      $wrows = DB::table('families')
                                          ->where('f_file', '=', $this->tree->id())
                                          ->join('dates AS married', static function (JoinClause $join): void {
                                              $join
                                                  ->on('married.d_file', '=', 'f_file')
                              Severity: Major
                              Found in app/Statistics/Repository/FamilyRepository.php and 1 other location - About 7 hrs to fix
                              app/Statistics/Repository/FamilyRepository.php on lines 1015..1034

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

                              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

                                      return DB::table('link AS link1')
                                          ->join('link AS link2', static function (JoinClause $join): void {
                                              $join
                                                  ->on('link2.l_from', '=', 'link1.l_from')
                                                  ->on('link2.l_type', '=', 'link1.l_type')
                              Severity: Major
                              Found in app/Statistics/Repository/FamilyRepository.php and 1 other location - About 2 hrs to fix
                              app/Statistics/Repository/FamilyRepository.php on lines 812..831

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

                              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

                                      $row = DB::table('link AS parentfamily')
                                          ->join('link AS childfamily', static function (JoinClause $join): void {
                                              $join
                                                  ->on('childfamily.l_file', '=', 'parentfamily.l_file')
                                                  ->on('childfamily.l_from', '=', 'parentfamily.l_from')
                              Severity: Major
                              Found in app/Statistics/Repository/FamilyRepository.php and 1 other location - About 2 hrs to fix
                              app/Statistics/Repository/FamilyRepository.php on lines 307..327

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

                              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

                                  private function calculateAge(int $age): string
                                  {
                                      if ($age < 31) {
                                          return I18N::plural('%s day', '%s days', $age, I18N::number($age));
                                      }
                              Severity: Major
                              Found in app/Statistics/Repository/FamilyRepository.php and 1 other location - About 2 hrs to fix
                              app/Statistics/Repository/IndividualRepository.php on lines 969..983

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

                              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

                                      return DB::table('families')
                                          ->join('link AS children', static function (JoinClause $join): void {
                                              $join
                                                  ->on('children.l_from', '=', 'f_id')
                                                  ->on('children.l_file', '=', 'f_file')
                              Severity: Major
                              Found in app/Statistics/Repository/FamilyRepository.php and 1 other location - About 2 hrs to fix
                              app/Services/SearchService.php on lines 115..127

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

                              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