gdbots/pbj-php

View on GitHub
src/Field.php

Summary

Maintainability
D
2 days
Test Coverage

File Field.php has 364 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
declare(strict_types=1);

namespace Gdbots\Pbj;

Severity: Minor
Found in src/Field.php - About 4 hrs to fix

    Field has 34 functions (exceeds 20 allowed). Consider refactoring.
    Open

    final class Field implements \JsonSerializable
    {
        /**
         * Regular expression pattern for matching a valid field name.  The pattern allows
         * for camelCase fields name but snake_case is recommend.
    Severity: Minor
    Found in src/Field.php - About 4 hrs to fix

      Method __construct has 18 arguments (exceeds 4 allowed). Consider refactoring.
      Open

              string    $name,
              Type      $type,
              FieldRule $rule,
              bool      $required = false,
              ?int      $minLength = null,
      Severity: Major
      Found in src/Field.php - About 2 hrs to fix

        Function applyDefault has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
        Open

            private function applyDefault($default = null): void
            {
                $this->default = $default;
        
                if ($this->type->isScalar()) {
        Severity: Minor
        Found in src/Field.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 applyDefault has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function applyDefault($default = null): void
            {
                $this->default = $default;
        
                if ($this->type->isScalar()) {
        Severity: Minor
        Found in src/Field.php - About 1 hr to fix

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

              public function getDefault(?Message $message = null): mixed
              {
                  if (null === $this->default) {
                      if ($this->useTypeDefault) {
                          return $this->isASingleValue() ? $this->type->getDefault() : [];
          Severity: Minor
          Found in src/Field.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 applyNumericOptions has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              private function applyNumericOptions(?int $min = null, ?int $max = null, int $precision = 10, int $scale = 2): void
              {
                  if (null !== $max) {
                      $this->max = $max;
                  }
          Severity: Minor
          Found in src/Field.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 true;
          Severity: Major
          Found in src/Field.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                    return $this->default;
            Severity: Major
            Found in src/Field.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                          return $default;
              Severity: Major
              Found in src/Field.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                            return false;
                Severity: Major
                Found in src/Field.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return false;
                  Severity: Major
                  Found in src/Field.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                            return true;
                    Severity: Major
                    Found in src/Field.php - About 30 mins to fix

                      There are no issues that match your filters.

                      Category
                      Status