efureev/php-support

View on GitHub
src/Helpers/Arr.php

Summary

Maintainability
F
3 days
Test Coverage

Function fromPostgresArrayWithBraces has a Cognitive Complexity of 52 (exceeds 5 allowed). Consider refactoring.
Open

    public static function fromPostgresArrayWithBraces(
        ?string $s,
        int $start = 0,
        ?int &$end = null,
        array $braces = [
Severity: Minor
Found in src/Helpers/Arr.php - About 1 day 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

File Arr.php has 415 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

declare(strict_types=1);

namespace Php\Support\Helpers;
Severity: Minor
Found in src/Helpers/Arr.php - About 5 hrs to fix

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

        public static function dataToArray(mixed $items): mixed
        {
            if (is_object($items)) {
                if ($items instanceof JsonSerializable) {
                    return static::dataToArray($items->jsonSerialize());
    Severity: Minor
    Found in src/Helpers/Arr.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

    Arr has 24 functions (exceeds 20 allowed). Consider refactoring.
    Open

    class Arr
    {
        /**
         * Collapse an array of arrays into a single array.
         *
    Severity: Minor
    Found in src/Helpers/Arr.php - About 2 hrs to fix

      Method fromPostgresArrayWithBraces has 56 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function fromPostgresArrayWithBraces(
              ?string $s,
              int $start = 0,
              ?int &$end = null,
              array $braces = [
      Severity: Major
      Found in src/Helpers/Arr.php - About 2 hrs to fix

        Function remove has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function remove(array|ArrayObject &$array, array|string $keys): void
            {
                $original = &$array;
                $keys     = (array)$keys;
        
        
        Severity: Minor
        Found in src/Helpers/Arr.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

        Function merge has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function merge(array $res, array $b, bool $replaceArray = true): array
            {
                foreach ($b as $key => $val) {
                    if (is_int($key)) {
                        if (isset($res[$key])) {
        Severity: Minor
        Found in src/Helpers/Arr.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

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

            public static function has(ArrayAccess|array $array, string|array $keys, string $separator = '.'): bool
            {
                $keys = (array)$keys;
        
                if (!$array || $keys === []) {
        Severity: Minor
        Found in src/Helpers/Arr.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 dataToArray has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function dataToArray(mixed $items): mixed
            {
                if (is_object($items)) {
                    if ($items instanceof JsonSerializable) {
                        return static::dataToArray($items->jsonSerialize());
        Severity: Minor
        Found in src/Helpers/Arr.php - About 1 hr to fix

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

              public static function get(mixed $array, string|int|null $key, mixed $default = null, string $separator = '.'): mixed
              {
                  if (!static::accessible($array)) {
                      return value($default);
                  }
          Severity: Minor
          Found in src/Helpers/Arr.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

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

              public static function random(array $array, ?int $number = null, bool $preserveKeys = false): mixed
              {
                  $requested = $number ?? 1;
          
                  $count = count($array);
          Severity: Minor
          Found in src/Helpers/Arr.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

          Avoid too many return statements within this method.
          Open

                  return $array;
          Severity: Major
          Found in src/Helpers/Arr.php - About 30 mins to fix

            Avoid too many return statements within this method.
            Open

                        return (array)$items->jsonSerialize();
            Severity: Major
            Found in src/Helpers/Arr.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return value($default);
              Severity: Major
              Found in src/Helpers/Arr.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return (array)$items;
                Severity: Major
                Found in src/Helpers/Arr.php - About 30 mins to fix

                  There are no issues that match your filters.

                  Category
                  Status