CORE-POS/IS4C

View on GitHub
fannie/classlib2.0/item/FannieSignage.php

Summary

Maintainability
F
2 wks
Test Coverage
D
69%

File FannieSignage.php has 1134 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    Copyright 2014 Whole Foods Co-op, Duluth, MN

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

    Function loadItems has a Cognitive Complexity of 64 (exceeds 5 allowed). Consider refactoring.
    Open

        public function loadItems()
        {
            if ($this->source == 'provided') {
                return $this->items;
            }
    Severity: Minor
    Found in fannie/classlib2.0/item/FannieSignage.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

    FannieSignage has 42 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class FannieSignage 
    {
        protected $items = array();
        protected $source = '';
        protected $source_id = 0;
    Severity: Minor
    Found in fannie/classlib2.0/item/FannieSignage.php - About 5 hrs to fix

      Method loadItems has 118 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function loadItems()
          {
              if ($this->source == 'provided') {
                  return $this->items;
              }
      Severity: Major
      Found in fannie/classlib2.0/item/FannieSignage.php - About 4 hrs to fix

        Method listItems has 104 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function listItems()
            {
                // preserve values from re-posting form
                $overrides = array();
                $upc = FormLib::get('update_upc', array());
        Severity: Major
        Found in fannie/classlib2.0/item/FannieSignage.php - About 4 hrs to fix

          Method listFromBatches has 94 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              protected function listFromBatches($dbc)
              {
                  if (!is_array($this->source_id)) {
                      $this->source_id = array($this->source_id);
                  }
          Severity: Major
          Found in fannie/classlib2.0/item/FannieSignage.php - About 3 hrs to fix

            Method listFromUpcomingSale has 61 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function listFromUpcomingSale($dbc)
                {
                    $ids = '';
                    $args = array();
                    $s_def = $dbc->tableDefinition('SignProperties');
            Severity: Major
            Found in fannie/classlib2.0/item/FannieSignage.php - About 2 hrs to fix

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

                  public function formatPrice($price, $multiplier=1, $regPrice=0)
                  {
                      if ($multiplier > 1) {
                          // if the multiplier results in a nearly round number, just use the round number
                          // otherwise use two decimal places.
              Severity: Minor
              Found in fannie/classlib2.0/item/FannieSignage.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 listFromCurrentSale has 59 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  protected function listFromCurrentSale($dbc)
                  {
                      $ids = '';
                      $args = array();
                      $s_def = $dbc->tableDefinition('SignProperties');
              Severity: Major
              Found in fannie/classlib2.0/item/FannieSignage.php - About 2 hrs to fix

                Function listFromBatches has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
                Open

                    protected function listFromBatches($dbc)
                    {
                        if (!is_array($this->source_id)) {
                            $this->source_id = array($this->source_id);
                        }
                Severity: Minor
                Found in fannie/classlib2.0/item/FannieSignage.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 listFromUpcomingRetail has 49 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    protected function listFromUpcomingRetail($dbc)
                    {
                        $ids = '';
                        $args = array();
                        $s_def = $dbc->tableDefinition('SignProperties');
                Severity: Minor
                Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

                  Method listFromCurrentRetail has 45 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function listFromCurrentRetail($dbc)
                      {
                          $ids = '';
                          $args = array();
                          $s_def = $dbc->tableDefinition('SignProperties');
                  Severity: Minor
                  Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

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

                        public function drawBarcode($upc, $pdf, $x, $y, $args=array())
                        {
                            $height = isset($args['height']) ? $args['height'] : 16;
                            $width = isset($args['width']) ? $args['width'] : 0.35;
                            $align = isset($args['align']) ? $args['align'] : 'C';
                    Severity: Minor
                    Found in fannie/classlib2.0/item/FannieSignage.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 listItems has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        public function listItems()
                        {
                            // preserve values from re-posting form
                            $overrides = array();
                            $upc = FormLib::get('update_upc', array());
                    Severity: Minor
                    Found in fannie/classlib2.0/item/FannieSignage.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 drawBarcode has 42 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        public function drawBarcode($upc, $pdf, $x, $y, $args=array())
                        {
                            $height = isset($args['height']) ? $args['height'] : 16;
                            $width = isset($args['width']) ? $args['width'] : 0.35;
                            $align = isset($args['align']) ? $args['align'] : 'C';
                    Severity: Minor
                    Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

                      Method sortProductsByPhysicalLocation has 41 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          static function sortProductsByPhysicalLocation($dbc, $data, $storeID)
                          {
                      
                              $upcs = array();
                              foreach ($data as $k => $row) {
                      Severity: Minor
                      Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

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

                            protected function fitText($pdf, $font_size, $text, $spacing)
                            {
                                $font_shrink = 0;
                                $effective_width = $this->width - $this->left;
                                $column = $spacing[0];
                        Severity: Minor
                        Found in fannie/classlib2.0/item/FannieSignage.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 formatPrice has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public function formatPrice($price, $multiplier=1, $regPrice=0)
                            {
                                if ($multiplier > 1) {
                                    // if the multiplier results in a nearly round number, just use the round number
                                    // otherwise use two decimal places.
                        Severity: Minor
                        Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

                          Method listFromBatchBarcodes has 34 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              protected function listFromBatchBarcodes()
                              {
                                  if (!is_array($this->source_id)) {
                                      $this->source_id = array($this->source_id);
                                  }
                          Severity: Minor
                          Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

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

                                protected function listFromShelftags()
                                {
                                    $query = 'SELECT s.upc,
                                                s.description,
                                                s.description AS posDescription,
                            Severity: Minor
                            Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

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

                                  protected function unrollLikeCode($dbc, $code, $item)
                                  {
                                      $likeP = $dbc->prepare('
                                          SELECT u.upc,
                                              ' . ItemText::longBrandSQL('s', 'p') . ',
                              Severity: Minor
                              Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

                                Method fitText has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    protected function fitText($pdf, $font_size, $text, $spacing)
                                    {
                                        $font_shrink = 0;
                                        $effective_width = $this->width - $this->left;
                                        $column = $spacing[0];
                                Severity: Minor
                                Found in fannie/classlib2.0/item/FannieSignage.php - About 1 hr to fix

                                  Function printablePrice has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      protected function printablePrice($item)
                                      {
                                          $price = $item['normal_price'];
                                          if ($item['scale'] && isset($item['signMultiplier']) && $item['signMultiplier'] < 0) {
                                              $price = $this->formatScalePrice($item['normal_price'], $item['signMultiplier'], $item['nonSalePrice']);
                                  Severity: Minor
                                  Found in fannie/classlib2.0/item/FannieSignage.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

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

                                      protected static function formatOffString($price, $multiplier, $regPrice)
                                      {
                                          if ($regPrice == 0 || $multiplier == -4) {
                                              return sprintf('$%.2f', $price);
                                          } elseif ($multiplier == -1) {
                                  Severity: Minor
                                  Found in fannie/classlib2.0/item/FannieSignage.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 drawBarcode has 5 arguments (exceeds 4 allowed). Consider refactoring.
                                  Open

                                      public function drawBarcode($upc, $pdf, $x, $y, $args=array())
                                  Severity: Minor
                                  Found in fannie/classlib2.0/item/FannieSignage.php - About 35 mins to fix

                                    Avoid too many return statements within this method.
                                    Open

                                                return '4/$' . $ttl;
                                    Severity: Major
                                    Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                      Avoid too many return statements within this method.
                                      Open

                                                  return $price;
                                      Severity: Major
                                      Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                        Avoid too many return statements within this method.
                                        Open

                                                    return sprintf('$%.2f', $price);
                                        Severity: Major
                                        Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                          Avoid too many return statements within this method.
                                          Open

                                                      return '5/$' . $ttl;
                                          Severity: Major
                                          Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                            Avoid too many return statements within this method.
                                            Open

                                                        return sprintf('%d/$%d', $mult, round($mult*$price));
                                            Severity: Major
                                            Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                              Avoid too many return statements within this method.
                                              Open

                                                          return '2/$' . $ttl;
                                              Severity: Major
                                              Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                                Avoid too many return statements within this method.
                                                Open

                                                            return '5/$5';
                                                Severity: Major
                                                Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                                  Avoid too many return statements within this method.
                                                  Open

                                                              return _('BUY ONE GET ONE FREE');
                                                  Severity: Major
                                                  Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                                    Avoid too many return statements within this method.
                                                    Open

                                                                return $price;
                                                    Severity: Major
                                                    Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

                                                      Avoid too many return statements within this method.
                                                      Open

                                                                  return substr(sprintf('%.2f', $price),-2) . chr(0xA2);
                                                      Severity: Major
                                                      Found in fannie/classlib2.0/item/FannieSignage.php - About 30 mins to fix

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

                                                            protected function formatSize($size, $item)
                                                            {
                                                                $plu = ltrim($item['upc'], '0');
                                                                if (strlen($plu) < 5 && strlen($plu) > 0 && $item['scale']) {
                                                                    return 'PLU# ' . ltrim($item['upc'], '0'); // show PLU #s on by-weight
                                                        Severity: Minor
                                                        Found in fannie/classlib2.0/item/FannieSignage.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

                                                            static function sortProductsByPhysicalLocation($dbc, $data, $storeID)
                                                            {
                                                        
                                                                $upcs = array();
                                                                foreach ($data as $k => $row) {
                                                        Severity: Major
                                                        Found in fannie/classlib2.0/item/FannieSignage.php and 1 other location - About 1 day to fix
                                                        fannie/admin/labels/pdf_layouts/FpdfLib.php on lines 107..156

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

                                                        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

                                                            protected function listFromUpcomingSale($dbc)
                                                            {
                                                                $ids = '';
                                                                $args = array();
                                                                $s_def = $dbc->tableDefinition('SignProperties');
                                                        Severity: Major
                                                        Found in fannie/classlib2.0/item/FannieSignage.php and 1 other location - About 1 day to fix
                                                        fannie/classlib2.0/item/FannieSignage.php on lines 510..564

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

                                                        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

                                                            protected function listFromUpcomingRetail($dbc)
                                                            {
                                                                $ids = '';
                                                                $args = array();
                                                                $s_def = $dbc->tableDefinition('SignProperties');
                                                        Severity: Major
                                                        Found in fannie/classlib2.0/item/FannieSignage.php and 1 other location - About 1 day to fix
                                                        fannie/classlib2.0/item/FannieSignage.php on lines 632..698

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

                                                        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