ForestAdmin/forest-rails

View on GitHub

Showing 121 of 136 total issues

Class SchemaAdapter has 24 methods (exceeds 20 allowed). Consider refactoring.
Open

  class SchemaAdapter
    def initialize(model)
      @model = model
    end

Severity: Minor
Found in app/services/forest_liana/schema_adapter.rb - About 2 hrs to fix

    Method fields_per_model has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def fields_per_model(params_fields, model)
          if params_fields
            if Rails::VERSION::MAJOR > 4
              params_fields_hash = params_fields.to_unsafe_h
            else
    Severity: Minor
    Found in app/controllers/forest_liana/application_controller.rb - 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 extract_relationships has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
    Open

        def extract_relationships
          if @params['data']['relationships']
            @params['data']['relationships'].each do |name, relationship|
              data = relationship['data']
              # Rails 3 requires a :sym argument for the reflect_on_association
    Severity: Minor
    Found in app/deserializers/forest_liana/resource_deserializer.rb - 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 perform has 63 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def perform
          raw_query = @params['query'].strip
    
          LiveQueryChecker.new(raw_query, 'Live Query Chart').validate()
    
    
    Severity: Major
    Found in app/services/forest_liana/query_stat_getter.rb - About 2 hrs to fix

      Method add_columns has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
      Open

          def add_columns
            @model.columns.each do |column|
              unless is_sti_column_of_child_model?(column)
                field_schema = get_schema_for_column(column)
                collection.fields << field_schema unless field_schema.nil?
      Severity: Minor
      Found in app/services/forest_liana/schema_adapter.rb - 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

      Class FiltersParser has 22 methods (exceeds 20 allowed). Consider refactoring.
      Open

        class FiltersParser
          AGGREGATOR_OPERATOR = %w(and or)
      
          def initialize(filters, resource, timezone, params = nil)
            @filters = filters
      Severity: Minor
      Found in app/services/forest_liana/filters_parser.rb - About 2 hrs to fix

        Method initialize has 58 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def initialize filename, collections, meta
              @filename = filename
              @meta = meta
        
              # NOTICE: Remove unecessary keys
        Severity: Major
        Found in lib/forest_liana/schema_file_updater.rb - About 2 hrs to fix

          Method field has 58 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              def field(name, opts, &block)
                # TODO: Handle empty name
          
                if opts.key?(:isRequired)
                  FOREST_LOGGER.warn "DEPRECATION WARNING: isRequired on field \"#{name}\" is deprecated. Please use is_required."
          Severity: Major
          Found in lib/forest_liana/collection.rb - About 2 hrs to fix

            Method send_apimap has 55 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                def send_apimap(with_feedback=false)
                  if ForestLiana.env_secret && ForestLiana.env_secret.length != 64
                    FOREST_LOGGER.error "Your env_secret does not seem to be correct. " \
                      "Can you check on Forest that you copied it properly in the " \
                      "forest_liana initializer?"
            Severity: Major
            Found in lib/forest_liana/bootstrapper.rb - About 2 hrs to fix

              Method initialize has 55 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def initialize(attributes = {})
                  if attributes.key?(:global)
                    FOREST_LOGGER.error "REMOVED OPTION: The support for Smart Action \"global\" option is now " \
                      "removed. Please set \"type: 'global'\" instead of \"global: true\" for the " \
                      "\"#{attributes[:name]}\" Smart Action."
              Severity: Major
              Found in app/models/forest_liana/model/action.rb - About 2 hrs to fix

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

                    def perform
                      add_columns
                      add_associations
                
                      collection.fields.sort_by!.with_index { |k, idx| [k[:field].to_s, idx] }
                Severity: Minor
                Found in app/services/forest_liana/schema_adapter.rb - About 2 hrs to fix

                  Method render_csv has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def render_csv getter, model
                        set_headers_file
                        set_headers_streaming
                  
                        response.status = 200
                  Severity: Minor
                  Found in app/controllers/forest_liana/application_controller.rb - 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 call has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def call(env)
                      params = env['action_dispatch.request.path_parameters']
                      collection_name = params[:collection]
                      resource = ForestLiana::SchemaUtils.find_model_from_collection_name(collection_name, true)
                  
                  
                  Severity: Minor
                  Found in app/controllers/forest_liana/router.rb - 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 setup_intercom_integration has 47 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      def setup_intercom_integration(collection_name)
                        model_name = ForestLiana.name_for(collection_name.constantize)
                        # TODO: Remove once lianas prior to 2.0.0 are not supported anymore.
                        model_name_old = ForestLiana.name_old_for(collection_name.constantize)
                  
                  
                  Severity: Minor
                  Found in lib/forest_liana/bootstrapper.rb - About 1 hr to fix

                    Method set_has_many_relationships has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def set_has_many_relationships
                          if @params['data']['relationships']
                            @params['data']['relationships'].each do |name, relationship|
                              data = relationship['data']
                              association = @resource.reflect_on_association(name.to_sym)
                    Severity: Minor
                    Found in app/services/forest_liana/resource_creator.rb - 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 handle_result has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
                    Open

                        def handle_result(result, action)
                          if result.nil? || !result.is_a?(Array)
                            return render status: 500, json: { error: 'Error in smart action load hook: hook must return an array of fields' }
                          end
                    
                    
                    Severity: Minor
                    Found in app/controllers/forest_liana/actions_controller.rb - 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 get_date_filter has 43 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def get_date_filter(operator, value)
                          return nil unless is_date_operator? operator
                    
                          filter = case operator
                            when OPERATOR_FUTURE
                    Severity: Minor
                    Found in app/services/forest_liana/operator_date_interval_parser.rb - About 1 hr to fix

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

                          def install
                            if ForestLiana.env_secret.present?
                              puts "\nForest liana already installed on this app.\nHere is your current environment " +
                                "secret: #{ForestLiana.env_secret}\nYou can update the config/secrets.yml file with the " +
                                "new environment secret: #{env_secret}"
                      Severity: Minor
                      Found in lib/generators/forest_liana/install_generator.rb - About 1 hr to fix

                        Method call has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          def call(env)
                            params = env['action_dispatch.request.path_parameters']
                            collection_name = params[:collection]
                            resource = ForestLiana::SchemaUtils.find_model_from_collection_name(collection_name, true)
                        
                        
                        Severity: Minor
                        Found in app/controllers/forest_liana/router.rb - About 1 hr to fix

                          Method pretty_print has 40 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                              def pretty_print json, indentation = ""
                                result = ""
                          
                                if json.kind_of? Array
                                  result << "["
                          Severity: Minor
                          Found in lib/forest_liana/json_printer.rb - About 1 hr to fix
                            Severity
                            Category
                            Status
                            Source
                            Language