MPOS/php-mpos

View on GitHub
include/classes/transaction.class.php

Summary

Maintainability
D
3 days
Test Coverage

File transaction.class.php has 383 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
$defflip = (!cfip()) ? exit(header('HTTP/1.1 401 Unauthorized')) : 1;

class Transaction extends Base {
  protected $table = 'transactions';
Severity: Minor
Found in include/classes/transaction.class.php - About 5 hrs to fix

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

      public function getTransactions($start=0, $filter=NULL, $limit=30, $account_id=NULL) {
        $this->debug->append("STA " . __METHOD__, 4);
        $sql = "
          SELECT
            t.id AS id,
    Severity: Minor
    Found in include/classes/transaction.class.php - About 3 hrs to fix

    Cognitive Complexity

    Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

    A method's cognitive complexity is based on a few simple rules:

    • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
    • Code is considered more complex for each "break in the linear flow of the code"
    • Code is considered more complex when "flow breaking structures are nested"

    Further reading

    Method getTransactions has 67 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public function getTransactions($start=0, $filter=NULL, $limit=30, $account_id=NULL) {
        $this->debug->append("STA " . __METHOD__, 4);
        $sql = "
          SELECT
            t.id AS id,
    Severity: Major
    Found in include/classes/transaction.class.php - About 2 hrs to fix

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

        public function getTransactionTypebyTime($account_id=NULL) {
          $this->debug->append("STA " . __METHOD__, 4);
          if ($data = $this->memcache->get(__FUNCTION__)) return $data;
          $stmt = $this->mysqli->prepare("
            SELECT
      Severity: Minor
      Found in include/classes/transaction.class.php - About 1 hr to fix

        Function getTransactionSummary has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
        Open

          public function getTransactionSummary($account_id=NULL) {
            if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
            $sql = "
              SELECT
                SUM(t.amount) AS total, t.type AS type
        Severity: Minor
        Found in include/classes/transaction.class.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 createDebitRecord has 33 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          private function createDebitRecord($account_id, $coin_address, $amount, $type) {
            // Calculate and deduct txfee from amount
            $type == 'Debit_MP' ? $txfee = $this->config['txfee_manual'] : $txfee = $this->config['txfee_auto'];
            $amount = $amount - $txfee;
            // Add Debit record
        Severity: Minor
        Found in include/classes/transaction.class.php - About 1 hr to fix

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

            public function getTransactionSummary($account_id=NULL) {
              if ($data = $this->memcache->get(__FUNCTION__ . $account_id)) return $data;
              $sql = "
                SELECT
                  SUM(t.amount) AS total, t.type AS type
          Severity: Minor
          Found in include/classes/transaction.class.php - About 1 hr to fix

            Method getMPQueue has 30 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              public function getMPQueue($limit=250) {
                $stmt = $this->mysqli->prepare("
                  SELECT
                  a.id,
                  a.username,
            Severity: Minor
            Found in include/classes/transaction.class.php - About 1 hr to fix

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

                public function getAPQueue($limit=250) {
                  $this->debug->append("STA " . __METHOD__, 4);
                  $stmt = $this->mysqli->prepare("
                    SELECT
                      a.id,
              Severity: Minor
              Found in include/classes/transaction.class.php - About 1 hr to fix

                Consider simplifying this complex logical expression.
                Open

                              if (empty($filter['type']) || ($filter['type'] != 'Debit_AP' && $filter['type'] != 'Debit_MP' && $filter['type'] != 'TXFee' && $filter['type'] != 'Credit_PPS' && $filter['type'] != 'Fee_PPS' && $filter['type'] != 'Donation_PPS')) {
                                $aFilter[] = "( b.confirmations >= " . $this->config['confirmations'] . " OR ISNULL(b.confirmations) )";
                              }
                Severity: Major
                Found in include/classes/transaction.class.php - About 1 hr to fix

                  Avoid deeply nested control flow statements.
                  Open

                                if (empty($filter['type']) || ($filter['type'] != 'Debit_AP' && $filter['type'] != 'Debit_MP' && $filter['type'] != 'TXFee' && $filter['type'] != 'Credit_PPS' && $filter['type'] != 'Fee_PPS' && $filter['type'] != 'Donation_PPS')) {
                                  $aFilter[] = "( b.confirmations >= " . $this->config['confirmations'] . " OR ISNULL(b.confirmations) )";
                                }
                  Severity: Major
                  Found in include/classes/transaction.class.php - About 45 mins to fix

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

                      private function createDebitRecord($account_id, $coin_address, $amount, $type) {
                        // Calculate and deduct txfee from amount
                        $type == 'Debit_MP' ? $txfee = $this->config['txfee_manual'] : $txfee = $this->config['txfee_auto'];
                        $amount = $amount - $txfee;
                        // Add Debit record
                    Severity: Minor
                    Found in include/classes/transaction.class.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 addTransaction has 6 arguments (exceeds 4 allowed). Consider refactoring.
                    Open

                      public function addTransaction($account_id, $amount, $type='Credit', $block_id=NULL, $coin_address=NULL, $txid=NULL) {
                    Severity: Minor
                    Found in include/classes/transaction.class.php - About 45 mins to fix

                      Avoid too many return statements within this method.
                      Open

                            return false;
                      Severity: Major
                      Found in include/classes/transaction.class.php - About 30 mins to fix

                        Avoid too many return statements within this method.
                        Open

                            return $this->sqlError();
                        Severity: Major
                        Found in include/classes/transaction.class.php - About 30 mins to fix

                          Avoid too many return statements within this method.
                          Open

                              return $transaction_id;
                          Severity: Major
                          Found in include/classes/transaction.class.php - About 30 mins to fix

                            There are no issues that match your filters.

                            Category
                            Status