CORE-POS/IS4C

View on GitHub
pos/is4c-nf/parser/parse/UPC.php

Summary

Maintainability
F
1 wk
Test Coverage
F
55%

File UPC.php has 686 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    Copyright 2007 Whole Foods Co-op

Severity: Major
Found in pos/is4c-nf/parser/parse/UPC.php - About 1 day to fix

    Function handleItem has a Cognitive Complexity of 57 (exceeds 5 allowed). Consider refactoring.
    Open

        private function handleItem($upc, $row, $scaleStickerItem, $scalepriceUPC, $scalepriceEAN)
        {
            $ret = $this->default_json();
            $myUrl = MiscLib::baseURL();
            $dbc = Database::pDataConnect();
    Severity: Minor
    Found in pos/is4c-nf/parser/parse/UPC.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

    Method handleItem has 209 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private function handleItem($upc, $row, $scaleStickerItem, $scalepriceUPC, $scalepriceEAN)
        {
            $ret = $this->default_json();
            $myUrl = MiscLib::baseURL();
            $dbc = Database::pDataConnect();
    Severity: Major
    Found in pos/is4c-nf/parser/parse/UPC.php - About 1 day to fix

      UPC has 23 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class UPC extends Parser 
      {
          /**
            Defines how the UPC was entered.
            Known good values are:
      Severity: Minor
      Found in pos/is4c-nf/parser/parse/UPC.php - About 2 hrs to fix

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

            private function lookupItem($upc)
            {
                $dbc = Database::pDataConnect();
                $query = "SELECT inUse,upc,description,normal_price,scale,deposit,
                    qttyEnforced,department,local,tax,foodstamp,discount,
        Severity: Minor
        Found in pos/is4c-nf/parser/parse/UPC.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 lookupItem has 46 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function lookupItem($upc)
            {
                $dbc = Database::pDataConnect();
                $query = "SELECT inUse,upc,description,normal_price,scale,deposit,
                    qttyEnforced,department,local,tax,foodstamp,discount,
        Severity: Minor
        Found in pos/is4c-nf/parser/parse/UPC.php - About 1 hr to fix

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

              private function rewriteScaleSticker($upc)
              {
                  if ($upc == '0028491108110' || $upc == '0028491108310' || $upc == '0028491108010' || $upc == '0028491108210') {
                      return array($upc, false, 0, 0);
                  }
          Severity: Minor
          Found in pos/is4c-nf/parser/parse/UPC.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 addDeposit has 38 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function addDeposit($upc)
              {
                  $upc = str_pad($upc,13,'0',STR_PAD_LEFT);
          
                  $dbc = Database::pDataConnect();
          Severity: Minor
          Found in pos/is4c-nf/parser/parse/UPC.php - About 1 hr to fix

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

                private function rewriteScaleSticker($upc)
                {
                    if ($upc == '0028491108110' || $upc == '0028491108310' || $upc == '0028491108010' || $upc == '0028491108210') {
                        return array($upc, false, 0, 0);
                    }
            Severity: Minor
            Found in pos/is4c-nf/parser/parse/UPC.php - About 1 hr to fix

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

                  private function enforceSaleLimit($dbc, $row, $quantity)
                  {
                      if ($row['specialpricemethod'] == 7) {
                          return $row;
                      }
              Severity: Minor
              Found in pos/is4c-nf/parser/parse/UPC.php - About 1 hr to fix

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

                    function parse($str)
                    {
                        $this->source = $this->getPrefix($str);
                        if ($this->source == self::GS1_ITEM_PREFIX ||
                            $this->source == self::GS1_EXPANDED_PREFIX) {
                Severity: Minor
                Found in pos/is4c-nf/parser/parse/UPC.php - About 1 hr to fix

                  Consider simplifying this complex logical expression.
                  Open

                          if ($row['scale'] == 1 
                              && $this->session->get("lastWeight") > 0 && $this->session->get("weight") > 0
                              && abs($this->session->get("weight") - $this->session->get("lastWeight")) < 0.0005
                              && !$scaleStickerItem && abs($row['normal_price']) > 0.01
                              && $this->session->get('msgrepeat') == 0) {
                  Severity: Major
                  Found in pos/is4c-nf/parser/parse/UPC.php - About 1 hr to fix

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

                        public function sanitizeUPC($entered)
                        {
                            // leading/trailing whitespace creates issues
                            $entered = trim($entered);
                    
                    
                    Severity: Minor
                    Found in pos/is4c-nf/parser/parse/UPC.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 nonProductUPCs has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function nonProductUPCs($upc, $ret)
                        {
                            $dbc = Database::pDataConnect();
                            $objs = is_array($this->session->get("SpecialUpcClasses")) ? $this->session->get('SpecialUpcClasses') : array();
                            foreach($objs as $className){
                    Severity: Minor
                    Found in pos/is4c-nf/parser/parse/UPC.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 enforceSaleLimit has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function enforceSaleLimit($dbc, $row, $quantity)
                        {
                            if ($row['specialpricemethod'] == 7) {
                                return $row;
                            }
                    Severity: Minor
                    Found in pos/is4c-nf/parser/parse/UPC.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

                    Method handleItem has 5 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                        private function handleItem($upc, $row, $scaleStickerItem, $scalepriceUPC, $scalepriceEAN)
                    Severity: Minor
                    Found in pos/is4c-nf/parser/parse/UPC.php - About 35 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return $ret;
                      Severity: Major
                      Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                    return $ret;
                        Severity: Major
                        Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                                          return $ret;
                          Severity: Major
                          Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                            Avoid too many return statements within this method.
                            Open

                                            return $ret;
                            Severity: Major
                            Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                              Avoid too many return statements within this method.
                              Open

                                      return $ret;
                              Severity: Major
                              Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                                Avoid too many return statements within this method.
                                Open

                                            return $ret;
                                Severity: Major
                                Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                                  Avoid too many return statements within this method.
                                  Open

                                              return $ret;
                                  Severity: Major
                                  Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return $ret;
                                    Severity: Major
                                    Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return $ret;
                                      Severity: Major
                                      Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                        return $ret;
                                        Severity: Major
                                        Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                      return $ret;
                                          Severity: Major
                                          Found in pos/is4c-nf/parser/parse/UPC.php - About 30 mins to fix

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

                                                function parse($str)
                                                {
                                                    $this->source = $this->getPrefix($str);
                                                    if ($this->source == self::GS1_ITEM_PREFIX ||
                                                        $this->source == self::GS1_EXPANDED_PREFIX) {
                                            Severity: Minor
                                            Found in pos/is4c-nf/parser/parse/UPC.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 expandUPCE has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                            Open

                                                public function expandUPCE($entered)
                                                {
                                                    $par6 = substr($entered, -1);
                                                    if ($par6 == 0) $entered = substr($entered, 0, 3)."00000".substr($entered, 3, 3);
                                                    elseif ($par6 == 1) $entered = substr($entered, 0, 3)."10000".substr($entered, 3, 3);
                                            Severity: Minor
                                            Found in pos/is4c-nf/parser/parse/UPC.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

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

                                                public function expandUPCE($entered)
                                                {
                                                    $par6 = substr($entered, -1);
                                                    if ($par6 == 0) $entered = substr($entered, 0, 3)."00000".substr($entered, 3, 3);
                                                    elseif ($par6 == 1) $entered = substr($entered, 0, 3)."10000".substr($entered, 3, 3);
                                            Severity: Major
                                            Found in pos/is4c-nf/parser/parse/UPC.php and 1 other location - About 1 day to fix
                                            fannie/classlib2.0/lib/BarcodeLib.php on lines 58..69

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

                                            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