ikuseiGmbH/smart-village-app-cms

View on GitHub

Showing 1,158 of 1,254 total issues

File events_controller.rb has 371 lines of code (exceeds 250 allowed). Consider refactoring.
Open

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

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

      def index
        results = @smart_village.query <<~GRAPHQL
          query {
            genericItems(genericType: "Noticeboard") {
              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.

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

      def create
        if params[:email].present? && params[:password].present?
          @current_user = User.new(email: params[:email], password: params[:password])
          @current_user.sign_in
          if @current_user.valid?

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

        def convert_params_for_graphql
          # Convert has_many categories
          if @deadline_params["categories"].present?
            categories = []
            @deadline_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 perform has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
    Open

      def perform
        @tour_data.each do |tour_data_line|
          @waste_types.each do |waste_type_key, _waste_type|
            next if @tour_assignment[waste_type_key].blank?
            next if @address_assignment[waste_type_key].blank?
    Severity: Minor
    Found in app/services/importer/waste_calendar.rb - About 4 hrs to fix

    Cognitive Complexity

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

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

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

    Further reading

    Function onInsert has 117 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        'onInsert': function (evt, node) {
          var $nodeid = $(node.el).find('#' + escapeSelector(node.id));
          var boundaries = node.getArrayBoundaries();
    
          var moveNodeTo = function (fromIdx, toIdx) {
    Severity: Major
    Found in lib/jsonform.js - About 4 hrs to fix

      Complex method OffersController#convert_params_for_graphql (71.3)
      Open

          def convert_params_for_graphql
            # Convert has_many content_blocks(which has_many media_contents)
            content_block_params = @offer_params["content_blocks"]
            return unless content_block_params.present?
      
      
      Severity: Minor
      Found in app/controllers/offers_controller.rb by flog

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

      You can read more about ABC metrics or the flog tool

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

          def convert_params_for_graphql
            # Convert has_many categories
            if @deadline_params["categories"].present?
              categories = []
              @deadline_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.

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

          def convert_params_for_graphql
            # Convert has_many categories
            if @news_item_params["categories"].present?
              categories = []
              @news_item_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.

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

          def convert_params_for_graphql
            # Convert has_many categories
            if @event_params["categories"].present?
              categories = []
              @event_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.

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

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

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

            def convert_params_for_graphql
              # Convert has_many categories
              if @event_params["categories"].present?
                categories = []
                @event_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

        Assignment Branch Condition size for edit_survey_record is too high. [34.06/15]
        Open

            def edit_survey_record
              results = @smart_village.query <<~GRAPHQL
                query {
                  surveys(
                    ids: [

        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.

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

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

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

        Example:

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

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

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

        Cognitive Complexity

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

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

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

        Further reading

        Complex method SessionController#create (60.4)
        Open

          def create
            if params[:email].present? && params[:password].present?
              @current_user = User.new(email: params[:email], password: params[:password])
              @current_user.sign_in
              if @current_user.valid?
        Severity: Minor
        Found in app/controllers/session_controller.rb by flog

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

        You can read more about ABC metrics or the flog tool

        Assignment Branch Condition size for verify_user is too high. [32.94/15]
        Open

          def verify_user
            result = validate_support_id
            if result && result.code == "200" && result.body.present?
              encounter_server = SmartVillageApi.encounter_server_url
              uri = Addressable::URI.parse("#{encounter_server}/v1/support/verify_user.json")

        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.

        Function onInsert has 91 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            'onInsert': function (evt, node) {
              var $nodeid = $(node.el).find('#' + escapeSelector(node.id));
              var boundaries = node.getArrayBoundaries();
        
              // Switch two nodes in an array
        Severity: Major
        Found in lib/jsonform.js - About 3 hrs to fix

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

            def edit
              results = @smart_village.query <<~GRAPHQL
                query {
                  newsItem(
                    id: #{params[:id]}
          Severity: Major
          Found in app/controllers/news_items_controller.rb - About 3 hrs to fix
            Severity
            Category
            Status
            Source
            Language