mtwilliams/broadsheet

View on GitHub

Showing 12 of 12 total issues

Method mail has a Cognitive Complexity of 20 (exceeds 5 allowed). Consider refactoring.
Open

    def mail(opts = {})
      fail unless opts.include? :to
       fail unless opts[:to].include? :address
      fail unless opts.include? :from
       fail unless opts[:from].include? :address
Severity: Minor
Found in app/broadsheet/mailer.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 registered has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
Open

    def self.registered(app)
      app.before do
        begin
          if session[:id]
            @session = Broadsheet::Session[session[:id].to_i]
Severity: Minor
Found in app/broadsheet/authentication.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 mail has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    def mail(opts = {})
      fail unless opts.include? :to
       fail unless opts[:to].include? :address
      fail unless opts.include? :from
       fail unless opts[:from].include? :address
Severity: Minor
Found in app/broadsheet/mailer.rb - About 1 hr to fix

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

      def self.login(user)
        token = Broadsheet::Token.create(owner: user,
                                         type: 'one_time_login_token',
                                         unguessable: SecureRandom.hex(32),
                                         expires_at: DateTime.now + 1.day)
    Severity: Major
    Found in app/broadsheet/mailers/users_mailer.rb and 1 other location - About 1 hr to fix
    app/broadsheet/mailers/users_mailer.rb on lines 2..16

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

    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 self.welcome(user)
        token = Broadsheet::Token.create(owner: user,
                             type: 'email_verification_token',
                             unguessable: SecureRandom.hex(32),
                             expires_at: DateTime.now + 7.days)
    Severity: Major
    Found in app/broadsheet/mailers/users_mailer.rb and 1 other location - About 1 hr to fix
    app/broadsheet/mailers/users_mailer.rb on lines 18..32

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

    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 registered has 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.registered(app)
          app.before do
            begin
              if session[:id]
                @session = Broadsheet::Session[session[:id].to_i]
    Severity: Minor
    Found in app/broadsheet/authentication.rb - About 1 hr to fix

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

      def distance_of_time_in_words(from_time, to_time = Time.now.to_i, include_seconds = false)
        distance_in_minutes = (((to_time - from_time).abs)/60).round
        distance_in_seconds = ((to_time - from_time).abs).round
      
        case distance_in_minutes
      Severity: Minor
      Found in lib/dotiw.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

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

        def url
          if Broadsheet.env.production?
            "https://#{ENV['HOST']}/v1/comments/#{self.id}"
          else
            "http://#{ENV['HOST']}:#{ENV['PORT']}/v1/comments/#{self.id}"
      Severity: Minor
      Found in app/broadsheet/models/comment.rb and 2 other locations - About 25 mins to fix
      app/broadsheet/models/post.rb on lines 2..6
      app/broadsheet/models/user.rb on lines 2..6

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

      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 3 locations. Consider refactoring.
      Open

        def url
          if Broadsheet.env.production?
            "https://#{ENV['HOST']}/v1/users/#{self.id}"
          else
            "http://#{ENV['HOST']}:#{ENV['PORT']}/v1/users/#{self.id}"
      Severity: Minor
      Found in app/broadsheet/models/user.rb and 2 other locations - About 25 mins to fix
      app/broadsheet/models/comment.rb on lines 2..6
      app/broadsheet/models/post.rb on lines 2..6

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

      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 3 locations. Consider refactoring.
      Open

        def url
          if Broadsheet.env.production?
            "https://#{ENV['HOST']}/v1/posts/#{self.id}"
          else
            "http://#{ENV['HOST']}:#{ENV['PORT']}/v1/posts/#{self.id}"
      Severity: Minor
      Found in app/broadsheet/models/post.rb and 2 other locations - About 25 mins to fix
      app/broadsheet/models/comment.rb on lines 2..6
      app/broadsheet/models/user.rb on lines 2..6

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

      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 opts[:to][:name]
                to "#{opts[:to][:name]} <#{opts[:to][:address]}>"
              else
                to opts[:to][:address]
      Severity: Minor
      Found in app/broadsheet/mailer.rb and 1 other location - About 20 mins to fix
      app/broadsheet/mailer.rb on lines 32..35

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

      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 opts[:from][:name]
                from "#{opts[:from][:name]} <#{opts[:from][:address]}>"
              else
                from opts[:from][:address]
      Severity: Minor
      Found in app/broadsheet/mailer.rb and 1 other location - About 20 mins to fix
      app/broadsheet/mailer.rb on lines 27..30

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

      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