hnhdigital-os/laravel-dynamic-filter

View on GitHub
src/Traits/ModelTrait.php

Summary

Maintainability
F
1 wk
Test Coverage

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

    private static function processAttributeFilter($query, $filter_setting, $filter_requests)
    {
        $model = (new static());
        foreach ($filter_requests as $filter_request) {
            // Clean inputs
Severity: Minor
Found in src/Traits/ModelTrait.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

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

    public static function getFilterAttributes($first_call = true)
    {
        $model = (new static());

        if (isset($model->filter_attributes) && is_array($model->filter_attributes)) {
Severity: Minor
Found in src/Traits/ModelTrait.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 ModelTrait.php has 518 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace Bluora\LaravelDynamicFilter\Traits;

use DB;
Severity: Major
Found in src/Traits/ModelTrait.php - About 1 day to fix

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

        public function getAppliedFiltersArray($search_request)
        {
            $model = (new static());
            $result = [];
            foreach ($model->getFilterAttributes() as $filter_name => $filter_settings) {
    Severity: Minor
    Found in src/Traits/ModelTrait.php - About 5 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 validateOperators has 135 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function validateOperators($filter, &$method, &$arguments, $model, $filter_setting, $operator, $value1, $value2)
        {
            // No space search.
            if (array_has($filter_setting, 'phone_search')) {
                $value1_numeric = str_replace(' ', '', $value1);
    Severity: Major
    Found in src/Traits/ModelTrait.php - About 5 hrs to fix

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

          private static function validateOperators($filter, &$method, &$arguments, $model, $filter_setting, $operator, $value1, $value2)
          {
              // No space search.
              if (array_has($filter_setting, 'phone_search')) {
                  $value1_numeric = str_replace(' ', '', $value1);
      Severity: Minor
      Found in src/Traits/ModelTrait.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

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

          public function scopeApplyAttributeFilters($query, $search_request)
          {
              if (isset($search_request['filters']) && is_array($search_request['filters']) && !empty($search_request['filters'])) {
      
                  // Get available filters
      Severity: Minor
      Found in src/Traits/ModelTrait.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 processAttributeFilter has 77 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private static function processAttributeFilter($query, $filter_setting, $filter_requests)
          {
              $model = (new static());
              foreach ($filter_requests as $filter_request) {
                  // Clean inputs
      Severity: Major
      Found in src/Traits/ModelTrait.php - About 3 hrs to fix

        Method getFilterAttributes has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function getFilterAttributes($first_call = true)
            {
                $model = (new static());
        
                if (isset($model->filter_attributes) && is_array($model->filter_attributes)) {
        Severity: Major
        Found in src/Traits/ModelTrait.php - About 2 hrs to fix

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

              public function scopeModelJoin($query, $relationships, $operator = '=', $type = 'left', $where = false)
              {
                  if (!is_array($relationships)) {
                      $relationships = [$relationships];
                  }
          Severity: Minor
          Found in src/Traits/ModelTrait.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 scopeModelJoin has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function scopeModelJoin($query, $relationships, $operator = '=', $type = 'left', $where = false)
              {
                  if (!is_array($relationships)) {
                      $relationships = [$relationships];
                  }
          Severity: Minor
          Found in src/Traits/ModelTrait.php - About 1 hr to fix

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

                public function scopeApplyAttributeFilters($query, $search_request)
                {
                    if (isset($search_request['filters']) && is_array($search_request['filters']) && !empty($search_request['filters'])) {
            
                        // Get available filters
            Severity: Minor
            Found in src/Traits/ModelTrait.php - About 1 hr to fix

              Method getAppliedFiltersArray has 36 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public function getAppliedFiltersArray($search_request)
                  {
                      $model = (new static());
                      $result = [];
                      foreach ($model->getFilterAttributes() as $filter_name => $filter_settings) {
              Severity: Minor
              Found in src/Traits/ModelTrait.php - About 1 hr to fix

                Method validateOperators has 8 arguments (exceeds 4 allowed). Consider refactoring.
                Open

                    private static function validateOperators($filter, &$method, &$arguments, $model, $filter_setting, $operator, $value1, $value2)
                Severity: Major
                Found in src/Traits/ModelTrait.php - About 1 hr to fix

                  Avoid deeply nested control flow statements.
                  Open

                                              if (in_array($check_operator, $available_operators)) {
                                                  $operator = $check_operator;
                                                  $value1 = implode(' ', $value1_array);
                                              }
                  Severity: Major
                  Found in src/Traits/ModelTrait.php - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                                    if (isset($settings['name'])) {
                                                        $filter_detail['name'] = $settings['name'].': '.$filter_detail['attribute_name'];
                                                    }
                    Severity: Major
                    Found in src/Traits/ModelTrait.php - About 45 mins to fix

                      Method scopeModelJoin has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                          public function scopeModelJoin($query, $relationships, $operator = '=', $type = 'left', $where = false)
                      Severity: Minor
                      Found in src/Traits/ModelTrait.php - About 35 mins to fix

                        Method applyFilterAttributeArray has 5 arguments (exceeds 4 allowed). Consider refactoring.
                        Open

                            private static function applyFilterAttributeArray($query, $attribute_list, $method, $arguments, $positive = true)
                        Severity: Minor
                        Found in src/Traits/ModelTrait.php - About 35 mins to fix

                          Avoid too many return statements within this method.
                          Open

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

                            Avoid too many return statements within this method.
                            Open

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

                              Avoid too many return statements within this method.
                              Open

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

                                Avoid too many return statements within this method.
                                Open

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

                                  Avoid too many return statements within this method.
                                  Open

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

                                    Avoid too many return statements within this method.
                                    Open

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

                                      Avoid too many return statements within this method.
                                      Open

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

                                        Avoid too many return statements within this method.
                                        Open

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

                                          Avoid too many return statements within this method.
                                          Open

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

                                            Avoid too many return statements within this method.
                                            Open

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

                                              Avoid too many return statements within this method.
                                              Open

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

                                                Avoid too many return statements within this method.
                                                Open

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

                                                  Avoid too many return statements within this method.
                                                  Open

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

                                                    Avoid too many return statements within this method.
                                                    Open

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

                                                      Avoid too many return statements within this method.
                                                      Open

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

                                                        Avoid too many return statements within this method.
                                                        Open

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

                                                          Avoid too many return statements within this method.
                                                          Open

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

                                                            Avoid too many return statements within this method.
                                                            Open

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

                                                              There are no issues that match your filters.

                                                              Category
                                                              Status