assemblymade/coderwall

View on GitHub

Showing 189 of 189 total issues

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

  def add_skills_for_lanyrd_facts!
    tokenized_lanyrd_tags.each do |lanyrd_tag|
      if self.skills.any?
        skill = skill_for(lanyrd_tag)
        skill.apply_facts unless skill.nil?
Severity: Minor
Found in app/models/concerns/user_facts.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 validate_each has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
Open

  def validate_each(object, attribute, value)
    raise(ArgumentError, "A regular expression must be supplied as the :format option of the options hash") unless options[:format].nil? or options[:format].is_a?(Regexp)
    configuration = {message: "is invalid or not responding", format: URI::regexp(%w(http https))}
    configuration.update(options)

Severity: Minor
Found in app/validators/uri_validator.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 2 locations. Consider refactoring.
Open

  def comment_reply(username, commentor_username, comment_id)
    headers['X-Mailgun-Variables'] = {email_type: NEW_COMMENT_EVENT}.to_json
    track_campaign("new_comment")

    @commentor = User.find_by_username(commentor_username)
Severity: Major
Found in app/mailers/notifier_mailer.rb and 1 other location - About 1 hr to fix
app/mailers/notifier_mailer.rb on lines 88..100

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

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 new_comment(user_id, commentor_id, comment_id)
    headers['X-Mailgun-Variables'] = {email_type: NEW_COMMENT_EVENT}.to_json
    track_campaign("new_comment")

    @commentor = User.find(commentor_id)
Severity: Major
Found in app/mailers/notifier_mailer.rb and 1 other location - About 1 hr to fix
app/mailers/notifier_mailer.rb on lines 102..114

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

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

  def perform(id)
    client = Octokit::Client.new
    if  ENV['TRAVIS'].blank? && client.ratelimit[:remaining] < 1000
      # If we have less than 1000 request remaining, delay this job
      # We leaving 1000 for more critical tasks
Severity: Minor
Found in app/jobs/extract_github_profile.rb - About 1 hr to fix

    Method search_for_popular_protips has 27 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        def self.search_for_popular_protips(from, to, max_results=10)
          url = "#{ENV['ELASTICSEARCH_URL']}/#{ENV['ELASTICSEARCH_PROTIPS_INDEX']}/_search"
          query = {
            'query' => {
              'bool' => {
    Severity: Minor
    Found in app/mailers/protip_mailer.rb - About 1 hr to fix

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

          def search(query_string, tags =[], options={})
            query, team, author, bookmarked_by, execution, sorts= preprocess_query(query_string)
            tags = [] if tags.nil?
            tags = preprocess_tags(tags)
            tag_ids = process_tags_for_search(tags)
      Severity: Minor
      Found in app/models/protip.rb - About 1 hr to fix

        Consider simplifying this complex logical expression.
        Open

              unless query_string.nil?
                query = query_string.dup
                query.gsub!(/(\d+)\"/, "\\1\\\"") #handle 27" cases
                team = query.gsub!(/(team:([0-9A-Z\-]+))/i, "") && $2
                team = (team =~ /^[a-f0-9]+$/i && team.length == 24 ? team : Team.where(slug: team).first.try(:id))
        Severity: Major
        Found in app/models/protip.rb - About 1 hr to fix

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

            def add(badge, github_username)
              badge_name = get_name badge
          
              id = @client.organization_teams("coderwall-#{badge_name}")[1].id
          
          
          Severity: Minor
          Found in app/structs/github_badge.rb and 1 other location - About 55 mins to fix
          app/structs/github_badge.rb on lines 27..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 46.

          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 remove(badge, github_username)
              badge_name = get_name badge
              id         = @client.organization_teams("coderwall-#{badge_name}")[1].id
              @client.remove_team_member(id, github_username)
            rescue Octokit::NotFound => e
          Severity: Minor
          Found in app/structs/github_badge.rb and 1 other location - About 55 mins to fix
          app/structs/github_badge.rb on lines 15..25

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

          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 upvote_ancestor has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def upvote_ancestor(link_identifier, link)
              ProtipLink.where(identifier: link_identifier).order('created_at ASC').first.try(:tap) do |ancestor|
                if (ancestor.protip != self) and (ancestor.protip.author.id != self.author.id) and (ancestor.url == link)
                  ancestor.protip.upvote_by(self.user, self.user.tracking_code, DEFAULT_IP_ADDRESS) unless ancestor.nil? || ancestor.protip.nil?
                  break
          Severity: Minor
          Found in app/models/protip.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 sanitize_tags! has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def sanitize_tags!
              new_topics = self.topic_list.reject { |tag| tag.blank? }.map do |topic|
                sanitized_topic = self.class.preprocess_tag(topic)
                invalid_topic = topic.match("^((?!#{VALID_TAG}).)*$") && $1
                errors[:topics] << "The tag '#{topic}' has invalid characters: #{invalid_topic unless invalid_topic.nil?}" if sanitized_topic.nil?
          Severity: Minor
          Found in app/models/protip.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 accept has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def accept
              apply_cache_buster
          
              accept_params = params.permit(:id, :r, :email)
          
          
          Severity: Minor
          Found in app/controllers/teams_controller.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

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

            def replace_assignments_and_awards_for_twitter(twitter_usernames, badge_class)
              competition_end_date = Date.parse(@end_date)
              tags                 = ['hackathon', 'nodejs', 'award', 'nodeknockout']
              metadata             = { award: badge_class.name }
              twitter_usernames.each do |twitter_username|
          Severity: Minor
          Found in app/badges/node_knockout.rb and 1 other location - About 55 mins to fix
          app/badges/node_knockout.rb on lines 53..61

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

          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

              if user.team.try(:hiring?)
                [user.team, user.team.jobs.sample]
              else
                teams = teams_for_user(user)
                teams.each do |team|
          Severity: Minor
          Found in app/mailers/protip_mailer.rb and 1 other location - About 55 mins to fix
          app/mailers/weekly_digest_mailer.rb on lines 127..133

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

          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 topics_to_query has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def topics_to_query(topics)
              topics = topics.split(" + ") unless topics.nil? or topics.is_a? Array
              topics.map do |topic|
                if Protip::USER_SCOPE.include? topic or topic =~ /^team:/ or topic =~ /^author:/
                  topic
          Severity: Minor
          Found in app/helpers/protips_helper.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

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

              if user.team.try(:hiring?)
                [user.team, user.team.jobs.sample]
              else
                teams = teams_for_user(user)
                teams.each do |team|
          Severity: Minor
          Found in app/mailers/weekly_digest_mailer.rb and 1 other location - About 55 mins to fix
          app/mailers/protip_mailer.rb on lines 85..91

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

          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 replace_assignments_and_awards(github_usernames, badge_class)
              competition_end_date = Date.parse(@end_date)
              tags                 = ['hackathon', 'nodejs', 'award', 'nodeknockout']
              metadata             = {
                award: badge_class.name
          Severity: Minor
          Found in app/badges/node_knockout.rb and 1 other location - About 55 mins to fix
          app/badges/node_knockout.rb on lines 66..72

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

          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 process_links has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def process_links
              if self.body_changed?
                self.links.each do |link|
                  link_identifier = ProtipLink.generate_identifier(link)
                  existing_link = self.protip_links.find_or_initialize_by_identifier(identifier: link_identifier, url: link.first(254))
          Severity: Minor
          Found in app/models/protip.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 record_visit has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

            def record_visit
              if viewing_user
                if viewing_user == current_user && (viewing_user.try(:last_request_at) || 1.week.ago) < 1.day.ago && viewing_user.active? && viewing_user.last_refresh_at < 2.days.ago
                  RefreshUserJob.perform_async(current_user.id)
                end
          Severity: Minor
          Found in app/controllers/application_controller.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

          Severity
          Category
          Status
          Source
          Language