dofinity/pelecard

View on GitHub
src/Pelecard/PelecardPaymentStatus.php

Summary

Maintainability
D
2 days
Test Coverage

File PelecardPaymentStatus.php has 783 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * @file PelecardPaymentStatus class - allows to get payment status message based on status code
 */
namespace Pelecard;
Severity: Major
Found in src/Pelecard/PelecardPaymentStatus.php - About 1 day to fix

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

      public function getMessage() {
        if (!is_string($this->code) || !array_key_exists($this->code, PelecardPaymentStatus::MESSAGES)) {
          // invalid status code provided, should be string value
          return null;
        }
    Severity: Minor
    Found in src/Pelecard/PelecardPaymentStatus.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 getMessage has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      public function getMessage() {
        if (!is_string($this->code) || !array_key_exists($this->code, PelecardPaymentStatus::MESSAGES)) {
          // invalid status code provided, should be string value
          return null;
        }
    Severity: Minor
    Found in src/Pelecard/PelecardPaymentStatus.php - About 1 hr to fix

      The method getMessage() has a Cyclomatic Complexity of 10. The configured cyclomatic complexity threshold is 10.
      Open

        public function getMessage() {
          if (!is_string($this->code) || !array_key_exists($this->code, PelecardPaymentStatus::MESSAGES)) {
            // invalid status code provided, should be string value
            return null;
          }

      CyclomaticComplexity

      Since: 0.1

      Complexity is determined by the number of decision points in a method plus one for the method entry. The decision points are 'if', 'while', 'for', and 'case labels'. Generally, 1-4 is low complexity, 5-7 indicates moderate complexity, 8-10 is high complexity, and 11+ is very high complexity.

      Example

      // Cyclomatic Complexity = 11
      class Foo {
      1   public function example() {
      2       if ($a == $b) {
      3           if ($a1 == $b1) {
                      fiddle();
      4           } elseif ($a2 == $b2) {
                      fiddle();
                  } else {
                      fiddle();
                  }
      5       } elseif ($c == $d) {
      6           while ($c == $d) {
                      fiddle();
                  }
      7        } elseif ($e == $f) {
      8           for ($n = 0; $n < $h; $n++) {
                      fiddle();
                  }
              } else {
                  switch ($z) {
      9               case 1:
                          fiddle();
                          break;
      10              case 2:
                          fiddle();
                          break;
      11              case 3:
                          fiddle();
                          break;
                      default:
                          fiddle();
                          break;
                  }
              }
          }
      }

      Source https://phpmd.org/rules/codesize.html#cyclomaticcomplexity

      Opening brace of a class must be on the line after the definition
      Open

      class PelecardPaymentStatus {

      Terminating statement must be indented to the same level as the CASE body
      Open

              break;

      Terminating statement must be indented to the same level as the CASE body
      Open

              break;

      The closing brace for the class must go on the next line after the body
      Open

      }

      Line exceeds 120 characters; contains 149 characters
      Open

            'HE' => 'הפרש בימים בקליטת חסומים גדול מדי - בצע שידור או בקשה לאישור עבור כל עסקה.',

      Line exceeds 120 characters; contains 143 characters
      Open

            'EN' => 'The difference in generations in the blocked cards input is too large, transmit or request authorization for each transaction.',

      Line exceeds 120 characters; contains 139 characters
      Open

            'HE' => 'לא הוכנס פס מגנטי כולו. הגדר עסקה כעסקה טלפונית או כעסקת חתימה בלבד.',

      Line exceeds 120 characters; contains 121 characters
      Open

            'HE' => 'למסוף אין אישור לעסקת כוכבים/נקודות/מיילים לסוג אשראי זה.',

      Line exceeds 120 characters; contains 158 characters
      Open

            'HE' => 'כרטיס לא רשאי לבצע עסקת אשראי גמיש (עדיף +30/) עפ"י הגדרת המערכת. (VECTOR21 של דיינרס).',

      Line exceeds 120 characters; contains 140 characters
      Open

            'EN' => 'The card belongs to a group that is not permitted to execute transactions according to system definitions (Visa VECTOR 20).',

      Line exceeds 120 characters; contains 125 characters
      Open

            'EN' => 'The transaction`s amount exceeds the ceiling when the input file contains J1, J2 or J3 (contact prohibited).',

      Line exceeds 120 characters; contains 127 characters
      Open

            'EN' => 'Defective card according to system definitions (Isracard VECTOR1), error in the number of figures on the card.',

      Line exceeds 120 characters; contains 144 characters
      Open

            'EN' => 'The card is not permitted to execute flexible credit transactions (Adif/30+) according to system definitions (Diners VECTOR21).',

      Line exceeds 120 characters; contains 121 characters
      Open

            'HE' => 'לא ניתן לבטל עסקה קודמת (עסקת זכות או מספר כרטיס אינו זהה).',

      Line exceeds 120 characters; contains 122 characters
      Open

            'HE' => 'קיים תשלום ראשון ו/או תשלום קבוע לסוג אשראי שונה מתשלומים.',

      Line exceeds 120 characters; contains 125 characters
      Open

            'EN' => 'The card is not permitted to execute dollar transactions according to system definitions (Isracard VECTOR1).',

      Line exceeds 120 characters; contains 132 characters
      Open

            'HE' => 'תוכנית הופסקה עפ"י הוראת המפעיל (ESC) או COM PORT לא ניתן לפתיחה (Windows).',

      Line exceeds 120 characters; contains 128 characters
      Open

            'HE' => 'מספר מסוף מרכזי לא הוכנס לשאילתה במסוף המוגדר לעבודה כרב ספק.',

      Line exceeds 120 characters; contains 126 characters
      Open

            'HE' => 'מספר תשלומים גדול מידי על פי רשימת כרטיסים תקפים של ישראכרט.',

      Line exceeds 120 characters; contains 146 characters
      Open

            'HE' => 'כרטיס לא רשאי לבצע עסקאות חיוב מיידי עפ"י הגדרת המערכת. (VECTOR21 של דיינרס).',

      Line exceeds 120 characters; contains 148 characters
      Open

            'HE' => 'כרטיס לא רשאי לבצע עסקאות בתשלומים על פי רשימת כרטיסים תקפים של ישראכרט.',

      Line exceeds 120 characters; contains 135 characters
      Open

            'HE' => 'קידומת הכרטיס (7 ספרות) לא תקפה עפ”י הגדרת המערכת (VECTOR21 של דיינרס).',

      Line exceeds 120 characters; contains 143 characters
      Open

            'HE' => 'כרטיס לא רשאי לבצע עסקאות דולריות עפ”י הגדרת המערכת (VECTOR1 של ישראכרט).',

      Line exceeds 120 characters; contains 127 characters
      Open

            'HE' => 'כרטיס לא רשאי לבצע עסקאות בתשלומים עפ"י וקטור 31 של לאומיקארד.',

      Line exceeds 120 characters; contains 140 characters
      Open

            'HE' => 'תקלת תקשורת, יש לנסות שוב או לפנות למנהל המערכת ולמסור את קוד התשובה',

      Line exceeds 120 characters; contains 138 characters
      Open

            'HE' => 'מסוף חייב לבקש אישור כאשר רשומת הקלט מכילה J3 או J2 או J1 (אסור להתקשר).',

      Line exceeds 120 characters; contains 131 characters
      Open

            'HE' => 'כרטיס אינו רשאי לבצע עסקאות טלפוניות עפ"י וקטור 31 של לאומיקארד.',

      Line exceeds 120 characters; contains 125 characters
      Open

            'HE' => 'מסוף שאינו מעודכן כרב ספק/רב מוטב והוקלד מספר ספק/מספר מוטב.',

      Line exceeds 120 characters; contains 129 characters
      Open

            'HE' => 'מסוף לא מוגדר כתחנת דלק. (הועבר כרטיס דלק או קוד עסקה לא מתאים).',

      Line exceeds 120 characters; contains 152 characters
      Open

            'HE' => 'כרטיס לא תקין עפ”י הגדרת המערכת (VECTOR1 של ישראכרט)- מספר הספרות בכרטיס- שגוי.',

      Line exceeds 120 characters; contains 138 characters
      Open

            'HE' => 'כרטיס אמריקן אקספרס אשר הונפק בחוייל לא רשאי לבצע עסקאות בתשלומים.',

      Line exceeds 120 characters; contains 152 characters
      Open

            'HE' => 'קובץ חסומים (NEG) לא קיים או לא מעודכן - בצע שידור או בקשה לאישור עבור כל עסקה.',

      Line exceeds 120 characters; contains 122 characters
      Open

            'HE' => 'כרטיסי ויזה ודיינרס לא רשאים לבצע עסקאות מועדון בתשלומים.',

      Line exceeds 120 characters; contains 125 characters
      Open

            'EN' => 'The card is not permitted to carry out installment transactions according to Isracard`s list of valid cards.',

      Line exceeds 120 characters; contains 122 characters
      Open

            'EN' => 'The card is not permitted for telephone and signature-only transactions according to Alpha vector no. 31.',

      Line exceeds 120 characters; contains 132 characters
      Open

            'EN' => 'The supplier/beneficiary number was entered, however the terminal was not updated as the main supplier/beneficiary.',

      Line exceeds 120 characters; contains 127 characters
      Open

            'HE' => 'בתחנות דלק לא ניתן לבצע "שרות עצמי" אלא "שרות עצמי בתחנות דלק".',

      Line exceeds 120 characters; contains 156 characters
      Open

            'EN' => 'Installment error, the amount of transactions needs to be equal to: first installment plus fixed installments times number of installments.',

      Line exceeds 120 characters; contains 137 characters
      Open

            'EN' => 'Blocked cards file (NEG) does not exist or has not been updated, transmit or request authorization for each transaction.',

      Line exceeds 120 characters; contains 136 characters
      Open

            'EN' => 'The difference in days in the blocked cards input is too large, transmit or request authorization for each transaction.',

      Line exceeds 120 characters; contains 129 characters
      Open

            'HE' => 'כרטיס חסום בספק כאשר רשומת הקלט מכילה J3 או J2 או J1 (אסור להתקשר).',

      Line exceeds 120 characters; contains 151 characters
      Open

            'HE' => 'הפרש דורות בקליטת חסומים גדול מידי - בצע שידור או בקשה לאישור עבור כל עסקה.',

      Line exceeds 120 characters; contains 121 characters
      Open

            'EN' => 'The terminal must request authorization where the input file contains J1, J2 or J3 (contact prohibited).',

      Line exceeds 120 characters; contains 133 characters
      Open

            'EN' => 'The card is not permitted to execute immediate debit transactions according to system definitions (Diners VECTOR21).',

      Line exceeds 120 characters; contains 131 characters
      Open

            'EN' => 'When the magnetic strip is not completely entered, define the transaction as a telephone number or signature only.',

      Line exceeds 120 characters; contains 122 characters
      Open

            'HE' => 'מסוף מבצע שידור ו/או מעדכן נתונים. אנא נסה שנית מאוחר יותר.',

      Line exceeds 120 characters; contains 172 characters
      Open

            'HE' => 'שגיאה בתשלומים - סכום עסקה צריך להיות שווה תשלום ראשון +(תשלום קבוע כפול מספר תשלומים).',

      Line exceeds 120 characters; contains 141 characters
      Open

            'HE' => 'חייב להקליד מספר סודי, כאשר רשומת הקלט מכילה J3 או J2 או J1 (אסור להתקשר).',

      Line exceeds 120 characters; contains 175 characters
      Open

            'HE' => 'הכרטיס שייך לקבוצת כרטיסים אשר אינה רשאית לבצע עסקאות עפ”י הגדרת המערכת (VECTOR20 של ויזה).',

      Line exceeds 120 characters; contains 122 characters
      Open

            'HE' => 'סידרת כרטיסים לא תקפה עפ”י הגדרת המערכת. (VECTOR5 של ישראכרט).',

      Line exceeds 120 characters; contains 137 characters
      Open

            'HE' => 'קידומת הכרטיס (2 ספרות) לא תקפה עפ”י הגדרת המערכת. (VECTOR7 של ישראכרט).',

      Line exceeds 120 characters; contains 151 characters
      Open

            'HE' => 'כרטיס לא רשאי לבצע עסקאות טלפוניות וחתימה בלבד עפ"י ווקטור 31 של לאומיקארד.',

      Line indented incorrectly; expected 12 spaces, found 6
      Open

            case 'HE':

      Line indented incorrectly; expected at least 16 spaces, found 8
      Open

              $outputMessage = null;

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        }

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        }

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        protected $locale = 'HE';

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          $this->locale = $locale;

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          return $this->code;

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        protected $code;

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          }

      Expected 1 newline at end of file; 0 found
      Open

      }

      Opening brace should be on a new line
      Open

        public function __construct($statusCode, $locale = 'HE') {

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        }

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

            $outputLocale = strtoupper($this->locale);

      Line indented incorrectly; expected 12 spaces, found 6
      Open

            case 'EN':

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        public function getCode() {

      Line indented incorrectly; expected at least 12 spaces, found 6
      Open

            return null;

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        public function __toString() {

      Opening brace should be on a new line
      Open

        public function __toString() {

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        }

      Line indented incorrectly; expected 16 spaces, found 8
      Open

              }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          $messageHe = PelecardPaymentStatus::MESSAGES[$this->code]['HE'];

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          return (is_string($this->getMessage())) ? $this->getMessage() : '';

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

        const MESSAGES = [

      Line indented incorrectly; expected 16 spaces, found 8
      Open

              }

      Opening brace should be on a new line
      Open

        public function getCode() {

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        public function getMessage() {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          if (is_string($this->locale) && in_array(strtoupper($this->locale), ['HE', 'EN'], true)) {

      Line indented incorrectly; expected at least 4 spaces, found 2
      Open

        ];

      Line indented incorrectly; expected 4 spaces, found 2
      Open

        public function __construct($statusCode, $locale = 'HE') {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          if (!is_string($this->code) || !array_key_exists($this->code, PelecardPaymentStatus::MESSAGES)) {

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

                $outputMessage = $messageEn;

      Line indented incorrectly; expected 12 spaces, found 6
      Open

            default:

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          $this->code = $statusCode;

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

                $outputMessage = $messageEn;

      Opening brace should be on a new line
      Open

        public function getMessage() {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          $outputLocale = 'HE';

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          switch ($outputLocale) {

      Line indented incorrectly; expected at least 20 spaces, found 10
      Open

                $outputMessage = $messageHe;

      Line indented incorrectly; expected 16 spaces, found 8
      Open

              } elseif (!empty($messageEn)) {

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          $outputMessage = null;

      Line indented incorrectly; expected 16 spaces, found 8
      Open

              if (!empty($messageEn)) {

      Line indented incorrectly; expected 16 spaces, found 8
      Open

              if (!empty($messageHe)) {

      Line indented incorrectly; expected 8 spaces, found 4
      Open

          }

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          $messageEn = PelecardPaymentStatus::MESSAGES[$this->code]['EN'];

      Line indented incorrectly; expected at least 8 spaces, found 4
      Open

          return $outputMessage;

      There are no issues that match your filters.

      Category
      Status