publiclab/plots2

View on GitHub

Showing 686 of 688 total issues

Method send_digest_spam has a Cognitive Complexity of 12 (exceeds 5 allowed). Consider refactoring.
Open

  def send_digest_spam(nodes, frequency_digest)
    if frequency_digest == User::Frequency::DAILY
      @subject = 'Your daily digest for moderation'
    elsif frequency_digest == User::Frequency::WEEKLY
      @subject = 'Your weekly digest for moderation'
Severity: Minor
Found in app/mailers/admin_mailer.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 reset has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def reset
    if params[:key] && !params[:key].nil?
      @user = User.find_by(reset_key: params[:key])
      if @user
        if params[:user] && params[:user][:password]
Severity: Minor
Found in app/controllers/users_controller.rb - About 1 hr to fix

Method parse_comment_from_email has 35 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.parse_comment_from_email(mail, node_id, user, reply_to = [false, nil])
    node = Node.where(nid: node_id).first
    if node && mail&.html_part
      mail_doc = Nokogiri::HTML(mail&.html_part&.body&.decoded) # To parse the mail to extract comment content and reply content
      domain = get_domain mail.from.first
Severity: Minor
Found in app/models/comment.rb - About 1 hr to fix

Function urlMapHash has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function urlMapHash() {
  // This is based off of jywarren's urlhash, made specific to our map hash needs

  const paramArray = ["zoom", "lat", "lon"];
  
Severity: Minor
Found in app/assets/javascripts/urlMapHash.js - About 1 hr to fix

Method index has 34 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def index
    range
    if @start > @end
      flash.now[:warning] = "Start date must come before end date"
    end
Severity: Minor
Found in app/controllers/stats_controller.rb - About 1 hr to fix

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

      o[ os[i].rows[0] ] = { text: o[ os[i].rows[0] ], row: ns[i].rows[0] };
Severity: Major
Found in app/assets/javascripts/jsdiff.js and 1 other location - About 1 hr to fix
app/assets/javascripts/jsdiff.js on lines 138..138

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

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 params[:topic]
      nids = @nodes.collect(&:nid) || []
      @notes = Node.where(status: 1, type: %w(page))
        .where('node.nid IN (?)', nids)
        .where('(type = "note" OR type = "page" OR type = "map") AND node.status = 1 AND (node.title LIKE ? OR node_revisions.title LIKE ? OR node_revisions.body LIKE ? OR term_data.name = ?)',
Severity: Major
Found in app/controllers/wiki_controller.rb and 1 other location - About 1 hr to fix
app/controllers/wiki_controller.rb on lines 433..444

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

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

      n[ ns[i].rows[0] ] = { text: n[ ns[i].rows[0] ], row: os[i].rows[0] };
Severity: Major
Found in app/assets/javascripts/jsdiff.js and 1 other location - About 1 hr to fix
app/assets/javascripts/jsdiff.js on lines 139..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 62.

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 params[:topic]
      nids = @nodes.collect(&:nid) || []
      @nodes = Node.where(status: 1, type: %w(page))
        .where('node.nid IN (?)', nids)
        .where('(type = "note" OR type = "page" OR type = "map") AND node.status = 1 AND (node.title LIKE ? OR node_revisions.title LIKE ? OR node_revisions.body LIKE ? OR term_data.name = ?)',
Severity: Major
Found in app/controllers/wiki_controller.rb and 1 other location - About 1 hr to fix
app/controllers/wiki_controller.rb on lines 420..431

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

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

Function SignUpFormValidator has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function SignUpFormValidator(formClass) {
  var signUpForm = document.querySelector(formClass);

  if (!signUpForm) return;

Severity: Minor
Found in app/assets/javascripts/validation.js - About 1 hr to fix

Function diff has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function diff( o, n ) {
  var ns = new Object();
  var os = new Object();
  
  for ( var i = 0; i < n.length; i++ ) {
Severity: Minor
Found in app/assets/javascripts/jsdiff.js - About 1 hr to fix

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

  def create
    @node = Node.find params[:id]
    @body = params[:body]
    @user = current_user
    begin
Severity: Minor
Found in app/controllers/comment_controller.rb - About 1 hr to fix

Method notify_tag_added has 33 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def notify_tag_added(node, tag, tagging_user)
    subject = '[PublicLab] ' +
              (node.has_power_tag('question') ? 'Question: ' : '') +
              node.title +
              " (##{node.id}) "
Severity: Minor
Found in app/mailers/subscription_mailer.rb - About 1 hr to fix

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

  def create
    if params[:i]
      @image = Image.new(remote_url: params[:i],
                         uid: current_user.uid)
      flash[:error] = 'The image could not be saved.' unless @image.save!
Severity: Minor
Found in app/controllers/images_controller.rb - About 1 hr to fix

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

  def notify_moderators_of_spam(node, moderator)
    subject = '[New Public Lab poster needs moderation] ' + node.title
    @author = node.author
    @moderator = moderator
    @node = node
Severity: Major
Found in app/mailers/admin_mailer.rb and 1 other location - About 1 hr to fix
app/mailers/admin_mailer.rb on lines 86..101

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

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 notify_moderators_of_approval(node, moderator)
    subject = '[New Public Lab poster needs moderation] ' + node.title
    @author = node.author
    @moderator = moderator
    @node = node
Severity: Major
Found in app/mailers/admin_mailer.rb and 1 other location - About 1 hr to fix
app/mailers/admin_mailer.rb on lines 122..137

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

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

Function attachSaveListener has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  attachSaveListener() {
    // remove any other existing eventHandler
    $("textarea").off("input.save"); // input.save is a custom jQuery eventHandler
    const thisEditor = this; // save a reference to this editor, because inside the eventListener, "this" points to e.target
    //implementing a debounce function on save method
Severity: Minor
Found in app/assets/javascripts/editor.js - About 1 hr to fix

Method new has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def new
    @revision = Revision.new
    if current_user &.first_time_poster
      flash[:notice] = "You can create a wiki once your research note/question has been approved by moderators. Click <a href='https://publiclab.org/notes/tester/04-23-2016/new-moderation-system-for-first-time-posters'>here</a> to learn why."
      redirect_to '/'
Severity: Minor
Found in app/controllers/wiki_controller.rb - About 1 hr to fix

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

  def create
    if !current_user.admin?
      flash[:warning] = 'Only admins may edit features.'
      redirect_to "/features?_=#{Time.now.to_i}"
    else
Severity: Minor
Found in app/controllers/features_controller.rb - About 1 hr to fix

Method delete has 32 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def delete
    node_tag = NodeTag.where(nid: params[:nid], tid: params[:tid]).first
    node = Node.where(nid: params[:nid]).first
    # only admins, mods can delete other peoples' tags if the note/wiki contains the locked tag
    if (node_tag.uid == current_user.uid && !node.has_tag('locked')) || logged_in_as(['admin', 'moderator']) || (node.uid == current_user.uid && !node.has_tag('locked'))
Severity: Minor
Found in app/controllers/tag_controller.rb - About 1 hr to fix
Severity
Category
Status
Source
Language