hnhdigital-os/laravel-model-search

View on GitHub
src/ModelSearch.php

Summary

Maintainability
F
4 days
Test Coverage

File ModelSearch.php has 886 lines of code (exceeds 250 allowed). Consider refactoring.
Wontfix

<?php

namespace HnhDigital\ModelSearch;

use Illuminate\Database\Query\Expression;
Severity: Major
Found in src/ModelSearch.php - About 2 days to fix

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

        private function processRequest($request)
        {
            $this->request = self::parseRequest($request);
    
            if (empty($this->request)) {
    Severity: Minor
    Found in src/ModelSearch.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

    ModelSearch has 39 functions (exceeds 20 allowed). Consider refactoring.
    Wontfix

    class ModelSearch
    {
        /**
         * Filter types.
         *
    Severity: Minor
    Found in src/ModelSearch.php - About 5 hrs to fix

      Method filterByString has 62 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function filterByString($filter)
          {
              $operator = Arr::get($filter, 'operator');
              $method = Arr::get($filter, 'method');
              $arguments = Arr::get($filter, 'arguments');
      Severity: Major
      Found in src/ModelSearch.php - About 2 hrs to fix

        Method filterByNumber has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function filterByNumber($filter)
            {
                $operator = Arr::get($filter, 'operator');
                $method = Arr::get($filter, 'method');
                $arguments = Arr::get($filter, 'arguments');
        Severity: Major
        Found in src/ModelSearch.php - About 2 hrs to fix

          Method processRequest has 51 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              private function processRequest($request)
              {
                  $this->request = self::parseRequest($request);
          
                  if (empty($this->request)) {
          Severity: Major
          Found in src/ModelSearch.php - About 2 hrs to fix

            Method modelJoin has 41 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                public function modelJoin($relationships, $operator = '=', $type = 'left', $where = false)
                {
                    $relationships = Arr::wrap($relationships);
            
                    // Check relationships array and remove any that we don't have conenction for.
            Severity: Minor
            Found in src/ModelSearch.php - About 1 hr to fix

              Method filterByListLookup has 41 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  public static function filterByListLookup($filter)
                  {
                      $operator = Arr::get($filter, 'operator');
                      $method = Arr::get($filter, 'method');
                      $source = Arr::get($filter, 'settings.source');
              Severity: Minor
              Found in src/ModelSearch.php - About 1 hr to fix

                Method validateFilterItem has 37 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                    private static function validateFilterItem($filter, $settings)
                    {
                        // Convert string to filter array.
                        if (! is_array($filter)) {
                            $filter = ['', $filter];
                Severity: Minor
                Found in src/ModelSearch.php - About 1 hr to fix

                  Method getRelation has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      private static function getRelation($relation)
                      {
                          $method = basename(str_replace('\\', '/', get_class($relation)));
                  
                          switch ($method) {
                  Severity: Minor
                  Found in src/ModelSearch.php - About 1 hr to fix

                    Method buildCastedAttributes has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        private static function buildCastedAttributes($model, &$result, $method = null)
                        {
                            $model_name = 'self';
                            $name_append = '';
                    
                    
                    Severity: Minor
                    Found in src/ModelSearch.php - About 1 hr to fix

                      Method filterByUuid has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                          public static function filterByUuid($filter)
                          {
                              $operator = Arr::get($filter, 'operator');
                              $method = Arr::get($filter, 'method');
                              $arguments = Arr::get($filter, 'arguments');
                      Severity: Minor
                      Found in src/ModelSearch.php - About 1 hr to fix

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

                            public static function filterByString($filter)
                            {
                                $operator = Arr::get($filter, 'operator');
                                $method = Arr::get($filter, 'method');
                                $arguments = Arr::get($filter, 'arguments');
                        Severity: Minor
                        Found in src/ModelSearch.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 filterByListLookup has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                        Open

                            public static function filterByListLookup($filter)
                            {
                                $operator = Arr::get($filter, 'operator');
                                $method = Arr::get($filter, 'method');
                                $source = Arr::get($filter, 'settings.source');
                        Severity: Minor
                        Found in src/ModelSearch.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 filterByScope has 30 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                            public static function filterByScope($filter)
                            {
                                $operator = Arr::get($filter, 'operator');
                                $method = Arr::get($filter, 'method');
                                $source = Arr::get($filter, 'settings.source');
                        Severity: Minor
                        Found in src/ModelSearch.php - About 1 hr to fix

                          Method buildSearchAttributes has 27 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              private static function buildSearchAttributes($model, &$result, $method = null)
                              {
                                  $model_name = 'self';
                                  $name_append = '';
                          
                          
                          Severity: Minor
                          Found in src/ModelSearch.php - About 1 hr to fix

                            Method applySearchFilter has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                            Open

                                private static function applySearchFilter(&$query, $filter)
                                {
                                    $filter_type = Arr::get($filter, 'settings.filter');
                                    $method = Arr::get($filter, 'method');
                                    $arguments = Arr::get($filter, 'arguments');
                            Severity: Minor
                            Found in src/ModelSearch.php - About 1 hr to fix

                              Method filterByBoolean has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                              Open

                                  public static function filterByBoolean($filter)
                                  {
                                      $operator = Arr::get($filter, 'operator');
                                      $method = Arr::get($filter, 'method');
                                      $arguments = Arr::get($filter, 'arguments');
                              Severity: Minor
                              Found in src/ModelSearch.php - About 1 hr to fix

                                Method filterByList has 26 lines of code (exceeds 25 allowed). Consider refactoring.
                                Open

                                    public static function filterByList($filter)
                                    {
                                        $operator = Arr::get($filter, 'operator');
                                        $method = Arr::get($filter, 'method');
                                        $arguments = Arr::get($filter, 'arguments');
                                Severity: Minor
                                Found in src/ModelSearch.php - About 1 hr to fix

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

                                      public static function filterByNumber($filter)
                                      {
                                          $operator = Arr::get($filter, 'operator');
                                          $method = Arr::get($filter, 'method');
                                          $arguments = Arr::get($filter, 'arguments');
                                  Severity: Minor
                                  Found in src/ModelSearch.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 modelJoin has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      public function modelJoin($relationships, $operator = '=', $type = 'left', $where = false)
                                      {
                                          $relationships = Arr::wrap($relationships);
                                  
                                          // Check relationships array and remove any that we don't have conenction for.
                                  Severity: Minor
                                  Found in src/ModelSearch.php - About 45 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 validateFilterItem has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                                  Open

                                      private static function validateFilterItem($filter, $settings)
                                      {
                                          // Convert string to filter array.
                                          if (! is_array($filter)) {
                                              $filter = ['', $filter];
                                  Severity: Minor
                                  Found in src/ModelSearch.php - About 45 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 'IN';
                                  Severity: Major
                                  Found in src/ModelSearch.php - About 30 mins to fix

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

                                        private static function buildCastedAttributes($model, &$result, $method = null)
                                        {
                                            $model_name = 'self';
                                            $name_append = '';
                                    
                                    
                                    Severity: Minor
                                    Found in src/ModelSearch.php - About 25 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 getRelation has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private static function getRelation($relation)
                                        {
                                            $method = basename(str_replace('\\', '/', get_class($relation)));
                                    
                                            switch ($method) {
                                    Severity: Minor
                                    Found in src/ModelSearch.php - About 25 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 validateAttributes has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                                    Open

                                        private static function validateAttributes($model, $name, &$attributes)
                                        {
                                            // Should be an array.
                                            if (! is_array($attributes)) {
                                                $attributes = [$attributes];
                                    Severity: Minor
                                    Found in src/ModelSearch.php - About 25 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

                                    There are no issues that match your filters.

                                    Category
                                    Status