jnaqsh/nerdnews

View on GitHub

Showing 21 of 21 total issues

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

  def create
    session[:authhash] = nil #ensure no one sets it
    omniauth = request.env['omniauth.auth']
    provider = request.env['omniauth.auth']['provider']
    @authhash = Hash.new
Severity: Minor
Found in app/controllers/identities_controller.rb - About 5 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 determine_browser_and_os has a Cognitive Complexity of 22 (exceeds 5 allowed). Consider refactoring.
Open

  def determine_browser_and_os(ua = request.env["HTTP_USER_AGENT"])
    ua = (ua||"").downcase
    br = case ua
      when /opera[\/,\s+](\d+)/
        o = %W(opera opera#{$1})
Severity: Minor
Found in app/helpers/application_helper.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 create has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

  def create
    @story = Story.find(params[:story_id])
    @comment = @story.comments.build(comment_params)
    @comment.user = nil
    @comment.parent_id = comment_params[:parent_id].empty? ? nil : Comment.find(comment_params[:parent_id])
Severity: Minor
Found in app/controllers/comments_controller.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 create has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def create
    session[:authhash] = nil #ensure no one sets it
    omniauth = request.env['omniauth.auth']
    provider = request.env['omniauth.auth']['provider']
    @authhash = Hash.new
Severity: Minor
Found in app/controllers/identities_controller.rb - About 1 hr to fix

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

      def create
        if params[:cancel]
          delete_sessions
          redirect_to root_url, flash: { error: t('controllers.users.create.flash.canceled') }
        else
    Severity: Minor
    Found in app/controllers/users_controller.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

    Function drawBubble has 29 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        var drawBubble = function(context, label, colour) {
    
            // automatic abbreviation for long (>2 digits) numbers
            if (typeof label == 'number' && label > 99 && options.abbreviate) {
                label = abbreviateNumber(label);
    Severity: Minor
    Found in app/assets/javascripts/tinycon.js - About 1 hr to fix

      Method determine_browser_and_os has 28 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def determine_browser_and_os(ua = request.env["HTTP_USER_AGENT"])
          ua = (ua||"").downcase
          br = case ua
            when /opera[\/,\s+](\d+)/
              o = %W(opera opera#{$1})
      Severity: Minor
      Found in app/helpers/application_helper.rb - About 1 hr to fix

        Method create has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def create
            @story = Story.find(params[:story_id])
            @comment = @story.comments.build(comment_params)
            @comment.user = nil
            @comment.parent_id = comment_params[:parent_id].empty? ? nil : Comment.find(comment_params[:parent_id])
        Severity: Minor
        Found in app/controllers/comments_controller.rb - About 1 hr to fix

          Method create has 26 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def create
              if params[:cancel]
                delete_sessions
                redirect_to root_url, flash: { error: t('controllers.users.create.flash.canceled') }
              else
          Severity: Minor
          Found in app/controllers/users_controller.rb - About 1 hr to fix

            Method create has 26 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def create
                begin
                  @rating         = Rating.find(votes_params[:rating_id])
                  @user           = current_user
                  @vote           = Vote.new()
            Severity: Minor
            Found in app/controllers/votes_controller.rb - About 1 hr to fix

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

                    @stories = Story.search(:include => [:tags, :user, :publisher, {:votes => [:rating, :user]}]) do
                      without(:publish_date, nil)
                      without(:hide, true)
                      fulltext params[:search]
                      fulltext params[:tag]
              Severity: Minor
              Found in app/controllers/stories_controller.rb and 1 other location - About 50 mins to fix
              app/controllers/api/v1/stories_controller.rb on lines 20..27

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

              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

                      @stories = Story.search(:include => [:tags, :user, :publisher, {:votes => [:rating, :user]}]) do
                        without(:publish_date, nil)
                        without(:hide, true)
                        fulltext params[:search]
                        fulltext params[:tag]
              Severity: Minor
              Found in app/controllers/api/v1/stories_controller.rb and 1 other location - About 50 mins to fix
              app/controllers/stories_controller.rb on lines 171..178

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

              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 normalize_friendly_id(string)
                  sep = "-"
                  parameterized_string = string
                  parameterized_string.gsub!(/[^\w\-اآبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیءئؤيإأةك۱۲۳۴۵۶۷۸۹۰ٔ‌]+/i, sep)
                  unless sep.nil? || sep.empty?
              Severity: Minor
              Found in app/models/user.rb and 1 other location - About 45 mins to fix
              app/models/story.rb on lines 128..139

              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

                def normalize_friendly_id(string)
                  sep = "-"
                  parameterized_string = string
                  parameterized_string.gsub!(/[^a-z0-9\-_اآبپتثجچحخدذرزژسشصضطظعغفقکگلمنوهیءئؤيإأةك۱۲۳۴۵۶۷۸۹۰ٔ‌]+/i, sep)
                  unless sep.nil? || sep.empty?
              Severity: Minor
              Found in app/models/story.rb and 1 other location - About 45 mins to fix
              app/models/user.rb on lines 88..99

              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

              Method publish has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def publish
                  respond_to do |format|
                    if @story.mark_as_published(current_user, story_url(@story))
              
                      rate_user(@story.user, 3) if @story.user #rate for user who wrote a story
              Severity: Minor
              Found in app/controllers/stories_controller.rb - About 45 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 8 (exceeds 5 allowed). Consider refactoring.
              Open

                def update
                  @story.attributes = story_params
              
                  respond_to do |format|
                    if params[:preview_button]
              Severity: Minor
              Found in app/controllers/stories_controller.rb - About 45 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 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def create
                  if current_user
                    @user = current_user
                    @story = @user.stories.build(story_params)
                  else
              Severity: Minor
              Found in app/controllers/stories_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 new has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def new
                  if pre_auth.authorizable?
                    if Doorkeeper::AccessToken.matching_token_for(pre_auth.client, current_resource_owner.id, pre_auth.scopes) || skip_authorization?
                      auth = authorization.authorize
                      redirect_to auth.redirect_uri
              Severity: Minor
              Found in app/controllers/oauth/authorizations_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 show has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def show
                  @story = Story.includes([:tags, :user, :publisher, {:votes => [:rating, :user]}]).find(params[:id])
              
                  share_by_mail
              
              
              Severity: Minor
              Found in app/controllers/stories_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 has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
              Open

                def create
                  user = User.where(:email => params[:email]).first
                  if user && user.authenticate(params[:password])
                    if params[:remember_me]
                      cookies.permanent.signed[:user_id] = user.id
              Severity: Minor
              Found in app/controllers/sessions_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

              Severity
              Category
              Status
              Source
              Language