ikuseiGmbH/smart-village-app-cms

View on GitHub
app/controllers/constructions_controller.rb

Summary

Maintainability
D
2 days
Test Coverage

Parameters should be whitelisted for mass assignment
Open

      params.require(:construction).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.

Class has too many lines. [199/100]
Open

class ConstructionsController < ApplicationController
  before_action :verify_current_user
  before_action { verify_current_user_role("role_construction_site") }
  before_action :init_graphql_client
  before_action :load_category_list, only: [:edit, :new, :create]

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

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

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|
Severity: Minor
Found in app/controllers/constructions_controller.rb - About 1 day to fix

Cognitive Complexity

Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

A method's cognitive complexity is based on a few simple rules:

  • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
  • Code is considered more complex for each "break in the linear flow of the code"
  • Code is considered more complex when "flow breaking structures are nested"

Further reading

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

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|

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.

Complex method ConstructionsController#convert_params_for_graphql (104.0)
Open

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|

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 has too many lines. [57/10]
Open

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|

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. [46/10]
Open

  def edit
    results = @smart_village.query <<~GRAPHQL
      query {
        genericItem(
          id: #{params[:id]}

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.

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

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|

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.

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

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|

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 has too many lines. [19/10]
Open

  def index
    results = @smart_village.query <<~GRAPHQL
      query {
        genericItems(genericType: "ConstructionSite") {
          id

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"]},

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 convert_params_for_graphql has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def convert_params_for_graphql
      # Convert has_many categories
      if @construction_params["categories"].present?
        categories = []
        @construction_params["categories"].each do |_key, category|
Severity: Major
Found in app/controllers/constructions_controller.rb - About 2 hrs to fix

    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

    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 edit has 46 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def edit
        results = @smart_village.query <<~GRAPHQL
          query {
            genericItem(
              id: #{params[:id]}
    Severity: Minor
    Found in app/controllers/constructions_controller.rb - About 1 hr to fix

      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

      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.

      ConstructionsController#create_or_update_mutation has boolean parameter 'update'
      Open

          def create_or_update_mutation(update = false)

      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

      ConstructionsController#update has approx 6 statements
      Open

        def update

      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.)

      ConstructionsController#create has approx 10 statements
      Open

        def create

      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.)

      ConstructionsController#convert_params_for_graphql has approx 42 statements
      Open

          def convert_params_for_graphql

      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.)

      ConstructionsController#convert_params_for_graphql calls '@construction_params["locations"]' 2 times
      Open

            if @construction_params["locations"].present?
              geo_locations = []
              @construction_params["locations"].each do |_key, location|

      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.

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

      class ConstructionsController < ApplicationController

      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.

      ConstructionsController#convert_params_for_graphql calls 'location["geo_location"]["longitude"]' 2 times
      Open

                location["geoLocation"]["longitude"] = location["geo_location"]["longitude"].to_f if location["geo_location"]["longitude"].present?

      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.

      ConstructionsController#convert_params_for_graphql calls '@construction_params["payload"]["restrictions"]' 2 times
      Open

            if @construction_params["payload"]["restrictions"].present?
              restrictions = []
              @construction_params["payload"]["restrictions"].each do |_key, value|

      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.

      ConstructionsController has no descriptive comment
      Open

      class ConstructionsController < ApplicationController

      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

      ConstructionsController#convert_params_for_graphql calls '@construction_params["dates"]' 2 times
      Open

            if @construction_params["dates"].present?
              dates = []
              @construction_params["dates"].each do |_key, date|

      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.

      ConstructionsController#convert_params_for_graphql calls 'location["geoLocation"]' 2 times
      Open

                location["geoLocation"]["latitude"] = location["geo_location"]["latitude"].to_f if location["geo_location"]["latitude"].present?
                location["geoLocation"]["longitude"] = location["geo_location"]["longitude"].to_f if location["geo_location"]["longitude"].present?

      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.

      ConstructionsController#convert_params_for_graphql calls '@construction_params["categories"]' 2 times
      Open

            if @construction_params["categories"].present?
              categories = []
              @construction_params["categories"].each do |_key, category|

      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.

      ConstructionsController#convert_params_for_graphql calls 'location["geo_location"]["latitude"]' 2 times
      Open

                location["geoLocation"]["latitude"] = location["geo_location"]["latitude"].to_f if location["geo_location"]["latitude"].present?

      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.

      ConstructionsController#convert_params_for_graphql calls '@construction_params["media_contents"]' 2 times
      Open

            if @construction_params["media_contents"].present?
              media_contents = []
              @construction_params["media_contents"].each do |_key, media_content|

      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.

      ConstructionsController#convert_params_for_graphql calls '@construction_params["payload"]' 3 times
      Open

            if @construction_params["payload"]["restrictions"].present?
              restrictions = []
              @construction_params["payload"]["restrictions"].each do |_key, value|
                next if value.blank?
                next if value["description"].blank?

      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.

      ConstructionsController#convert_params_for_graphql calls 'location["geo_location"]' 5 times
      Open

                next if location["geo_location"].blank?
      
                location["geoLocation"] = {}
                location["geoLocation"]["latitude"] = location["geo_location"]["latitude"].to_f if location["geo_location"]["latitude"].present?
                location["geoLocation"]["longitude"] = location["geo_location"]["longitude"].to_f if location["geo_location"]["longitude"].present?

      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.

      ConstructionsController assumes too much for instance variable '@construction_params'
      Open

      class ConstructionsController < ApplicationController

      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.

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

          def new_generic_item

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

      ConstructionsController#update has the variable name 'e'
      Open

          rescue Graphlient::Errors::GraphQLError => e

      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.

      ConstructionsController#create has the variable name 'e'
      Open

          rescue Graphlient::Errors::GraphQLError => e

      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.

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

            if @construction_params["media_contents"].present?
              media_contents = []
              @construction_params["media_contents"].each do |_key, media_content|
                next if media_content.blank?
                # content_type is always something (default: `image`), so we need to check all values
      Severity: Major
      Found in app/controllers/constructions_controller.rb and 4 other locations - About 1 hr to fix
      app/controllers/deadlines_controller.rb on lines 223..234
      app/controllers/events_controller.rb on lines 371..382
      app/controllers/jobs_controller.rb on lines 236..247
      app/controllers/offers_controller.rb on lines 208..219

      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 48.

      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 create
          query = create_or_update_mutation
          begin
            results = @smart_village.query query
          rescue Graphlient::Errors::GraphQLError => e
      Severity: Major
      Found in app/controllers/constructions_controller.rb and 6 other locations - About 50 mins to fix
      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
      app/controllers/tours_controller.rb on lines 149..161

      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 6 locations. Consider refactoring.
      Open

        def destroy
          results = @smart_village.query <<~GRAPHQL
            mutation {
              destroyRecord(
                id: #{params["id"]},
      Severity: Major
      Found in app/controllers/constructions_controller.rb and 5 other locations - About 35 mins to fix
      app/controllers/events_controller.rb on lines 239..258
      app/controllers/jobs_controller.rb on lines 147..166
      app/controllers/news_items_controller.rb on lines 175..194
      app/controllers/offers_controller.rb on lines 132..151
      app/controllers/point_of_interests_controller.rb on lines 202..221

      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 35.

      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 11 locations. Consider refactoring.
      Open

            if @construction_params["dates"].present?
              dates = []
              @construction_params["dates"].each do |_key, date|
                next if date.blank?
                next unless nested_values?(date.to_h).include?(true)
      Severity: Major
      Found in app/controllers/constructions_controller.rb and 10 other locations - About 30 mins to fix
      app/controllers/deadlines_controller.rb on lines 238..246
      app/controllers/events_controller.rb on lines 320..328
      app/controllers/events_controller.rb on lines 332..340
      app/controllers/events_controller.rb on lines 359..367
      app/controllers/events_controller.rb on lines 386..394
      app/controllers/jobs_controller.rb on lines 198..206
      app/controllers/jobs_controller.rb on lines 251..259
      app/controllers/news_items_controller.rb on lines 219..227
      app/controllers/offers_controller.rb on lines 223..231
      app/controllers/surveys_controller.rb on lines 191..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 33.

      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
          construction_id = params[:id]
      
          query = create_or_update_mutation(true)
          # logger.warn(query)
      Severity: Major
      Found in app/controllers/constructions_controller.rb and 4 other locations - About 30 mins to fix
      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
      app/controllers/tours_controller.rb on lines 164..176

      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 {
              genericItem(
                id: #{params[:id]}
      Severity: Major
      Found in app/controllers/constructions_controller.rb and 6 other locations - About 20 mins to fix
      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
      app/controllers/tours_controller.rb on lines 40..146

      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 @construction_params["categories"].present?
              categories = []
              @construction_params["categories"].each do |_key, category|
                next if category.blank?
      
      
      Severity: Minor
      Found in app/controllers/constructions_controller.rb and 6 other locations - About 15 mins to fix
      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
      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

      Missing top-level class documentation comment.
      Open

      class ConstructionsController < ApplicationController

      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. [138/100]
      Open

                location["geoLocation"]["latitude"] = location["geo_location"]["latitude"].to_f if location["geo_location"]["latitude"].present?

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

        before_action :load_category_list, only: [:edit, :new, :create]

      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]

      Line is too long. [141/100]
      Open

                location["geoLocation"]["longitude"] = location["geo_location"]["longitude"].to_f if location["geo_location"]["longitude"].present?

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

            if @construction_params["dates"].present?

      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

      Use the return of the conditional for variable assignment and comparison.
      Open

          if results.try(:data).try(:destroy_record).try(:status_code) == 200
            flash["notice"] = "Eintrag wurde gelöscht"
          else
            flash["notice"] = "Fehler: #{results.errors.inspect}"
          end

      Line is too long. [123/100]
      Open

                media_content["source_url"] = media_content.dig("source_url", "url").present? ? media_content["source_url"] : nil

      There are no issues that match your filters.

      Category
      Status