bborn/communityengine

View on GitHub

Showing 147 of 147 total issues

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

  def update
    @album = Album.find(params[:id])

    respond_to do |format|
      if @album.update_attributes(album_params)
Severity: Minor
Found in app/controllers/albums_controller.rb - About 35 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 create has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    @topic = Topic.includes(:forum).where(:id => params[:topic_id].to_i, :forum_id => params[:forum_id].to_i).first
    if @topic.locked?
      respond_to do |format|
        format.html do
Severity: Minor
Found in app/controllers/sb_posts_controller.rb - About 35 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 delete_message_threads has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
Open

  def delete_message_threads
    if request.post?
      if params[:delete]
        params[:delete].each { |id|
          message_thread = MessageThread.find_by_id_and_recipient_id(id, @user.id)
Severity: Minor
Found in app/controllers/messages_controller.rb - About 35 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 too many return statements within this function.
Open

        return type.min > value ? type.min : type.max < value ? type.max : value;
Severity: Major
Found in app/assets/javascripts/jcrop/jquery.color.js - About 30 mins to fix

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

      def create
        commentable_type = get_commentable_type(params[:commentable_type])
        @commentable = commentable_type.singularize.constantize.find(params[:commentable_id])
    
        @comment = @commentable.comments.new(comment_params)
    Severity: Minor
    Found in app/controllers/comments_controller.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

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

      def set_locale
        if Rails.env.eql?('test')
          configatron.community_locale = 'en'
        end
        # Get the current path and request method (useful in the layout for changing the language)
    Severity: Minor
    Found in lib/community_engine/localized_application.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

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

      def recent_forum_activity(forum)
        return false unless logged_in? && forum.topics.first
        return false unless last_active || session[:forums]
         
        return forum.topics.order("replied_at desc").first.replied_at > (last_active || session[:forums][forum.id])
    Severity: Minor
    Found in app/helpers/forums_helper.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

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

      def should_notify_recipient?
        return false unless recipient && recipient.email
        return false if recipient.eql?(user)
        return false unless recipient.notify_comments?
        true
    Severity: Minor
    Found in app/models/comment.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

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

      def self.find_by_user_or_ip_address(favoritable = nil, user = nil, remote_ip = nil)
        return false unless favoritable && (user || remote_ip)
        
        if user
          favorite = self.where("user_id = ? AND favoritable_type = ? AND favoritable_id = ?", user.id, favoritable.class.to_s, favoritable.id).first
    Severity: Minor
    Found in app/models/favorite.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

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

      def self.find_or_create_from_authorization(auth)
        user = User.where(:email => auth.email).first_or_initialize
        user.login ||= auth.nickname
    
        if user.new_record?
    Severity: Minor
    Found in app/models/user.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

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

        def require_current_user
          @user ||= User.find(params[:user_id] || params[:id] )
          unless admin? || (@user && (@user.eql?(current_user)))
            redirect_to :controller => 'sessions', :action => 'new' and return false
          end
    Severity: Minor
    Found in app/controllers/base_controller.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

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

      def update
        @post = Post.unscoped.find(params[:id])
        @user = @post.user
    
        respond_to do |format|
    Severity: Minor
    Found in app/controllers/posts_controller.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

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

      def commentable_url(comment)
        if comment.recipient && comment.commentable
          if comment.commentable_type != "User"
            polymorphic_url([comment.recipient, comment.commentable])+"#comment-#{comment.id}"
          elsif comment
    Severity: Minor
    Found in app/helpers/base_helper.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

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

      def load_images_from_uri
        uri = URI.parse(params[:uri])
        begin
          doc = Nokogiri::HTML( open( uri ) )
        rescue
    Severity: Minor
    Found in app/controllers/clippings_controller.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

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

      def create_friendship_with_inviter(user, options = {})
        unless options[:inviter_code].blank? or options[:inviter_id].blank?
          friend = User.find(options[:inviter_id])
    
          if friend && friend.valid_invite_code?(options[:inviter_code])
    Severity: Minor
    Found in app/controllers/users_controller.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

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

      def destroy
        authorize @post
    
        @post.destroy
        flash[:notice] = :sb_post_was_deleted.l_with_args(:title => CGI::escapeHTML(@post.topic.title))
    Severity: Minor
    Found in app/controllers/sb_posts_controller.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

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

      def send_to_friend
        unless params[:emails]
          render :partial => 'posts/send_to_friend', :locals => {:user_id => params[:user_id], :post_id => params[:post_id]} and return
        end
        @post = Post.find(params[:id])
    Severity: Minor
    Found in app/controllers/posts_controller.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

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

      def avatar_photo_url(size = :original)
        if avatar_id
          avatar.photo.url(size)
        elsif facebook?
          facebook_authorization.picture_url
    Severity: Minor
    Found in app/models/user.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

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

      def crop_profile_photo
        unless @photo = @user.avatar
          flash[:notice] = :no_profile_photo.l
          redirect_to upload_profile_photo_user_path(@user) and return
        end
    Severity: Minor
    Found in app/controllers/users_controller.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

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

        respond_to do |format|
          format.html { redirect_to users_url }
          format.js   {
            render :inline => flash[:error], :status => 500 if flash[:error]
            render if flash[:notice]
    Severity: Minor
    Found in app/controllers/users_controller.rb and 1 other location - About 25 mins to fix
    app/controllers/comments_controller.rb on lines 131..135

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

    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