AJenbo/agcms

View on GitHub
application/inc/Models/Invoice.php

Summary

Maintainability
F
5 days
Test Coverage
B
88%

Invoice has 92 functions (exceeds 20 allowed). Consider refactoring.
Open

class Invoice extends AbstractEntity
{
    /** Table name in database. */
    public const TABLE_NAME = 'fakturas';

Severity: Major
Found in application/inc/Models/Invoice.php - About 1 day to fix

    File Invoice.php has 709 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    
    namespace App\Models;
    
    use App\DTO\InvoiceItem;
    Severity: Major
    Found in application/inc/Models/Invoice.php - About 1 day to fix

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

          public function getInvalid(): array
          {
              $invalid = [];
      
              if (!$this->hasValidEmail()) {
      Severity: Minor
      Found in application/inc/Models/Invoice.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

      The class Invoice has an overall complexity of 138 which is very high. The configured complexity threshold is 50.
      Open

      class Invoice extends AbstractEntity
      {
          /** Table name in database. */
          public const TABLE_NAME = 'fakturas';
      
      
      Severity: Minor
      Found in application/inc/Models/Invoice.php by phpmd

      Method getDbArray has 59 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function getDbArray(): array
          {
              $itemQuantities = [];
              $itemTitle = [];
              $itemValue = [];
      Severity: Major
      Found in application/inc/Models/Invoice.php - About 2 hrs to fix

        Function setItemData has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
        Open

            public function setItemData(string $itemData): self
            {
                $this->items = [];
        
                $items = json_decode($itemData, true);
        Severity: Minor
        Found in application/inc/Models/Invoice.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 mapFromDB has 56 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function mapFromDB(array $data): array
            {
                $itemQuantities = explode('<', $data['quantities']);
                $itemQuantities = array_map('intval', $itemQuantities);
                $itemValue = explode('<', $data['values']);
        Severity: Major
        Found in application/inc/Models/Invoice.php - About 2 hrs to fix

          Method getInvalid has 50 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function getInvalid(): array
              {
                  $invalid = [];
          
                  if (!$this->hasValidEmail()) {
          Severity: Minor
          Found in application/inc/Models/Invoice.php - About 2 hrs to fix

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

                public function __construct(array $data = [])
                {
                    $this->setItemData(strval($data['item_data'] ?? '[]'))
                        ->setHasShippingAddress(boolval($data['has_shipping_address'] ?? false))
                        ->setTimeStamp(intval($data['timestamp'] ?? time()))
            Severity: Minor
            Found in application/inc/Models/Invoice.php - About 1 hr to fix

              The class Invoice has 38 fields. Consider redesigning Invoice to keep the number of fields under 15.
              Open

              class Invoice extends AbstractEntity
              {
                  /** Table name in database. */
                  public const TABLE_NAME = 'fakturas';
              
              
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              TooManyFields

              Since: 0.1

              Classes that have too many fields could be redesigned to have fewer fields, possibly through some nested object grouping of some of the information. For example, a class with city/state/zip fields could instead have one Address field.

              Example

              class Person {
                 protected $one;
                 private $two;
                 private $three;
                 [... many more fields ...]
              }

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

              The class Invoice has 92 public methods and attributes. Consider reducing the number of public items to less than 45.
              Open

              class Invoice extends AbstractEntity
              {
                  /** Table name in database. */
                  public const TABLE_NAME = 'fakturas';
              
              
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              ExcessivePublicCount

              Since: 0.1

              A large number of public methods and attributes declared in a class can indicate the class may need to be broken up as increased effort will be required to thoroughly test it.

              Example

              public class Foo {
                  public $value;
                  public $something;
                  public $var;
                  // [... more more public attributes ...]
              
                  public function doWork() {}
                  public function doMoreWork() {}
                  public function doWorkAgain() {}
                  // [... more more public methods ...]
              }

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

              The method getInvalid() has an NPath complexity of 51520. The configured NPath complexity threshold is 200.
              Open

                  public function getInvalid(): array
                  {
                      $invalid = [];
              
                      if (!$this->hasValidEmail()) {
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              NPathComplexity

              Since: 0.1

              The NPath complexity of a method is the number of acyclic execution paths through that method. A threshold of 200 is generally considered the point where measures should be taken to reduce complexity.

              Example

              class Foo {
                  function bar() {
                      // lots of complicated code
                  }
              }

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

              The class Invoice has 1265 lines of code. Current threshold is 1000. Avoid really long classes.
              Open

              class Invoice extends AbstractEntity
              {
                  /** Table name in database. */
                  public const TABLE_NAME = 'fakturas';
              
              
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

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

                  public function setItemData(string $itemData): self
                  {
                      $this->items = [];
              
                      $items = json_decode($itemData, true);
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              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

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

                  public function getInvalid(): array
                  {
                      $invalid = [];
              
                      if (!$this->hasValidEmail()) {
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              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

              The method getItems has a boolean flag argument $normalizeVat, which is a certain sign of a Single Responsibility Principle violation.
              Open

                  public function getItems(bool $normalizeVat = true): array
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              BooleanArgumentFlag

              Since: 1.4.0

              A boolean flag argument is a reliable indicator for a violation of the Single Responsibility Principle (SRP). You can fix this problem by extracting the logic in the boolean flag into its own class or method.

              Example

              class Foo {
                  public function bar($flag = true) {
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#booleanargumentflag

              Avoid using static access to class '\App\Services\ConfigService' in method 'getAdminLink'.
              Open

                      return ConfigService::getString('base_url') . '/admin/invoices/' . $this->id . '/';
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class '\App\Services\ConfigService' in method 'getCheckId'.
              Open

                      return mb_substr(md5($this->id . ConfigService::getString('pbssalt')), 3, 5);
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class '\App\Enums\InvoiceStatus' in method '__construct'.
              Open

                          ->setStatus(InvoiceStatus::from(strval($data['status'] ?? 'new')))
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid using static access to class '\App\Services\ConfigService' in method 'getLink'.
              Open

                      return ConfigService::getString('base_url') . '/betaling/' . $this->getId() . '/' . $this->getCheckId() . '/';
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              StaticAccess

              Since: 1.4.0

              Static access causes unexchangeable dependencies to other classes and leads to hard to test code. Avoid using static access at all costs and instead inject dependencies through the constructor. The only case when static access is acceptable is when used for factory methods.

              Example

              class Foo
              {
                  public function bar()
                  {
                      Bar::baz();
                  }
              }

              Source https://phpmd.org/rules/cleancode.html#staticaccess

              Avoid variables with short names like $db. Configured minimum length is 3.
              Open

                      $db = app(DbService::class);
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Avoid variables with short names like $db. Configured minimum length is 3.
              Open

                      $db = app(DbService::class);
              Severity: Minor
              Found in application/inc/Models/Invoice.php by phpmd

              ShortVariable

              Since: 0.2

              Detects when a field, local, or parameter has a very short name.

              Example

              class Something {
                  private $q = 15; // VIOLATION - Field
                  public static function main( array $as ) { // VIOLATION - Formal
                      $r = 20 + $this->q; // VIOLATION - Local
                      for (int $i = 0; $i < 10; $i++) { // Not a Violation (inside FOR)
                          $r += $this->q;
                      }
                  }
              }

              Source https://phpmd.org/rules/naming.html#shortvariable

              Line exceeds 120 characters; contains 139 characters
              Open

                      return in_array($this->status, [InvoiceStatus::Canceled, InvoiceStatus::Accepted, InvoiceStatus::Giro, InvoiceStatus::Cash], true);

              There are no issues that match your filters.

              Category
              Status