robertgauld/osm

View on GitHub
lib/osm/activity.rb

Summary

Maintainability
D
2 days
Test Coverage

Method get has a Cognitive Complexity of 24 (exceeds 5 allowed). Consider refactoring.
Open

    def self.get(api, activity_id, version=nil, options={})
      cache_key = ['activity', activity_id]

      if !options[:no_cache] && cache_exist?(api, [*cache_key, version])
        activity = cache_read(api, [*cache_key, version])
Severity: Minor
Found in lib/osm/activity.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

Method get has 69 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def self.get(api, activity_id, version=nil, options={})
      cache_key = ['activity', activity_id]

      if !options[:no_cache] && cache_exist?(api, [*cache_key, version])
        activity = cache_read(api, [*cache_key, version])
Severity: Major
Found in lib/osm/activity.rb - About 2 hrs to fix

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

    module Osm
    
      class Activity < Osm::Model
        class Badge; end # Ensure the constant exists for the validators
        class File; end # Ensure the constant exists for the validators
    Severity: Minor
    Found in lib/osm/activity.rb - About 2 hrs to fix

      Method update has 40 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          def update(api, section, secret_update=false)
            raise Osm::ObjectIsInvalid, 'activity is invalid' unless valid?
            raise Osm::Forbidden, "You are not allowed to update this activity" unless self.editable
      
            data = api.perform_query("programme.php?action=update", {
      Severity: Minor
      Found in lib/osm/activity.rb - About 1 hr to fix

        Method update has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
        Open

            def update(api, section, secret_update=false)
              raise Osm::ObjectIsInvalid, 'activity is invalid' unless valid?
              raise Osm::Forbidden, "You are not allowed to update this activity" unless self.editable
        
              data = api.perform_query("programme.php?action=update", {
        Severity: Minor
        Found in lib/osm/activity.rb - About 25 mins 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

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

            class File
              include ActiveModel::MassAssignmentSecurity if ActiveModel::VERSION::MAJOR < 4
              include ActiveAttr::Model
        
              # @!attribute [rw] id
        Severity: Major
        Found in lib/osm/activity.rb and 1 other location - About 2 hrs to fix
        lib/osm/activity.rb on lines 377..412

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

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

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

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

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

        Refactorings

        Further Reading

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

            class Version
              include ActiveModel::MassAssignmentSecurity if ActiveModel::VERSION::MAJOR < 4
              include ActiveAttr::Model
        
              # @!attribute [rw] version
        Severity: Major
        Found in lib/osm/activity.rb and 1 other location - About 2 hrs to fix
        lib/osm/activity.rb on lines 281..316

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

        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

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

                  :badge_type => badge_data['badgetype'].to_sym,
                  :badge_section => badge_data['section'].to_sym,
                  :badge_name => badge_data['badgeLongName'],
                  :badge_id => Osm::to_i_or_nil(badge_data['badge_id']),
                  :badge_version => Osm::to_i_or_nil(badge_data['badge_version']),
        Severity: Minor
        Found in lib/osm/activity.rb and 1 other location - About 45 mins to fix
        lib/osm/meeting.rb on lines 124..131

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

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

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

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

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

        Refactorings

        Further Reading

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

              (data['files'].is_a?(Array) ? data['files'] : []).each do |file_data|
                attributes[:files].push File.new(
                  :id => Osm::to_i_or_nil(file_data['fileid']),
                  :activity_id => Osm::to_i_or_nil(file_data['activityid']),
                  :file_name => file_data['filename'],
        Severity: Minor
        Found in lib/osm/activity.rb and 1 other location - About 45 mins to fix
        lib/osm/activity.rb on lines 171..177

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

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

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

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

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

        Refactorings

        Further Reading

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

              (data['versions'].is_a?(Array) ? data['versions'] : []).each do |version_data|
                attributes[:versions].push Version.new(
                  :version => Osm::to_i_or_nil(version_data['value']),
                  :created_by => Osm::to_i_or_nil(version_data['userid']),
                  :created_by_name => version_data['firstname'],
        Severity: Minor
        Found in lib/osm/activity.rb and 1 other location - About 45 mins to fix
        lib/osm/activity.rb on lines 151..157

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

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

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

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

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

        Refactorings

        Further Reading

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

            if ActiveModel::VERSION::MAJOR < 4
              attr_accessible :id, :version, :group_id, :user_id, :title, :description,
                              :resources, :instructions, :running_time, :location,
                              :shared, :rating, :editable, :deletable, :used, :versions,
                              :sections, :tags, :files, :badges
        Severity: Minor
        Found in lib/osm/activity.rb and 1 other location - About 20 mins to fix
        lib/osm/badge.rb on lines 69..71

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

        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

        There are no issues that match your filters.

        Category
        Status