ikuseiGmbH/smart-village-app-cms

View on GitHub

Showing 1,158 of 1,254 total issues

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

  def sign_in
    auth_server = SmartVillageApi.auth_server_url
    uri = Addressable::URI.parse("#{auth_server}/users/sign_in.json")
    result = ApiRequestService.new(uri.to_s, nil, nil, user_credentials).post_request
    if result.code == "200" && result.body.present?
Severity: Minor
Found in app/models/user.rb by rubocop

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

Perceived complexity for index is too high. [14/7]
Open

  def index
    if helpers.visible_in_role?("role_news_item")
      news_results = @smart_village.query <<~GRAPHQL
        query {
          newsItems {

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

Example:

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

Cyclomatic complexity for convert_params_for_graphql is too high. [13/6]
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 cyclomatic complexity of methods is not higher than the configured maximum. The cyclomatic complexity is the number of linearly independent paths through a method. The algorithm counts decision points and adds one.

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

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

  def post_request
    url = Addressable::URI.parse(@uri.strip).normalize
    http = Net::HTTP.new(url.host, url.port || 80)

    if @uri.include?("https://")
Severity: Minor
Found in app/services/api_request_service.rb by rubocop

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

Function setDefaultValues has 61 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  var setDefaultValues = function (obj, schema, includeOptionalValues, skipFieldsWithoutDefaultValue) {
    if (!obj || !schema) return obj;
    if (!schema.properties) {
      schema = { properties: schema };
    }
Severity: Major
Found in lib/jsonform-defaults.js - About 2 hrs to fix

    Function getArrayBoundaries has 61 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

    formNode.prototype.getArrayBoundaries = function () {
      var boundaries = {
        minItems: -1,
        maxItems: -1
      };
    Severity: Major
    Found in lib/jsonform.js - About 2 hrs to fix

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

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

        Complex method ApiRequestService#get_request (44.4)
        Open

          def get_request(content_type_xml = false, pem = nil)
            uri = Addressable::URI.parse(@uri.strip).normalize
        
            uri.query = [uri.query, URI.encode_www_form(@params)].join("&") if @params&.any?
        
        
        Severity: Minor
        Found in app/services/api_request_service.rb by flog

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

        You can read more about ABC metrics or the flog tool

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

            def edit_static_content_record
              results = @smart_village.query <<~GRAPHQL
                query {
                  staticContent: publicHtmlFile(
                    name: "#{params[:name]}",

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

          def create
            query = create_params
            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.

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

          def create
            unless category_present?(news_item_params)
              flash[:error] = "Bitte eine Kategorie auswählen"
              redirect_to new_news_item_path and return
            end

        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.

        Perceived complexity for convert_params_for_graphql is too high. [13/7]
        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 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 create is too high. [21.75/15]
        Open

          def create
            unless category_present?(news_item_params)
              flash[:error] = "Bitte eine Kategorie auswählen"
              redirect_to new_news_item_path and return
            end

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

            def convert_params_for_graphql
              # Convert date, as we always have and need exactly one
              if @survey_params["dates"].present?
                dates = @survey_params.delete(:dates)
                @survey_params["date"] = dates["0"]

        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.

        Complex method SurveysController#edit_survey_record (44.4)
        Open

            def edit_survey_record
              results = @smart_village.query <<~GRAPHQL
                query {
                  surveys(
                    ids: [
        Severity: Minor
        Found in app/controllers/surveys_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

        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

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

            if (this.parentNode) {
              this.arrayPath = _.clone(this.parentNode.arrayPath);
              if (this.parentNode.view && this.parentNode.view.array) {
                this.arrayPath.push(this.childPos);
              }
          Severity: Major
          Found in lib/jsonform.js and 1 other location - About 2 hrs to fix
          lib/jsonform.js on lines 2110..2118

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

          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

          Severity
          Category
          Status
          Source
          Language