CORE-POS/IS4C

View on GitHub
fannie/item/AdvancedItemSearch.php

Summary

Maintainability
F
6 days
Test Coverage
F
49%

File AdvancedItemSearch.php has 848 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/*******************************************************************************

    Copyright 2013 Whole Foods Community Co-op

Severity: Major
Found in fannie/item/AdvancedItemSearch.php - About 2 days to fix

    AdvancedItemSearch has 44 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class AdvancedItemSearch extends FannieRESTfulPage
    {
        protected $header = 'Advanced Search';
        protected $title = 'Advanced Search';
    
    
    Severity: Minor
    Found in fannie/item/AdvancedItemSearch.php - About 6 hrs to fix

      Function filterSales has a Cognitive Complexity of 35 (exceeds 5 allowed). Consider refactoring.
      Open

          private function filterSales($items, $form)
          {
              if ($form->onsale !== '') {
      
                  $where = '1=1';
      Severity: Minor
      Found in fannie/item/AdvancedItemSearch.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 get_view has 73 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function get_view()
          {
              $dbc = $this->connection;
              $dbc->selectDB($this->config->get('OP_DB'));
      
      
      Severity: Major
      Found in fannie/item/AdvancedItemSearch.php - About 2 hrs to fix

        Method filterSales has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function filterSales($items, $form)
            {
                if ($form->onsale !== '') {
        
                    $where = '1=1';
        Severity: Major
        Found in fannie/item/AdvancedItemSearch.php - About 2 hrs to fix

          Function get_view has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
          Open

              protected function get_view()
              {
                  $dbc = $this->connection;
                  $dbc->selectDB($this->config->get('OP_DB'));
          
          
          Severity: Minor
          Found in fannie/item/AdvancedItemSearch.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 runSearchMethods has 43 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function runSearchMethods($form)
              {
                  $search = new stdClass();
                  $search->from = 'products AS p 
                          LEFT JOIN departments AS d ON p.department=d.dept_no
          Severity: Minor
          Found in fannie/item/AdvancedItemSearch.php - About 1 hr to fix

            Method streamOutput has 35 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                private function streamOutput($data) 
                {
                    $ret = '';
                    $ret .= '<table class="table search-table table-striped">';
                    $ret .= '<thead><tr>
            Severity: Minor
            Found in fannie/item/AdvancedItemSearch.php - About 1 hr to fix

              Method searchUPCs has 33 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  private function searchUPCs($search, $form)
                  {
                      if ($form->upcs !== '') {
                          $upcs = explode("\n", $form->upcs);
                          $upcs = array_map(function($i) {
              Severity: Minor
              Found in fannie/item/AdvancedItemSearch.php - About 1 hr to fix

                Method filterSavedItems has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private function filterSavedItems($items, $form)
                    {
                        $savedItems = $form->u;
                        if (is_array($savedItems) && count($savedItems) > 0) {
                            $savedQ = '
                Severity: Minor
                Found in fannie/item/AdvancedItemSearch.php - About 1 hr to fix

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

                      public function unitTest($phpunit)
                      {
                          $get = $this->get_view();
                          $phpunit->assertNotEquals(0, strlen($get));
                  
                  
                  Severity: Minor
                  Found in fannie/item/AdvancedItemSearch.php - About 1 hr to fix

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

                        private function filterSavedItems($items, $form)
                        {
                            $savedItems = $form->u;
                            if (is_array($savedItems) && count($savedItems) > 0) {
                                $savedQ = '
                    Severity: Minor
                    Found in fannie/item/AdvancedItemSearch.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 searchLikeCode has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function searchLikeCode($search, $form)
                        {
                            if ($form->likeCode !== '') {
                                if (!strstr($search->from, 'upcLike')) {
                                    $search->from .= ' LEFT JOIN upcLike AS u ON p.upc=u.upc ';
                    Severity: Minor
                    Found in fannie/item/AdvancedItemSearch.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 filterMovement has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private function filterMovement($items, $form)
                        {
                            if ($form->soldOp !== '') {
                                list($days, $store) = explode(':', $form->soldOp);
                                $movementStart = date('Y-m-d', mktime(0, 0, 0, date('n'), date('j')-$days-1, date('Y')));
                    Severity: Minor
                    Found in fannie/item/AdvancedItemSearch.php - About 1 hr to fix

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

                          private function runSearchMethods($form)
                          {
                              $search = new stdClass();
                              $search->from = 'products AS p 
                                      LEFT JOIN departments AS d ON p.department=d.dept_no
                      Severity: Minor
                      Found in fannie/item/AdvancedItemSearch.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

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

                          private function searchBrand($search, $form)
                          {
                              try {
                                  if ($form->brand !== '') {
                                      if (is_numeric($form->brand)) {
                      Severity: Minor
                      Found in fannie/item/AdvancedItemSearch.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

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

                          private function searchDiscountable($search, $form)
                          {
                              if ($form->discountable !== '') {
                                  $search->where .= ' AND p.discount=? ';
                                  if ($form->discountable == 1 || $form->discountable == 2) {
                      Severity: Minor
                      Found in fannie/item/AdvancedItemSearch.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

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

                          private function searchSuperDepartment($search, $form)
                          {
                              if ($form->superID !== '') {
                                  /**
                                    Unroll superdepartment into a list of department
                      Severity: Minor
                      Found in fannie/item/AdvancedItemSearch.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

                                  $upcs = array_map(function($i){ return BarcodeLib::padUPC(trim($i)); }, $upcs);
                      Severity: Major
                      Found in fannie/item/AdvancedItemSearch.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return $search;
                        Severity: Major
                        Found in fannie/item/AdvancedItemSearch.php - About 30 mins to fix

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

                              private function filterMovement($items, $form)
                              {
                                  if ($form->soldOp !== '') {
                                      list($days, $store) = explode(':', $form->soldOp);
                                      $movementStart = date('Y-m-d', mktime(0, 0, 0, date('n'), date('j')-$days-1, date('Y')));
                          Severity: Minor
                          Found in fannie/item/AdvancedItemSearch.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 searchSignage has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private function searchSignage($search, $form)
                              {
                                  if ($form->signinfo !== '') {
                                      if (!strstr($search->from, 'productUser')) {
                                          $search->from .= ' LEFT JOIN productUser AS s ON p.upc=s.upc ';
                          Severity: Minor
                          Found in fannie/item/AdvancedItemSearch.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 searchUPCs has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private function searchUPCs($search, $form)
                              {
                                  if ($form->upcs !== '') {
                                      $upcs = explode("\n", $form->upcs);
                                      $upcs = array_map(function($i) {
                          Severity: Minor
                          Found in fannie/item/AdvancedItemSearch.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 searchVendor has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              private function searchVendor($search, $form)
                              {
                                  if ($form->vendor === '0') {
                                      $search->where .= ' AND p.default_vendor_id=0 ';
                                  } elseif ($form->vendor !== '') {
                          Severity: Minor
                          Found in fannie/item/AdvancedItemSearch.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