CORE-POS/IS4C

View on GitHub
pos/is4c-nf/lib/ReceiptLib.php

Summary

Maintainability
F
1 wk
Test Coverage
C
72%

File ReceiptLib.php has 927 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

    Copyright 2001, 2004 Wedge Community Co-op

Severity: Major
Found in pos/is4c-nf/lib/ReceiptLib.php - About 2 days to fix

    Function printReceipt has a Cognitive Complexity of 50 (exceeds 5 allowed). Consider refactoring.
    Open

    static public function printReceipt($arg1, $ref, $second=False, $email=False) 
    {
        if($second) $email = False; // store copy always prints
        if($arg1 != "full") $email = False;
        $reprint = $arg1 == 'reprint' ? true : false;
    Severity: Minor
    Found in pos/is4c-nf/lib/ReceiptLib.php - About 7 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

    ReceiptLib has 46 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class ReceiptLib 
    {
        static private $PRINT;
    
        static private $EMAIL = 'COREPOS\\pos\\lib\\PrintHandlers\EmailPrintHandler';
    Severity: Minor
    Found in pos/is4c-nf/lib/ReceiptLib.php - About 6 hrs to fix

      Method printReceipt has 105 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

      static public function printReceipt($arg1, $ref, $second=False, $email=False) 
      {
          if($second) $email = False; // store copy always prints
          if($arg1 != "full") $email = False;
          $reprint = $arg1 == 'reprint' ? true : false;
      Severity: Major
      Found in pos/is4c-nf/lib/ReceiptLib.php - About 4 hrs to fix

        Function receiptDetail has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
        Open

        static public function receiptDetail($reprint=false, $transNum='') 
        { 
            // put into its own function to make it easier to follow, and slightly 
            // modified for wider-spread use of joe's "new" receipt format --- apbw 7/3/2007
            if (CoreLocal::get("newReceipt") == 2) {
        Severity: Minor
        Found in pos/is4c-nf/lib/ReceiptLib.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

        Function memReceiptMessages has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
        Open

        static public function memReceiptMessages($cardNo)
        {
            $dbc = Database::pDataConnect();
            $memQ = 'SELECT msg_text,modifier_module
                  FROM custReceiptMessage
        Severity: Minor
        Found in pos/is4c-nf/lib/ReceiptLib.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 receiptDetail has 72 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

        static public function receiptDetail($reprint=false, $transNum='') 
        { 
            // put into its own function to make it easier to follow, and slightly 
            // modified for wider-spread use of joe's "new" receipt format --- apbw 7/3/2007
            if (CoreLocal::get("newReceipt") == 2) {
        Severity: Major
        Found in pos/is4c-nf/lib/ReceiptLib.php - About 2 hrs to fix

          Function messageModFooters has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
          Open

          static private function messageModFooters($receipt, $where, $ref, $reprint, $nth)
          {
              // check if message mods have data
              // and add them to the receipt
              $dbc = Database::tDataConnect();
          Severity: Minor
          Found in pos/is4c-nf/lib/ReceiptLib.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

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

          static public function printReceiptHeader($dateTimeStamp, $ref) 
          {
              self::initDriver();
              $receipt = self::$PRINT->TextStyle(True);
              $imgCache = CoreLocal::get('ImageCache');
          Severity: Minor
          Found in pos/is4c-nf/lib/ReceiptLib.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 setupReprint has 47 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

          static private function setupReprint($where)
          {
              // lookup trans information
              $dbc = Database::tDataConnect();
              $queryHeader = "
          Severity: Minor
          Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

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

            static public function printReceiptHeader($dateTimeStamp, $ref) 
            {
                self::initDriver();
                $receipt = self::$PRINT->TextStyle(True);
                $imgCache = CoreLocal::get('ImageCache');
            Severity: Minor
            Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

              Method memReceiptMessages has 40 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

              static public function memReceiptMessages($cardNo)
              {
                  $dbc = Database::pDataConnect();
                  $memQ = 'SELECT msg_text,modifier_module
                        FROM custReceiptMessage
              Severity: Minor
              Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

                Method receiptFromBuilders has 38 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                static public function receiptFromBuilders($transNum='')
                {
                    $empNo=0;$laneNo=0;$transNo=0;
                    list($empNo, $laneNo, $transNo) = self::parseRef($transNum);
                    self::initDriver();
                Severity: Minor
                Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

                  Method chargeBalance has 36 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  static public function chargeBalance($receipt, $program="charge", $transNum='')
                  {
                      \COREPOS\pos\lib\MemberLib::chargeOk();
                  
                      $labels = array();
                  Severity: Minor
                  Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

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

                    static public function printChargeFooterStore($dateTimeStamp, $ref, $program="charge") 
                    {
                        $chgName = \COREPOS\pos\lib\MemberLib::getChgName();            // added by apbw 2/14/05 SCR
                        
                        $date = self::build_time($dateTimeStamp);
                    Severity: Minor
                    Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

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

                      static private function messageModFooters($receipt, $where, $ref, $reprint, $nth)
                      {
                          // check if message mods have data
                          // and add them to the receipt
                          $dbc = Database::tDataConnect();
                      Severity: Minor
                      Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

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

                        static public function printCabCoupon($dateTimeStamp, $ref)
                        {
                            $receipt = "\n";
                        
                            $receipt .= self::biggerFont(self::centerBig("WHOLE FOODS COMMUNITY CO-OP"))."\n\n";
                        Severity: Minor
                        Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

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

                          static public function twoColumns($col1, $col2) {
                              // init
                              $max = 56;
                              $text = "";
                              // find longest string in each column, ignoring font change strings
                          Severity: Minor
                          Found in pos/is4c-nf/lib/ReceiptLib.php - About 1 hr to fix

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

                            static public function receiptFromBuilders($transNum='')
                            {
                                $empNo=0;$laneNo=0;$transNo=0;
                                list($empNo, $laneNo, $transNo) = self::parseRef($transNum);
                                self::initDriver();
                            Severity: Minor
                            Found in pos/is4c-nf/lib/ReceiptLib.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 twoColumns has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                            static public function twoColumns($col1, $col2) {
                                // init
                                $max = 56;
                                $text = "";
                                // find longest string in each column, ignoring font change strings
                            Severity: Minor
                            Found in pos/is4c-nf/lib/ReceiptLib.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 getTypeMap has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                            static private function getTypeMap()
                            {
                                $typeMap = array();
                                foreach(self::messageMods(true) as $class){
                                    if (in_array($class, self::$msgMods)) {
                            Severity: Minor
                            Found in pos/is4c-nf/lib/ReceiptLib.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 chargeBalance has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                            Open

                            static public function chargeBalance($receipt, $program="charge", $transNum='')
                            {
                                \COREPOS\pos\lib\MemberLib::chargeOk();
                            
                                $labels = array();
                            Severity: Minor
                            Found in pos/is4c-nf/lib/ReceiptLib.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 messageModFooters has 5 arguments (exceeds 4 allowed). Consider refactoring.
                            Open

                            static private function messageModFooters($receipt, $where, $ref, $reprint, $nth)
                            Severity: Minor
                            Found in pos/is4c-nf/lib/ReceiptLib.php - About 35 mins to fix

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

                              static private function messageMods($nth)
                              {
                                  $messageMods = CoreLocal::get('ReceiptMessageMods');
                                  if (!is_array($messageMods)) $messageMods = array();
                                  if ($nth) {
                              Severity: Minor
                              Found in pos/is4c-nf/lib/ReceiptLib.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 false;
                              Severity: Major
                              Found in pos/is4c-nf/lib/ReceiptLib.php - About 30 mins to fix

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

                                static private function nthReceipt()
                                {
                                    if (CoreLocal::get('lotterySpin') !== false && CoreLocal::get('lotterySpin') !== '') {
                                        return CoreLocal::get('lotterySpin') < CoreLocal::get('nthReceipt');
                                    } elseif (CoreLocal::get('nthReceipt') > 0 && CoreLocal::get('nthReceipt') < 1) {
                                Severity: Minor
                                Found in pos/is4c-nf/lib/ReceiptLib.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 simpleReceipt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                static private function simpleReceipt($receipt, $arg1, $where)
                                {
                                    /***** jqh 09/29/05 if receipt isn't full, then display receipt in old style *****/
                                    $query="select linetoprint from rp_receipt WHERE " . $where . ' ORDER BY trans_id';
                                    if ($arg1 == 'partial') {
                                Severity: Minor
                                Found in pos/is4c-nf/lib/ReceiptLib.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 cutReceipt has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                Open

                                static public function cutReceipt($receipt, $second)
                                {
                                    if (is_array($receipt)){
                                        if ($second){
                                            // second always prints
                                Severity: Minor
                                Found in pos/is4c-nf/lib/ReceiptLib.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 public function code39($barcode, $forcePaper=false)
                                {
                                    if (!is_object(self::$PRINT)) {
                                        self::$PRINT= PrintHandler::factory(CoreLocal::get('ReceiptDriver'));
                                    }
                                Severity: Major
                                Found in pos/is4c-nf/lib/ReceiptLib.php and 1 other location - About 3 hrs to fix
                                pos/is4c-nf/lib/ReceiptLib.php on lines 1158..1169

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

                                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

                                static public function code128($barcode, $forcePaper=false)
                                {
                                    if (!is_object(self::$PRINT)) {
                                        self::$PRINT= PrintHandler::factory(CoreLocal::get('ReceiptDriver'));
                                    }
                                Severity: Major
                                Found in pos/is4c-nf/lib/ReceiptLib.php and 1 other location - About 3 hrs to fix
                                pos/is4c-nf/lib/ReceiptLib.php on lines 1145..1156

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

                                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