davidcelis/recommendable

View on GitHub

Showing 20 of 20 total issues

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

  module Rater
    module Disliker
      # Dislike an object. This will remove the item from a user's set of likes
      # or hidden items
      #
Severity: Major
Found in lib/recommendable/rater/disliker.rb and 1 other location - About 6 hrs to fix
lib/recommendable/rater/liker.rb on lines 2..111

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

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

  module Rater
    module Liker
      # Like an object. This will remove the item from a user's set of dislikes,
      # or hidden items.
      #
Severity: Major
Found in lib/recommendable/rater/liker.rb and 1 other location - About 6 hrs to fix
lib/recommendable/rater/disliker.rb on lines 2..111

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

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

Method recommends has 96 lines of code (exceeds 25 allowed). Consider refactoring.
Open

      def recommends(*things)
        Recommendable.configure do |config|
          config.ratable_classes = []
          config.user_class      = self
        end
Severity: Major
Found in lib/recommendable/rater.rb - About 3 hrs to fix

    Method method_missing has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
    Open

              def method_missing(method, *args, &block)
                if method.to_s =~ /\A((?:dis)?liked|hidden|bookmarked)_(.+)_in_common_with\z/
                  begin
                    send("#{$1}_in_common_with", $2.classify.constantize, *args)
                  rescue NameError
    Severity: Minor
    Found in lib/recommendable/rater.rb - About 2 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 make_recommendable! has 53 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

          def make_recommendable!
            Recommendable.configure { |config| config.ratable_classes << self }
    
            class_eval do
              include Likable
    Severity: Major
    Found in lib/recommendable/ratable.rb - About 2 hrs to fix

      Method update_recommendations_for has 38 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

              def update_recommendations_for(user_id)
                user_id = user_id.to_s
      
                nearest_neighbors = Recommendable.config.nearest_neighbors || Recommendable.config.user_class.count
                Recommendable.config.ratable_classes.each do |klass|
      Severity: Minor
      Found in lib/recommendable/helpers/calculations.rb - About 1 hr to fix

        Method update_similarities_for has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def update_similarities_for(user_id)
                  user_id = user_id.to_s # For comparison. Redis returns all set members as strings.
                  similarity_set = Recommendable::Helpers::RedisKeyMapper.similarity_set_for(user_id)
        
                  # Only calculate similarities for users who have rated the items that
        Severity: Minor
        Found in lib/recommendable/helpers/calculations.rb - About 1 hr to fix

          Method respond_to? has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                    def respond_to?(method, include_private = false)
                      if method.to_s =~ /\A((?:dis)?liked|hidden|bookmarked)_(.+)_in_common_with\z/ ||
                         method.to_s =~ /\A((?:dis)?liked|hidden|bookmarked)_(.+)_ids\z/ ||
                         method.to_s =~ /\A((?:dis)?liked|hidden|bookmarked|recommended)_(.+)\z/
                        begin
          Severity: Minor
          Found in lib/recommendable/rater.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

          Method recommends has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

                def recommends(*things)
                  Recommendable.configure do |config|
                    config.ratable_classes = []
                    config.user_class      = self
                  end
          Severity: Minor
          Found in lib/recommendable/rater.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

          Method enqueue has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              def enqueue(user_id)
                user_id = user_id.id if user_id.is_a?(Recommendable.config.user_class)
                user_id = user_id.to_s
          
                if defined?(::Sidekiq)
          Severity: Minor
          Found in lib/recommendable.rb - About 55 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

          Method update_similarities_for has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

                  def update_similarities_for(user_id)
                    user_id = user_id.to_s # For comparison. Redis returns all set members as strings.
                    similarity_set = Recommendable::Helpers::RedisKeyMapper.similarity_set_for(user_id)
          
                    # Only calculate similarities for users who have rated the items that
          Severity: Minor
          Found in lib/recommendable/helpers/calculations.rb - About 55 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

          Avoid deeply nested control flow statements.
          Open

                        rescue NameError
                          super
          Severity: Major
          Found in lib/recommendable/rater.rb - About 45 mins to fix

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

                      when defined?(ActiveRecord::Base)            && ancestors.include?(ActiveRecord::Base),
                           defined?(Mongoid::Document)             && ancestors.include?(Mongoid::Document),
                           defined?(MongoMapper::Document)         && ancestors.include?(MongoMapper::Document),
                           defined?(MongoMapper::EmbeddedDocument) && ancestors.include?(MongoMapper::EmbeddedDocument)
                        before_destroy :remove_from_recommendable!
            Severity: Minor
            Found in lib/recommendable/rater.rb and 1 other location - About 35 mins to fix
            lib/recommendable/ratable.rb on lines 21..26

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

            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

                      when defined?(ActiveRecord::Base)            && ancestors.include?(ActiveRecord::Base),
                           defined?(Mongoid::Document)             && ancestors.include?(Mongoid::Document),
                           defined?(MongoMapper::Document)         && ancestors.include?(MongoMapper::Document),
                           defined?(MongoMapper::EmbeddedDocument) && ancestors.include?(MongoMapper::EmbeddedDocument)
                        before_destroy :remove_from_recommendable!
            Severity: Minor
            Found in lib/recommendable/ratable.rb and 1 other location - About 35 mins to fix
            lib/recommendable/rater.rb on lines 35..40

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

            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

              module Ratable
                module Likable
                  # Fetch a list of users that have liked this item.
                  #
                  # @return [Array] a list of users that have liked this item
            Severity: Minor
            Found in lib/recommendable/ratable/likable.rb and 1 other location - About 35 mins to fix
            lib/recommendable/ratable/dislikable.rb on lines 2..22

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

            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

              module Ratable
                module Dislikable
                  # Fetch a list of users that have disliked this item.
                  #
                  # @return [Array] a list of users that have disliked this item
            Severity: Minor
            Found in lib/recommendable/ratable/dislikable.rb and 1 other location - About 35 mins to fix
            lib/recommendable/ratable/likable.rb on lines 2..22

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

            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

                    Recommendable.redis.pipelined do |redis|
                      sets.each { |set| redis.srem(set, id) }
                      zsets.each { |zset| redis.zrem(zset, id) }
                      redis.del(*keys)
            Severity: Minor
            Found in lib/recommendable/rater/recommender.rb and 1 other location - About 15 mins to fix
            lib/recommendable/ratable.rb on lines 93..96

            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

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

                        Recommendable.redis.pipelined do |redis|
                          sets.each { |set| redis.srem(set, id) }
                          zsets.each { |zset| redis.zrem(zset, id) }
                          redis.del(*keys)
            Severity: Minor
            Found in lib/recommendable/ratable.rb and 1 other location - About 15 mins to fix
            lib/recommendable/rater/recommender.rb on lines 79..82

            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

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

                  def unbookmark(obj)
                    return unless bookmarks?(obj)
            
                    run_hook(:before_unbookmark, obj)
                    Recommendable.redis.srem(Recommendable::Helpers::RedisKeyMapper.bookmarked_set_for(obj.class, id), obj.id)
            Severity: Minor
            Found in lib/recommendable/rater/bookmarker.rb and 1 other location - About 15 mins to fix
            lib/recommendable/rater/hider.rb on lines 33..40

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

            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

                  def unhide(obj)
                    return unless hides?(obj)
            
                    run_hook(:before_unhide, obj)
                    Recommendable.redis.srem(Recommendable::Helpers::RedisKeyMapper.hidden_set_for(obj.class, id), obj.id)
            Severity: Minor
            Found in lib/recommendable/rater/hider.rb and 1 other location - About 15 mins to fix
            lib/recommendable/rater/bookmarker.rb on lines 32..39

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

            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