CORE-POS/IS4C

View on GitHub
fannie/cron/tasks/ProductSummarizeLastQuarter.php

Summary

Maintainability
F
6 days
Test Coverage
F
0%

Function weightedAverages has a Cognitive Complexity of 120 (exceeds 5 allowed). Consider refactoring.
Open

    private function weightedAverages($dbc)
    {
        // now do weighted averages
        $this->cronMsg('Calculating weighted averages', FannieLogger::INFO);
        $dbc->query('TRUNCATE TABLE productSummaryLastQuarter');
Severity: Minor
Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 2 days 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 weightedAverages has 237 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    private function weightedAverages($dbc)
    {
        // now do weighted averages
        $this->cronMsg('Calculating weighted averages', FannieLogger::INFO);
        $dbc->query('TRUNCATE TABLE productSummaryLastQuarter');
Severity: Major
Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 1 day to fix

    File ProductSummarizeLastQuarter.php has 372 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /*******************************************************************************
    
        Copyright 2013 Whole Foods Co-op
    
    
    Severity: Minor
    Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 4 hrs to fix

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

          public function run()
          {
              global $FANNIE_OP_DB, $FANNIE_TRANS_DB, $FANNIE_ARCHIVE_DB;
      
              $dbc = FannieDB::get($FANNIE_ARCHIVE_DB);
      Severity: Minor
      Found in fannie/cron/tasks/ProductSummarizeLastQuarter.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 run has 89 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function run()
          {
              global $FANNIE_OP_DB, $FANNIE_TRANS_DB, $FANNIE_ARCHIVE_DB;
      
              $dbc = FannieDB::get($FANNIE_ARCHIVE_DB);
      Severity: Major
      Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 3 hrs to fix

        Avoid deeply nested control flow statements.
        Open

                                if ($i <= 5) {
                                    $totalCache5W['super'][$row['superID']][$weekID] = $totals['super'];
                                    $totalCache5W['dept'][$row['department']][$weekID] = $totals['dept'];
                                }
        Severity: Major
        Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

          Avoid deeply nested control flow statements.
          Open

                                  if ($i <= 1) {
                                      $totalCache1W['dept'][$row['department']][$weekID] = $totals['dept'];
                                  }
          Severity: Major
          Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                    if ($weekID <= 5) {
                                        $totalCache5W['store'][$storeID][$weekID] = $totals['store'];
                                        $totalCache5W['super'][$row['superID']][$weekID] = $totals['super'];
                                        $totalCache5W['dept'][$row['department']][$weekID] = $totals['dept'];
                                    }
            Severity: Major
            Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                                      if ($weekID <= 1) {
                                          $totalCache1W['store'][$storeID][$weekID] = $totals['store'];
                                          $totalCache1W['super'][$row['superID']][$weekID] = $totals['super'];
                                          $totalCache1W['dept'][$row['department']][$weekID] = $totals['dept'];
                                      }
              Severity: Major
              Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                        if ($i <= 5) {
                                            $totalCache5W['dept'][$row['department']][$weekID] = $totals['dept'];
                                        }
                Severity: Major
                Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                          if ($weekID <= 2) {
                                              $totalCache2W['store'][$storeID][$weekID] = $totals['store'];
                                              $totalCache2W['super'][$row['superID']][$weekID] = $totals['super'];
                                              $totalCache2W['dept'][$row['department']][$weekID] = $totals['dept'];
                                          }
                  Severity: Major
                  Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                            if ($i <= 2) {
                                                $totalCache2W['dept'][$row['department']][$weekID] = $totals['dept'];
                                            }
                    Severity: Major
                    Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                              if ($i <= 1) {
                                                  $totalCache1W['super'][$row['superID']][$weekID] = $totals['super'];
                                                  $totalCache1W['dept'][$row['department']][$weekID] = $totals['dept'];
                                              }
                      Severity: Major
                      Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                                if ($i <= 2) {
                                                    $totalCache2W['super'][$row['superID']][$weekID] = $totals['super'];
                                                    $totalCache2W['dept'][$row['department']][$weekID] = $totals['dept'];
                                                }
                        Severity: Major
                        Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php - About 45 mins to fix

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

                                          if (!isset($totalCache['dept'][$row['department']])) {
                                              $totalCache['dept'][$row['department']] = array();
                                              $totalCache1W['dept'][$row['department']] = array();
                                              $totalCache2W['dept'][$row['department']] = array();
                                              $totalCache5W['dept'][$row['department']] = array();
                          Severity: Major
                          Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php and 1 other location - About 1 hr to fix
                          fannie/cron/tasks/ProductSummarizeLastQuarter.php on lines 291..296

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

                          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 (!isset($totalCache['super'][$row['superID']])) {
                                              $totalCache['super'][$row['superID']] = array();
                                              $totalCache1W['super'][$row['superID']] = array();
                                              $totalCache2W['super'][$row['superID']] = array();
                                              $totalCache5W['super'][$row['superID']] = array();
                          Severity: Major
                          Found in fannie/cron/tasks/ProductSummarizeLastQuarter.php and 1 other location - About 1 hr to fix
                          fannie/cron/tasks/ProductSummarizeLastQuarter.php on lines 297..302

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

                          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