ikuseiGmbH/smart-village-app-cms

View on GitHub
app/controllers/tours_controller.rb

Summary

Maintainability
F
1 wk
Test Coverage

Parameters should be whitelisted for mass assignment
Open

      params.require(:tour).permit!

Mass assignment is a feature of Rails which allows an application to create a record from the values of a hash.

Example:

User.new(params[:user])

Unfortunately, if there is a user field called admin which controls administrator access, now any user can make themselves an administrator.

attr_accessible and attr_protected can be used to limit mass assignment. However, Brakeman will warn unless attr_accessible is used, or mass assignment is completely disabled.

There are two different mass assignment warnings which can arise. The first is when mass assignment actually occurs, such as the example above. This results in a warning like

Unprotected mass assignment near line 61: User.new(params[:user])

The other warning is raised whenever a model is found which does not use attr_accessible. This produces generic warnings like

Mass assignment is not restricted using attr_accessible

with a list of affected models.

In Rails 3.1 and newer, mass assignment can easily be disabled:

config.active_record.whitelist_attributes = true

Unfortunately, it can also easily be bypassed:

User.new(params[:user], :without_protection => true)

Brakeman will warn on uses of without_protection.

Complex method ToursController#convert_params_for_graphql (411.5)
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb by flog

Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

You can read more about ABC metrics or the flog tool

Method convert_params_for_graphql has a Cognitive Complexity of 164 (exceeds 5 allowed). Consider refactoring.
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb - About 3 days 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 has too many lines. [404/100]
Open

class ToursController < ApplicationController
  before_action :verify_current_user
  before_action { verify_current_user_role("role_tour") }
  before_action :init_graphql_client
  before_action :load_category_list, only: [:edit, :new, :create]
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks if the length a class exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for convert_params_for_graphql is too high. [203.2/15]
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

Method has too many lines. [152/10]
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Method has too many lines. [105/10]
Open

  def edit
    results = @smart_village.query <<~GRAPHQL
      query {
        tour(
          id: #{params[:id]}
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

Assignment Branch Condition size for set_defaults_and_types is too high. [66.29/15]
Open

    def set_defaults_and_types(entry)
      # set default values
      entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")

      if entry.keys.include?("temperature")
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

Block has too many lines. [102/25]
Open

        @tour_params["tour_stops"].each do |_key, tour_stop|
          next if tour_stop.blank?
          next if tour_stop["name"].blank?

          if tour_stop["payload"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks if the length of a block exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable. The cop can be configured to ignore blocks passed to certain methods.

Perceived complexity for convert_params_for_graphql is too high. [49/7]
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

Example:

def my_method                   # 1
  if cond                       # 1
    case var                    # 2 (0.8 + 4 * 0.2, rounded)
    when 1 then func_one
    when 2 then func_two
    when 3 then func_three
    when 4..10 then func_other
    end
  else                          # 1
    do_something until a && b   # 2
  end                           # ===
end                             # 7 complexity points

Cyclomatic complexity for convert_params_for_graphql is too high. [46/6]
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Minor
Found in app/controllers/tours_controller.rb by rubocop

This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

Method convert_params_for_graphql has 152 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def convert_params_for_graphql
      # Check recursively if any addresses data is given.
      # If not, we do not want to submit the params, because the name is required by the model,
      # which will result in a validation error.
      if @tour_params["addresses"].present?
Severity: Major
Found in app/controllers/tours_controller.rb - About 6 hrs to fix

    File tours_controller.rb has 406 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    class ToursController < ApplicationController
      before_action :verify_current_user
      before_action { verify_current_user_role("role_tour") }
      before_action :init_graphql_client
      before_action :load_category_list, only: [:edit, :new, :create]
    Severity: Minor
    Found in app/controllers/tours_controller.rb - About 5 hrs to fix

      Method has too many lines. [42/10]
      Open

          def set_defaults_and_types(entry)
            # set default values
            entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
      
            if entry.keys.include?("temperature")
      Severity: Minor
      Found in app/controllers/tours_controller.rb by rubocop

      This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

      Complex method ToursController#set_defaults_and_types (77.4)
      Open

          def set_defaults_and_types(entry)
            # set default values
            entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
      
            if entry.keys.include?("temperature")
      Severity: Minor
      Found in app/controllers/tours_controller.rb by flog

      Flog calculates the ABC score for methods. The ABC score is based on assignments, branches (method calls), and conditions.

      You can read more about ABC metrics or the flog tool

      Method edit has 105 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def edit
          results = @smart_village.query <<~GRAPHQL
            query {
              tour(
                id: #{params[:id]}
      Severity: Major
      Found in app/controllers/tours_controller.rb - About 4 hrs to fix

        Perceived complexity for set_defaults_and_types is too high. [25/7]
        Open

            def set_defaults_and_types(entry)
              # set default values
              entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
        
              if entry.keys.include?("temperature")
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop tries to produce a complexity score that's a measure of the complexity the reader experiences when looking at a method. For that reason it considers when nodes as something that doesn't add as much complexity as an if or a &&. Except if it's one of those special case/when constructs where there's no expression after case. Then the cop treats it as an if/elsif/elsif... and lets all the when nodes count. In contrast to the CyclomaticComplexity cop, this cop considers else nodes as adding complexity.

        Example:

        def my_method                   # 1
          if cond                       # 1
            case var                    # 2 (0.8 + 4 * 0.2, rounded)
            when 1 then func_one
            when 2 then func_two
            when 3 then func_three
            when 4..10 then func_other
            end
          else                          # 1
            do_something until a && b   # 2
          end                           # ===
        end                             # 7 complexity points

        Method set_defaults_and_types has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
        Open

            def set_defaults_and_types(entry)
              # set default values
              entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
        
              if entry.keys.include?("temperature")
        Severity: Minor
        Found in app/controllers/tours_controller.rb - 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

        Cyclomatic complexity for set_defaults_and_types is too high. [21/6]
        Open

            def set_defaults_and_types(entry)
              # set default values
              entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
        
              if entry.keys.include?("temperature")
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop checks that the cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

        An if statement (or unless or ?:) increases the complexity by one. An else branch does not, since it doesn't add a decision point. The && operator (or keyword and) can be converted to a nested if statement, and ||/or is shorthand for a sequence of ifs, so they also add one. Loops can be said to have an exit condition, so they add one.

        Method has too many lines. [19/10]
        Open

          def index
            results = @smart_village.query <<~GRAPHQL
              query {
                tours {
                  id
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Method has too many lines. [18/10]
        Open

          def destroy
            results = @smart_village.query <<~GRAPHQL
              mutation {
                destroyRecord(
                  id: #{params["id"]},
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Method has too many lines. [13/10]
        Open

            def new_tour
              OpenStruct.new(
                addresses: [OpenStruct.new(
                  geo_location: OpenStruct.new
                )],
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Method has too many lines. [12/10]
        Open

          def create
            query = create_or_update_mutation
            begin
              results = @smart_village.query query
            rescue Graphlient::Errors::GraphQLError => e
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop checks if the length of a method exceeds some maximum value. Comment lines can optionally be ignored. The maximum allowed length is configurable.

        Assignment Branch Condition size for create is too high. [16.58/15]
        Open

          def create
            query = create_or_update_mutation
            begin
              results = @smart_village.query query
            rescue Graphlient::Errors::GraphQLError => e
        Severity: Minor
        Found in app/controllers/tours_controller.rb by rubocop

        This cop checks that the ABC size of methods is not higher than the configured maximum. The ABC size is based on assignments, branches (method calls), and conditions. See http://c2.com/cgi/wiki?AbcMetric and https://en.wikipedia.org/wiki/ABC_Software_Metric.

        Method set_defaults_and_types has 42 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            def set_defaults_and_types(entry)
              # set default values
              entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
        
              if entry.keys.include?("temperature")
        Severity: Minor
        Found in app/controllers/tours_controller.rb - About 1 hr to fix

          ToursController#convert_params_for_graphql refers to 'tour_stop' more than self (maybe move it to another class?)
          Open

                    next if tour_stop.blank?
                    next if tour_stop["name"].blank?
          
                    if tour_stop["payload"].present?
                      if tour_stop["payload"]["scenes"].present?
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          Feature Envy occurs when a code fragment references another object more often than it references itself, or when several clients do the same series of manipulations on a particular type of object.

          Feature Envy reduces the code's ability to communicate intent: code that "belongs" on one class but which is located in another can be hard to find, and may upset the "System of Names" in the host class.

          Feature Envy also affects the design's flexibility: A code fragment that is in the wrong class creates couplings that may not be natural within the application's domain, and creates a loss of cohesion in the unwilling host class.

          Feature Envy often arises because it must manipulate other objects (usually its arguments) to get them into a useful form, and one force preventing them (the arguments) doing this themselves is that the common knowledge lives outside the arguments, or the arguments are of too basic a type to justify extending that type. Therefore there must be something which 'knows' about the contents or purposes of the arguments. That thing would have to be more than just a basic type, because the basic types are either containers which don't know about their contents, or they are single objects which can't capture their relationship with their fellows of the same type. So, this thing with the extra knowledge should be reified into a class, and the utility method will most likely belong there.

          Example

          Running Reek on:

          class Warehouse
            def sale_price(item)
              (item.price - item.rebate) * @vat
            end
          end

          would report:

          Warehouse#total_price refers to item more than self (FeatureEnvy)

          since this:

          (item.price - item.rebate)

          belongs to the Item class, not the Warehouse.

          ToursController#convert_params_for_graphql has approx 87 statements
          Open

              def convert_params_for_graphql
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          A method with Too Many Statements is any method that has a large number of lines.

          Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

          So the following method would score +6 in Reek's statement-counting algorithm:

          def parse(arg, argv, &error)
            if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
              return nil, block, nil                                         # +1
            end
            opt = (val = parse_arg(val, &error))[1]                          # +2
            val = conv_arg(*val)                                             # +3
            if opt and !arg
              argv.shift                                                     # +4
            else
              val[0] = nil                                                   # +5
            end
            val                                                              # +6
          end

          (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

          ToursController#set_defaults_and_types has approx 18 statements
          Open

              def set_defaults_and_types(entry)
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          A method with Too Many Statements is any method that has a large number of lines.

          Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

          So the following method would score +6 in Reek's statement-counting algorithm:

          def parse(arg, argv, &error)
            if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
              return nil, block, nil                                         # +1
            end
            opt = (val = parse_arg(val, &error))[1]                          # +2
            val = conv_arg(*val)                                             # +3
            if opt and !arg
              argv.shift                                                     # +4
            else
              val[0] = nil                                                   # +5
            end
            val                                                              # +6
          end

          (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

          ToursController#create has approx 10 statements
          Open

            def create
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          A method with Too Many Statements is any method that has a large number of lines.

          Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

          So the following method would score +6 in Reek's statement-counting algorithm:

          def parse(arg, argv, &error)
            if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
              return nil, block, nil                                         # +1
            end
            opt = (val = parse_arg(val, &error))[1]                          # +2
            val = conv_arg(*val)                                             # +3
            if opt and !arg
              argv.shift                                                     # +4
            else
              val[0] = nil                                                   # +5
            end
            val                                                              # +6
          end

          (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

          ToursController#update has approx 6 statements
          Open

            def update
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          A method with Too Many Statements is any method that has a large number of lines.

          Too Many Statements warns about any method that has more than 5 statements. Reek's smell detector for Too Many Statements counts +1 for every simple statement in a method and +1 for every statement within a control structure (if, else, case, when, for, while, until, begin, rescue) but it doesn't count the control structure itself.

          So the following method would score +6 in Reek's statement-counting algorithm:

          def parse(arg, argv, &error)
            if !(val = arg) and (argv.empty? or /\A-/ =~ (val = argv[0]))
              return nil, block, nil                                         # +1
            end
            opt = (val = parse_arg(val, &error))[1]                          # +2
            val = conv_arg(*val)                                             # +3
            if opt and !arg
              argv.shift                                                     # +4
            else
              val[0] = nil                                                   # +5
            end
            val                                                              # +6
          end

          (You might argue that the two assigments within the first @if@ should count as statements, and that perhaps the nested assignment should count as +2.)

          ToursController#convert_params_for_graphql contains iterators nested 3 deep
          Open

                            scene["downloadable_uris"].each do |_key, downloadable_uri|
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          A Nested Iterator occurs when a block contains another block.

          Example

          Given

          class Duck
            class << self
              def duck_names
                %i!tick trick track!.each do |surname|
                  %i!duck!.each do |last_name|
                    puts "full name is #{surname} #{last_name}"
                  end
                end
              end
            end
          end

          Reek would report the following warning:

          test.rb -- 1 warning:
            [5]:Duck#duck_names contains iterators nested 2 deep (NestedIterators)

          ToursController#create_or_update_mutation has boolean parameter 'update'
          Open

              def create_or_update_mutation(update = false)
          Severity: Minor
          Found in app/controllers/tours_controller.rb by reek

          Boolean Parameter is a special case of Control Couple, where a method parameter is defaulted to true or false. A Boolean Parameter effectively permits a method's caller to decide which execution path to take. This is a case of bad cohesion. You're creating a dependency between methods that is not really necessary, thus increasing coupling.

          Example

          Given

          class Dummy
            def hit_the_switch(switch = true)
              if switch
                puts 'Hitting the switch'
                # do other things...
              else
                puts 'Not hitting the switch'
                # do other things...
              end
            end
          end

          Reek would emit the following warning:

          test.rb -- 3 warnings:
            [1]:Dummy#hit_the_switch has boolean parameter 'switch' (BooleanParameter)
            [2]:Dummy#hit_the_switch is controlled by argument switch (ControlParameter)

          Note that both smells are reported, Boolean Parameter and Control Parameter.

          Getting rid of the smell

          This is highly dependent on your exact architecture, but looking at the example above what you could do is:

          • Move everything in the if branch into a separate method
          • Move everything in the else branch into a separate method
          • Get rid of the hit_the_switch method alltogether
          • Make the decision what method to call in the initial caller of hit_the_switch

          Avoid deeply nested control flow statements.
          Open

                          if tour_stop["payload"]["image"].present? && tour_stop["payload"]["image"]["uri"].present?
                            image = set_defaults_and_types(tour_stop["payload"]["image"])
                            image["id"] = "-4"
          
                            scene_downloadable_uris.unshift(image)
          Severity: Major
          Found in app/controllers/tours_controller.rb - About 45 mins to fix

            Avoid deeply nested control flow statements.
            Open

                                next if downloadable_uri.blank?
            Severity: Major
            Found in app/controllers/tours_controller.rb - About 45 mins to fix

              Avoid deeply nested control flow statements.
              Open

                              if tour_stop["payload"]["quad"].present?
                                quad = set_defaults_and_types(tour_stop["payload"]["quad"])
                                quad["id"] = "-6"
                                quad["height"] = 1000
                                quad["width"] = 1000
              Severity: Major
              Found in app/controllers/tours_controller.rb - About 45 mins to fix

                Avoid deeply nested control flow statements.
                Open

                                if tour_stop["payload"]["light"].present?
                                  light = set_defaults_and_types(tour_stop["payload"]["light"])
                                  light["id"] = "-5"
                
                                  scene_downloadable_uris.unshift(light)
                Severity: Major
                Found in app/controllers/tours_controller.rb - About 45 mins to fix

                  Avoid deeply nested control flow statements.
                  Open

                                      if downloadable_uri.keys.include?("uri") && downloadable_uri["uri"].blank?
                                        downloadable_uris << {}
                                        next
                                      end
                  Severity: Major
                  Found in app/controllers/tours_controller.rb - About 45 mins to fix

                    Avoid deeply nested control flow statements.
                    Open

                                    if tour_stop["payload"]["start_date"].present? && tour_stop["payload"]["time_period_in_days"].present?
                                      scene = scenes.first
                                    end
                    Severity: Major
                    Found in app/controllers/tours_controller.rb - About 45 mins to fix

                      Avoid deeply nested control flow statements.
                      Open

                                      if tour_stop["payload"]["mp4"].present? && tour_stop["payload"]["mp4"]["uri"].present?
                                        mp4 = set_defaults_and_types(tour_stop["payload"]["mp4"])
                                        mp4["id"] = "-3"
                      
                                        scene_downloadable_uris.unshift(mp4)
                      Severity: Major
                      Found in app/controllers/tours_controller.rb - About 45 mins to fix

                        Avoid deeply nested control flow statements.
                        Open

                                        if tour_stop["payload"]["target"].present? && tour_stop["payload"]["target"]["uri"].present?
                                          target = set_defaults_and_types(tour_stop["payload"]["target"])
                                          target["id"] = "-1"
                        
                                          scene_downloadable_uris.unshift(target)
                        Severity: Major
                        Found in app/controllers/tours_controller.rb - About 45 mins to fix

                          Avoid deeply nested control flow statements.
                          Open

                                          if tour_stop["payload"]["mp3"].present? && tour_stop["payload"]["mp3"]["uri"].present?
                                            mp3 = set_defaults_and_types(tour_stop["payload"]["mp3"])
                                            mp3["id"] = "-2"
                          
                                            scene_downloadable_uris.unshift(mp3)
                          Severity: Major
                          Found in app/controllers/tours_controller.rb - About 45 mins to fix

                            Avoid deeply nested control flow statements.
                            Open

                                            if tour_stop["payload"]["spot"].present?
                                              spot = tour_stop["payload"]["spot"]
                                              spot["id"] = "-7"
                                              spot["shadow_opacity"] = spot["shadow_opacity"].presence || 0.6
                                              spot["inner_angle"] = spot["inner_angle"].presence || 5
                            Severity: Major
                            Found in app/controllers/tours_controller.rb - About 45 mins to fix

                              Avoid deeply nested control flow statements.
                              Open

                                                  if downloadable_uri["size"].present?
                                                    total_size_calculated_from_downloadable_uris += downloadable_uri["size"]
                                                  end
                              Severity: Major
                              Found in app/controllers/tours_controller.rb - About 45 mins to fix

                                ToursController#set_defaults_and_types calls 'entry["min_distance"]' 2 times
                                Open

                                      entry["min_distance"] = entry["min_distance"].to_f if entry["min_distance"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController assumes too much for instance variable '@tour_params'
                                Open

                                class ToursController < ApplicationController
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Classes should not assume that instance variables are set or present outside of the current class definition.

                                Good:

                                class Foo
                                  def initialize
                                    @bar = :foo
                                  end
                                
                                  def foo?
                                    @bar == :foo
                                  end
                                end

                                Good as well:

                                class Foo
                                  def foo?
                                    bar == :foo
                                  end
                                
                                  def bar
                                    @bar ||= :foo
                                  end
                                end

                                Bad:

                                class Foo
                                  def go_foo!
                                    @bar = :foo
                                  end
                                
                                  def foo?
                                    @bar == :foo
                                  end
                                end

                                Example

                                Running Reek on:

                                class Dummy
                                  def test
                                    @ivar
                                  end
                                end

                                would report:

                                [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

                                Note that this example would trigger this smell warning as well:

                                class Parent
                                  def initialize(omg)
                                    @omg = omg
                                  end
                                end
                                
                                class Child < Parent
                                  def foo
                                    @omg
                                  end
                                end

                                The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

                                class Parent
                                  attr_reader :omg
                                
                                  def initialize(omg)
                                    @omg = omg
                                  end
                                end
                                
                                class Child < Parent
                                  def foo
                                    omg
                                  end
                                end

                                Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

                                If you don't want to expose those methods as public API just make them private like this:

                                class Parent
                                  def initialize(omg)
                                    @omg = omg
                                  end
                                
                                  private
                                  attr_reader :omg
                                end
                                
                                class Child < Parent
                                  def foo
                                    omg
                                  end
                                end

                                Current Support in Reek

                                An instance variable must:

                                • be set in the constructor
                                • or be accessed through a method with lazy initialization / memoization.

                                If not, Instance Variable Assumption will be reported.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["target"]' 3 times
                                Open

                                                if tour_stop["payload"]["target"].present? && tour_stop["payload"]["target"]["uri"].present?
                                                  target = set_defaults_and_types(tour_stop["payload"]["target"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["categories"]' 2 times
                                Open

                                      if @tour_params["categories"].present?
                                        categories = []
                                        @tour_params["categories"].each do |_key, category|
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'spot["direction"]' 2 times
                                Open

                                                  spot["direction"] = if spot["direction"].present?
                                                                        JSON.parse(spot["direction"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["spot"]' 2 times
                                Open

                                                if tour_stop["payload"]["spot"].present?
                                                  spot = tour_stop["payload"]["spot"]
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["contact"]' 2 times
                                Open

                                      if @tour_params["contact"].present?
                                        unless nested_values?(@tour_params["contact"].to_h).include?(true)
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["quad"]' 2 times
                                Open

                                                if tour_stop["payload"]["quad"].present?
                                                  quad = set_defaults_and_types(tour_stop["payload"]["quad"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["mp3"]' 3 times
                                Open

                                                if tour_stop["payload"]["mp3"].present? && tour_stop["payload"]["mp3"]["uri"].present?
                                                  mp3 = set_defaults_and_types(tour_stop["payload"]["mp3"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry.keys' 8 times
                                Open

                                      entry["color"] = entry["color"].presence || "#ffffff" if entry.keys.include?("color")
                                
                                      if entry.keys.include?("temperature")
                                        entry["temperature"] = entry["temperature"].presence || "6500"
                                      end
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'downloadable_uri["size"]' 2 times
                                Open

                                                    if downloadable_uri["size"].present?
                                                      total_size_calculated_from_downloadable_uris += downloadable_uri["size"]
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["time_period_in_days"].present?' 2 times
                                Open

                                                if tour_stop["payload"]["start_date"].present? && tour_stop["payload"]["time_period_in_days"].present?
                                                  scene = scenes.first
                                                end
                                
                                                scene_downloadable_uris = scene["downloadable_uris"]
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["max_distance"]' 2 times
                                Open

                                      entry["max_distance"] = entry["max_distance"].to_f if entry["max_distance"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["rotation"]' 2 times
                                Open

                                        entry["rotation"] = if entry["rotation"].present?
                                                              JSON.parse(entry["rotation"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["size"]' 2 times
                                Open

                                      entry["size"] = entry["size"].to_i if entry["size"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController has no descriptive comment
                                Open

                                class ToursController < ApplicationController
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Classes and modules are the units of reuse and release. It is therefore considered good practice to annotate every class and module with a brief comment outlining its responsibilities.

                                Example

                                Given

                                class Dummy
                                  # Do things...
                                end

                                Reek would emit the following warning:

                                test.rb -- 1 warning:
                                  [1]:Dummy has no descriptive comment (IrresponsibleModule)

                                Fixing this is simple - just an explaining comment:

                                # The Dummy class is responsible for ...
                                class Dummy
                                  # Do things...
                                end

                                ToursController#set_defaults_and_types calls 'entry["scale"]' 2 times
                                Open

                                        entry["scale"] = if entry["scale"].present?
                                                           JSON.parse(entry["scale"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["temperature"]' 3 times
                                Open

                                        entry["temperature"] = entry["temperature"].presence || "6500"
                                      end
                                      entry["intensity"] = entry["intensity"].presence || "1000" if entry.keys.include?("intensity")
                                
                                      # converts to float
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["length_km"]' 2 times
                                Open

                                      @tour_params["length_km"] = if @tour_params["length_km"].present?
                                                                    @tour_params["length_km"].to_i
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["light"]' 2 times
                                Open

                                                if tour_stop["payload"]["light"].present?
                                                  light = set_defaults_and_types(tour_stop["payload"]["light"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["mp4"]' 3 times
                                Open

                                                if tour_stop["payload"]["mp4"].present? && tour_stop["payload"]["mp4"]["uri"].present?
                                                  mp4 = set_defaults_and_types(tour_stop["payload"]["mp4"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["direction"]' 2 times
                                Open

                                        entry["direction"] = if entry["direction"].present?
                                                               JSON.parse(entry["direction"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["operating_company"]' 2 times
                                Open

                                      if @tour_params["operating_company"].present?
                                        unless nested_values?(@tour_params["operating_company"].to_h).include?(true)
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["addresses"]' 2 times
                                Open

                                      if @tour_params["addresses"].present?
                                        unless nested_values?(@tour_params["addresses"].to_h).include?(true)
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]' 33 times
                                Open

                                          if tour_stop["payload"].present?
                                            if tour_stop["payload"]["scenes"].present?
                                              scenes = []
                                              total_size_calculated_from_downloadable_uris = 0
                                
                                
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["time_period_in_days"]' 3 times
                                Open

                                                if tour_stop["payload"]["start_date"].present? && tour_stop["payload"]["time_period_in_days"].present?
                                                  scene = scenes.first
                                                end
                                
                                                scene_downloadable_uris = scene["downloadable_uris"]
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController assumes too much for instance variable '@smart_village'
                                Open

                                class ToursController < ApplicationController
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Classes should not assume that instance variables are set or present outside of the current class definition.

                                Good:

                                class Foo
                                  def initialize
                                    @bar = :foo
                                  end
                                
                                  def foo?
                                    @bar == :foo
                                  end
                                end

                                Good as well:

                                class Foo
                                  def foo?
                                    bar == :foo
                                  end
                                
                                  def bar
                                    @bar ||= :foo
                                  end
                                end

                                Bad:

                                class Foo
                                  def go_foo!
                                    @bar = :foo
                                  end
                                
                                  def foo?
                                    @bar == :foo
                                  end
                                end

                                Example

                                Running Reek on:

                                class Dummy
                                  def test
                                    @ivar
                                  end
                                end

                                would report:

                                [1]:InstanceVariableAssumption: Dummy assumes too much for instance variable @ivar

                                Note that this example would trigger this smell warning as well:

                                class Parent
                                  def initialize(omg)
                                    @omg = omg
                                  end
                                end
                                
                                class Child < Parent
                                  def foo
                                    @omg
                                  end
                                end

                                The way to address the smell warning is that you should create an attr_reader to use @omg in the subclass and not access @omg directly like this:

                                class Parent
                                  attr_reader :omg
                                
                                  def initialize(omg)
                                    @omg = omg
                                  end
                                end
                                
                                class Child < Parent
                                  def foo
                                    omg
                                  end
                                end

                                Directly accessing instance variables is considered a smell because it breaks encapsulation and makes it harder to reason about code.

                                If you don't want to expose those methods as public API just make them private like this:

                                class Parent
                                  def initialize(omg)
                                    @omg = omg
                                  end
                                
                                  private
                                  attr_reader :omg
                                end
                                
                                class Child < Parent
                                  def foo
                                    omg
                                  end
                                end

                                Current Support in Reek

                                An instance variable must:

                                • be set in the constructor
                                • or be accessed through a method with lazy initialization / memoization.

                                If not, Instance Variable Assumption will be reported.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["image"]' 3 times
                                Open

                                                if tour_stop["payload"]["image"].present? && tour_stop["payload"]["image"]["uri"].present?
                                                  image = set_defaults_and_types(tour_stop["payload"]["image"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["tour_stops"]' 2 times
                                Open

                                      if @tour_params["tour_stops"].present?
                                        tour_stops = []
                                        @tour_params["tour_stops"].each do |_key, tour_stop|
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["web_urls"]' 2 times
                                Open

                                      if @tour_params["web_urls"].present?
                                        web_urls = []
                                        @tour_params["web_urls"].each do |_key, url|
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'scene["downloadable_uris"]' 3 times
                                Open

                                                if scene["downloadable_uris"].present?
                                                  downloadable_uris = []
                                
                                                  scene["downloadable_uris"].each do |_key, downloadable_uri|
                                                    next if downloadable_uri.blank?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["intensity"]' 3 times
                                Open

                                      entry["intensity"] = entry["intensity"].presence || "1000" if entry.keys.include?("intensity")
                                
                                      # converts to float
                                      entry["min_distance"] = entry["min_distance"].to_f if entry["min_distance"].present?
                                      entry["max_distance"] = entry["max_distance"].to_f if entry["max_distance"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls '@tour_params["media_contents"]' 2 times
                                Open

                                      if @tour_params["media_contents"].present?
                                        media_contents = []
                                        @tour_params["media_contents"].each do |_key, media_content|
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'spot["position"]' 2 times
                                Open

                                                  spot["position"] = if spot["position"].present?
                                                                       JSON.parse(spot["position"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#convert_params_for_graphql calls 'tour_stop["payload"]["scenes"]' 2 times
                                Open

                                            if tour_stop["payload"]["scenes"].present?
                                              scenes = []
                                              total_size_calculated_from_downloadable_uris = 0
                                
                                              tour_stop["payload"]["scenes"].each do |_key, scene|
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#set_defaults_and_types calls 'entry["position"]' 2 times
                                Open

                                        entry["position"] = if entry["position"].present?
                                                              JSON.parse(entry["position"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                Duplication occurs when two fragments of code look nearly identical, or when two fragments of code have nearly identical effects at some conceptual level.

                                Reek implements a check for Duplicate Method Call.

                                Example

                                Here's a very much simplified and contrived example. The following method will report a warning:

                                def double_thing()
                                  @other.thing + @other.thing
                                end

                                One quick approach to silence Reek would be to refactor the code thus:

                                def double_thing()
                                  thing = @other.thing
                                  thing + thing
                                end

                                A slightly different approach would be to replace all calls of double_thing by calls to @other.double_thing:

                                class Other
                                  def double_thing()
                                    thing + thing
                                  end
                                end

                                The approach you take will depend on balancing other factors in your code.

                                ToursController#new_tour doesn't depend on instance state (maybe move it to another class?)
                                Open

                                    def new_tour
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                A Utility Function is any instance method that has no dependency on the state of the instance.

                                ToursController#set_defaults_and_types doesn't depend on instance state (maybe move it to another class?)
                                Open

                                    def set_defaults_and_types(entry)
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                A Utility Function is any instance method that has no dependency on the state of the instance.

                                ToursController#convert_params_for_graphql has the variable name 'mp3'
                                Open

                                                  mp3 = set_defaults_and_types(tour_stop["payload"]["mp3"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

                                Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

                                ToursController#convert_params_for_graphql has the variable name 'mp4'
                                Open

                                                  mp4 = set_defaults_and_types(tour_stop["payload"]["mp4"])
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

                                Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

                                ToursController#update has the variable name 'e'
                                Open

                                    rescue Graphlient::Errors::GraphQLError => e
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

                                Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

                                ToursController#create has the variable name 'e'
                                Open

                                    rescue Graphlient::Errors::GraphQLError => e
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by reek

                                An Uncommunicative Variable Name is a variable name that doesn't communicate its intent well enough.

                                Poor names make it hard for the reader to build a mental picture of what's going on in the code. They can also be mis-interpreted; and they hurt the flow of reading, because the reader must slow down to interpret the names.

                                Avoid more than 3 levels of block nesting.
                                Open

                                              if scenes.count.positive?
                                                # add target, mp3, mp4, image, light, quad and spot to the first scene
                                                # if there is a start date and time period in days, otherwise add them to the last
                                                # scene in order to have them at the correct place in the object for the mobile app
                                                scene = scenes.last
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop checks for excessive nesting of conditional and looping constructs.

                                You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                                The maximum level of nesting allowed is configurable.

                                Avoid more than 3 levels of block nesting.
                                Open

                                                next if scene.blank?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop checks for excessive nesting of conditional and looping constructs.

                                You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                                The maximum level of nesting allowed is configurable.

                                Avoid more than 3 levels of block nesting.
                                Open

                                                if scene["downloadable_uris"].present?
                                                  downloadable_uris = []
                                
                                                  scene["downloadable_uris"].each do |_key, downloadable_uri|
                                                    next if downloadable_uri.blank?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop checks for excessive nesting of conditional and looping constructs.

                                You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                                The maximum level of nesting allowed is configurable.

                                Avoid more than 3 levels of block nesting.
                                Open

                                              if tour_stop["payload"]["time_period_in_days"].present?
                                                tour_stop["payload"]["time_period_in_days"] = tour_stop["payload"]["time_period_in_days"].to_i
                                              end
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop checks for excessive nesting of conditional and looping constructs.

                                You can configure if blocks are considered using the CountBlocks option. When set to false (the default) blocks are not counted towards the nesting level. Set to true to count blocks as well.

                                The maximum level of nesting allowed is configurable.

                                Similar blocks of code found in 7 locations. Consider refactoring.
                                Open

                                  def create
                                    query = create_or_update_mutation
                                    begin
                                      results = @smart_village.query query
                                    rescue Graphlient::Errors::GraphQLError => e
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 6 other locations - About 50 mins to fix
                                app/controllers/constructions_controller.rb on lines 90..102
                                app/controllers/events_controller.rb on lines 208..220
                                app/controllers/jobs_controller.rb on lines 117..129
                                app/controllers/offers_controller.rb on lines 102..114
                                app/controllers/point_of_interests_controller.rb on lines 172..184
                                app/controllers/surveys_controller.rb on lines 48..60

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 42.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 4 locations. Consider refactoring.
                                Open

                                                if tour_stop["payload"]["target"].present? && tour_stop["payload"]["target"]["uri"].present?
                                                  target = set_defaults_and_types(tour_stop["payload"]["target"])
                                                  target["id"] = "-1"
                                
                                                  scene_downloadable_uris.unshift(target)
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 3 other locations - About 40 mins to fix
                                app/controllers/tours_controller.rb on lines 360..366
                                app/controllers/tours_controller.rb on lines 367..373
                                app/controllers/tours_controller.rb on lines 374..380

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 38.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 4 locations. Consider refactoring.
                                Open

                                                if tour_stop["payload"]["mp3"].present? && tour_stop["payload"]["mp3"]["uri"].present?
                                                  mp3 = set_defaults_and_types(tour_stop["payload"]["mp3"])
                                                  mp3["id"] = "-2"
                                
                                                  scene_downloadable_uris.unshift(mp3)
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 3 other locations - About 40 mins to fix
                                app/controllers/tours_controller.rb on lines 353..359
                                app/controllers/tours_controller.rb on lines 367..373
                                app/controllers/tours_controller.rb on lines 374..380

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 38.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 4 locations. Consider refactoring.
                                Open

                                                if tour_stop["payload"]["image"].present? && tour_stop["payload"]["image"]["uri"].present?
                                                  image = set_defaults_and_types(tour_stop["payload"]["image"])
                                                  image["id"] = "-4"
                                
                                                  scene_downloadable_uris.unshift(image)
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 3 other locations - About 40 mins to fix
                                app/controllers/tours_controller.rb on lines 353..359
                                app/controllers/tours_controller.rb on lines 360..366
                                app/controllers/tours_controller.rb on lines 367..373

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 38.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 4 locations. Consider refactoring.
                                Open

                                                if tour_stop["payload"]["mp4"].present? && tour_stop["payload"]["mp4"]["uri"].present?
                                                  mp4 = set_defaults_and_types(tour_stop["payload"]["mp4"])
                                                  mp4["id"] = "-3"
                                
                                                  scene_downloadable_uris.unshift(mp4)
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 3 other locations - About 40 mins to fix
                                app/controllers/tours_controller.rb on lines 353..359
                                app/controllers/tours_controller.rb on lines 360..366
                                app/controllers/tours_controller.rb on lines 374..380

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 38.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 6 locations. Consider refactoring.
                                Open

                                  def destroy
                                    results = @smart_village.query <<~GRAPHQL
                                      mutation {
                                        destroyRecord(
                                          id: #{params["id"]},
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 5 other locations - About 30 mins to fix
                                app/controllers/deadlines_controller.rb on lines 135..154
                                app/controllers/defect_reports_controller.rb on lines 55..74
                                app/controllers/noticeboards_controller.rb on lines 49..68
                                app/controllers/static_contents_controller.rb on lines 74..93
                                app/controllers/surveys_controller.rb on lines 78..97

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 32.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 5 locations. Consider refactoring.
                                Open

                                  def update
                                    tour_id = params[:id]
                                
                                    query = create_or_update_mutation(true)
                                    # logger.warn(query)
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 4 other locations - About 30 mins to fix
                                app/controllers/constructions_controller.rb on lines 105..117
                                app/controllers/jobs_controller.rb on lines 132..144
                                app/controllers/offers_controller.rb on lines 117..129
                                app/controllers/point_of_interests_controller.rb on lines 187..199

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 32.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 2 locations. Consider refactoring.
                                Open

                                      if @tour_params["media_contents"].present?
                                        media_contents = []
                                        @tour_params["media_contents"].each do |_key, media_content|
                                          next if media_content.blank?
                                
                                
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb and 1 other location - About 30 mins to fix
                                app/controllers/point_of_interests_controller.rb on lines 307..314

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 32.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 7 locations. Consider refactoring.
                                Open

                                  def edit
                                    results = @smart_village.query <<~GRAPHQL
                                      query {
                                        tour(
                                          id: #{params[:id]}
                                Severity: Major
                                Found in app/controllers/tours_controller.rb and 6 other locations - About 20 mins to fix
                                app/controllers/constructions_controller.rb on lines 40..87
                                app/controllers/deadlines_controller.rb on lines 42..100
                                app/controllers/events_controller.rb on lines 45..205
                                app/controllers/jobs_controller.rb on lines 40..114
                                app/controllers/offers_controller.rb on lines 38..99
                                app/controllers/point_of_interests_controller.rb on lines 40..169

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 28.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 7 locations. Consider refactoring.
                                Open

                                      if @tour_params["categories"].present?
                                        categories = []
                                        @tour_params["categories"].each do |_key, category|
                                          next if category.blank?
                                
                                
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb and 6 other locations - About 15 mins to fix
                                app/controllers/constructions_controller.rb on lines 165..172
                                app/controllers/deadlines_controller.rb on lines 199..206
                                app/controllers/events_controller.rb on lines 398..405
                                app/controllers/point_of_interests_controller.rb on lines 283..290
                                app/controllers/point_of_interests_controller.rb on lines 318..325
                                app/controllers/tours_controller.rb on lines 269..276

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 26.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Similar blocks of code found in 7 locations. Consider refactoring.
                                Open

                                      if @tour_params["web_urls"].present?
                                        web_urls = []
                                        @tour_params["web_urls"].each do |_key, url|
                                          next if url.blank?
                                
                                
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb and 6 other locations - About 15 mins to fix
                                app/controllers/constructions_controller.rb on lines 165..172
                                app/controllers/deadlines_controller.rb on lines 199..206
                                app/controllers/events_controller.rb on lines 398..405
                                app/controllers/point_of_interests_controller.rb on lines 283..290
                                app/controllers/point_of_interests_controller.rb on lines 318..325
                                app/controllers/tours_controller.rb on lines 240..247

                                Duplicated Code

                                Duplicated code can lead to software that is hard to understand and difficult to change. The Don't Repeat Yourself (DRY) principle states:

                                Every piece of knowledge must have a single, unambiguous, authoritative representation within a system.

                                When you violate DRY, bugs and maintenance problems are sure to follow. Duplicated code has a tendency to both continue to replicate and also to diverge (leaving bugs as two similar implementations differ in subtle ways).

                                Tuning

                                This issue has a mass of 26.

                                We set useful threshold defaults for the languages we support but you may want to adjust these settings based on your project guidelines.

                                The threshold configuration represents the minimum mass a code block must have to be analyzed for duplication. The lower the threshold, the more fine-grained the comparison.

                                If the engine is too easily reporting duplication, try raising the threshold. If you suspect that the engine isn't catching enough duplication, try lowering the threshold. The best setting tends to differ from language to language.

                                See codeclimate-duplication's documentation for more information about tuning the mass threshold in your .codeclimate.yml.

                                Refactorings

                                Further Reading

                                Line is too long. [118/100]
                                Open

                                                if tour_stop["payload"]["start_date"].present? && tour_stop["payload"]["time_period_in_days"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Missing top-level class documentation comment.
                                Open

                                class ToursController < ApplicationController
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop checks for missing top-level documentation of classes and modules. Classes with no body are exempt from the check and so are namespace modules - modules that have nothing in their bodies except classes, other modules, or constant definitions.

                                The documentation requirement is annulled if the class or module has a "#:nodoc:" comment next to it. Likewise, "#:nodoc: all" does the same for all its children.

                                Example:

                                # bad
                                class Person
                                  # ...
                                end
                                
                                # good
                                # Description/Explanation of Person class
                                class Person
                                  # ...
                                end

                                Line is too long. [106/100]
                                Open

                                                if tour_stop["payload"]["image"].present? && tour_stop["payload"]["image"]["uri"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Do not prefix writer method names with set_.
                                Open

                                    def set_defaults_and_types(entry)
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop makes sure that accessor methods are named properly.

                                Example:

                                # bad
                                def set_attribute(value)
                                end
                                
                                # good
                                def attribute=(value)
                                end
                                
                                # bad
                                def get_attribute
                                end
                                
                                # good
                                def attribute
                                end

                                Line is too long. [110/100]
                                Open

                                                tour_stop["payload"]["time_period_in_days"] = tour_stop["payload"]["time_period_in_days"].to_i
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Use a guard clause instead of wrapping the code inside a conditional expression.
                                Open

                                      if @tour_params["tour_stops"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Use a guard clause instead of wrapping the code inside a conditional expression

                                Example:

                                # bad
                                def test
                                  if something
                                    work
                                  end
                                end
                                
                                # good
                                def test
                                  return unless something
                                  work
                                end
                                
                                # also good
                                def test
                                  work if something
                                end
                                
                                # bad
                                if something
                                  raise 'exception'
                                else
                                  ok
                                end
                                
                                # good
                                raise 'exception' if something
                                ok

                                Line is too long. [102/100]
                                Open

                                                if tour_stop["payload"]["mp3"].present? && tour_stop["payload"]["mp3"]["uri"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Line is too long. [102/100]
                                Open

                                                if tour_stop["payload"]["mp4"].present? && tour_stop["payload"]["mp4"]["uri"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Line is too long. [108/100]
                                Open

                                                if tour_stop["payload"]["target"].present? && tour_stop["payload"]["target"]["uri"].present?
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                Use %i or %I for an array of symbols.
                                Wontfix

                                  before_action :load_category_list, only: [:edit, :new, :create]
                                Severity: Minor
                                Found in app/controllers/tours_controller.rb by rubocop

                                This cop can check for array literals made up of symbols that are not using the %i() syntax.

                                Alternatively, it checks for symbol arrays using the %i() syntax on projects which do not want to use that syntax.

                                Configuration option: MinSize If set, arrays with fewer elements than this value will not trigger the cop. For example, a MinSize of3` will not enforce a style on an array of 2 or fewer elements.

                                Example: EnforcedStyle: percent (default)

                                # good
                                %i[foo bar baz]
                                
                                # bad
                                [:foo, :bar, :baz]

                                Example: EnforcedStyle: brackets

                                # good
                                [:foo, :bar, :baz]
                                
                                # bad
                                %i[foo bar baz]

                                There are no issues that match your filters.

                                Category
                                Status