ikuseiGmbH/smart-village-app-cms

View on GitHub
app/controllers/waste_calendar_controller.rb

Summary

Maintainability
C
7 hrs
Test Coverage

Parameters should be whitelisted for mass assignment
Open

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

Parameters should be whitelisted for mass assignment
Open

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

Parameters should be whitelisted for mass assignment
Open

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

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

class WasteCalendarController < ApplicationController
  before_action :verify_current_user
  before_action { verify_current_user_role("role_waste_calendar") }
  before_action :init_graphql_client
  before_action :determine_waste_types, only: %i[index new edit_tour edit_location tour_dates]

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

  def create
    results = @smart_village.query <<~GRAPHQL
      query {
        publicJsonFile(name: "wasteTypes", version: "1.0.0") {
          content

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. [38.64/15]
Open

  def create
    results = @smart_village.query <<~GRAPHQL
      query {
        publicJsonFile(name: "wasteTypes", version: "1.0.0") {
          content

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

  def index
    # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers
    # Rails.cache.delete("waste_locations")

    latest = 9_999_999_999 # very high number to always match the latest version

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 tour_dates is too high. [25.38/15]
Open

  def tour_dates
    @edit_year = (params[:year].presence || Date.today.year).to_i
    @beginning_of_year = Date.strptime(@edit_year.to_s, "%Y").beginning_of_year
    @end_of_year = Date.strptime(@edit_year.to_s, "%Y").end_of_year

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 WasteCalendarController#create (46.1)
Open

  def create
    results = @smart_village.query <<~GRAPHQL
      query {
        publicJsonFile(name: "wasteTypes", version: "1.0.0") {
          content

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

  def tour_dates
    @edit_year = (params[:year].presence || Date.today.year).to_i
    @beginning_of_year = Date.strptime(@edit_year.to_s, "%Y").beginning_of_year
    @end_of_year = Date.strptime(@edit_year.to_s, "%Y").end_of_year

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

    def determine_waste_locations
      # Read from cache
      # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers
      # if Rails.cache.exist?("waste_locations")
      #   @waste_locations = Rails.cache.read("waste_locations")

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

  def edit_location
    @edit_location_id = params[:location_id]
    results = @smart_village.query <<~GRAPHQL
      query {
        wasteAddresses(

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.

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

class WasteCalendarController < ApplicationController
  before_action :verify_current_user
  before_action { verify_current_user_role("role_waste_calendar") }
  before_action :init_graphql_client
  before_action :determine_waste_types, only: %i[index new edit_tour edit_location tour_dates]
Severity: Minor
Found in app/controllers/waste_calendar_controller.rb - About 2 hrs to fix

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

      def update_tour_dates
        tour_id = params[:id]
        edit_year = params[:year]
        tour_dates = tour_date_params.select { |_key, value| value == "true" }
    
    

    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 create is too high. [10/6]
    Open

      def create
        results = @smart_village.query <<~GRAPHQL
          query {
            publicJsonFile(name: "wasteTypes", version: "1.0.0") {
              content

    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.

    File waste_calendar_controller.rb has 255 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    require "csv"
    
    class WasteCalendarController < ApplicationController
      before_action :verify_current_user
      before_action { verify_current_user_role("role_waste_calendar") }
    Severity: Minor
    Found in app/controllers/waste_calendar_controller.rb - About 2 hrs to fix

      Perceived complexity for create is too high. [10/7]
      Open

        def create
          results = @smart_village.query <<~GRAPHQL
            query {
              publicJsonFile(name: "wasteTypes", version: "1.0.0") {
                content

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

        def remove_tour
          @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 has too many lines. [13/10]
      Open

        def remove_location
          # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers
          # Rails.cache.delete("waste_locations")
      
          @smart_village.query <<~GRAPHQL

      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 WasteCalendarController#tour_dates (38.7)
      Open

        def tour_dates
          @edit_year = (params[:year].presence || Date.today.year).to_i
          @beginning_of_year = Date.strptime(@edit_year.to_s, "%Y").beginning_of_year
          @end_of_year = Date.strptime(@edit_year.to_s, "%Y").end_of_year
      
      

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

        def create
          results = @smart_village.query <<~GRAPHQL
            query {
              publicJsonFile(name: "wasteTypes", version: "1.0.0") {
                content
      Severity: Minor
      Found in app/controllers/waste_calendar_controller.rb - About 1 hr to fix

        Method create has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
        Open

          def create
            results = @smart_village.query <<~GRAPHQL
              query {
                publicJsonFile(name: "wasteTypes", version: "1.0.0") {
                  content
        Severity: Minor
        Found in app/controllers/waste_calendar_controller.rb - About 1 hr to fix

        Cognitive Complexity

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

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

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

        Further reading

        WasteCalendarController has at least 16 instance variables
        Open

        class WasteCalendarController < ApplicationController

        Too Many Instance Variables is a special case of LargeClass.

        Example

        Given this configuration

        TooManyInstanceVariables:
          max_instance_variables: 3

        and this code:

        class TooManyInstanceVariables
          def initialize
            @arg_1 = :dummy
            @arg_2 = :dummy
            @arg_3 = :dummy
            @arg_4 = :dummy
          end
        end

        Reek would emit the following warning:

        test.rb -- 5 warnings:
          [1]:TooManyInstanceVariables has at least 4 instance variables (TooManyInstanceVariables)

        WasteCalendarController#tour_dates has approx 9 statements
        Open

          def tour_dates

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

        WasteCalendarController#create_street_tour_matrix has approx 7 statements
        Open

          def create_street_tour_matrix

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

        WasteCalendarController has at least 22 methods
        Open

        class WasteCalendarController < ApplicationController

        Too Many Methods is a special case of LargeClass.

        Example

        Given this configuration

        TooManyMethods:
          max_methods: 3

        and this code:

        class TooManyMethods
          def one; end
          def two; end
          def three; end
          def four; end
        end

        Reek would emit the following warning:

        test.rb -- 1 warning:
          [1]:TooManyMethods has at least 4 methods (TooManyMethods)

        WasteCalendarController#update_tour_dates has approx 6 statements
        Open

          def update_tour_dates

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

        WasteCalendarController#create has approx 24 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.)

        WasteCalendarController#create_street_tour_matrix contains iterators nested 2 deep
        Open

              tour_ids.each do |tour_id, tour_value|

        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)

        WasteCalendarController assumes too much for instance variable '@waste_types'
        Open

        class WasteCalendarController < 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.

        WasteCalendarController assumes too much for instance variable '@waste_tours'
        Open

        class WasteCalendarController < 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.

        WasteCalendarController has no descriptive comment
        Open

        class WasteCalendarController < 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

        WasteCalendarController#index calls 'results.data' 2 times
        Open

            @waste_types = results.data.public_json_file.content
        
            results = @smart_village.query <<~GRAPHQL
              query {
                wasteAddresses(limit: 100) {

        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.

        WasteCalendarController assumes too much for instance variable '@edit_location_id'
        Open

        class WasteCalendarController < 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.

        WasteCalendarController assumes too much for instance variable '@address_data'
        Open

        class WasteCalendarController < 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.

        WasteCalendarController#calendarweeks_of_year calls 'last_day.cweek' 2 times
        Open

              if last_day.cweek == 1
                last_day.prev_week.cweek
              else
                last_day.cweek

        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.

        WasteCalendarController#tour_dates calls 'Date.strptime(@edit_year.to_s, "%Y")' 2 times
        Open

            @beginning_of_year = Date.strptime(@edit_year.to_s, "%Y").beginning_of_year
            @end_of_year = Date.strptime(@edit_year.to_s, "%Y").end_of_year

        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.

        WasteCalendarController assumes too much for instance variable '@edit_year'
        Open

        class WasteCalendarController < 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.

        WasteCalendarController#tour_dates calls '@edit_year.to_s' 2 times
        Open

            @beginning_of_year = Date.strptime(@edit_year.to_s, "%Y").beginning_of_year
            @end_of_year = Date.strptime(@edit_year.to_s, "%Y").end_of_year

        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.

        WasteCalendarController assumes too much for instance variable '@tour_data'
        Open

        class WasteCalendarController < 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.

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

        class WasteCalendarController < 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.

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

            def calendarweeks_of_year(year)

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

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

            def value_present(params)

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

        TODO found
        Open

              # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        TODO found
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        TODO found
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        TODO found
        Open

              # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        TODO found
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        TODO found
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Line is too long. [111/100]
        Open

                waste_tour_matrix = { tour_id: tour_id, tour_value: tour_value == "true", address_id: address_id.to_i }

        Line is too long. [104/100]
        Open

          before_action :determine_tour_list, only: %i[new edit_tour edit_location tour_dates update_tour_dates]

        Line is too long. [114/100]
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Line is too long. [114/100]
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Line is too long. [105/100]
        Open

                query = Converter::Base.new.build_mutation("assignWasteLocationToTour", waste_tour_matrix, false)

        Line is too long. [114/100]
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Line is too long. [116/100]
        Open

              # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Line is too long. [114/100]
        Open

            # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Line is too long. [116/100]
        Open

              # TODO: temporarily commented, as we need memcached for this in order to be successful across multiple workers

        Missing top-level class documentation comment.
        Open

        class WasteCalendarController < 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. [117/100]
        Open

            query = Converter::Base.new.build_mutation("createWasteTour", waste_tour_params, waste_tour_params.include?(:id))

        Line is too long. [129/100]
        Open

            query = Converter::Base.new.build_mutation("createWasteLocation", waste_location_params, waste_location_params.include?(:id))

        There are no issues that match your filters.

        Category
        Status