publiclab/plots2

View on GitHub

Showing 216 of 688 total issues

Function diffString has 39 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function diffString( o, n ) {
  o = o.replace(/\s+$/, '');
  n = n.replace(/\s+$/, '');

  var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
Severity: Minor
Found in app/assets/javascripts/jsdiff.js - About 1 hr to fix

Method subscribe_multiple_tag has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def subscribe_multiple_tag(tag_list)
    if !tag_list || tag_list == ''
      flash[:notice] = "Please enter tags for subscription in the url."
    else
      if tag_list.is_a? String
Severity: Minor
Found in app/controllers/users_controller.rb - About 1 hr to fix

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

  def create
    @user = User.new(user_params)
    @user.status = 1
    using_recaptcha = !params[:spamaway] && Rails.env == "production"
    recaptcha = verify_recaptcha(model: @user) if using_recaptcha
Severity: Minor
Found in app/controllers/users_controller.rb - About 1 hr to fix

Method subscribe_multiple_tag has 38 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def subscribe_multiple_tag(tag_list)
    if !tag_list || tag_list == ''
      flash[:notice] = "Please enter tags for subscription in the url."
    else
      if tag_list.is_a? String
Severity: Minor
Found in app/controllers/user_sessions_controller.rb - About 1 hr to fix

Method new_note has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def self.new_note(params)
    saved = false
    author = User.find(params[:uid])
    node = Node.new(uid:     author.uid,
                    title:   params[:title],
Severity: Minor
Found in app/models/node.rb - About 1 hr to fix

Method tagNearbyNodes has 37 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def tagNearbyNodes(coordinates, tag, period = { "from" => nil, "to" => nil }, sort_by = nil, order_direction = nil, limit = 10)
    raise("Must contain all four coordinates") if coordinates["nwlat"].nil?
    raise("Must contain all four coordinates") if coordinates["nwlng"].nil?
    raise("Must contain all four coordinates") if coordinates["selat"].nil?
    raise("Must contain all four coordinates") if coordinates["selng"].nil?
Severity: Minor
Found in app/services/search_service.rb - About 1 hr to fix

Function diffString2 has 36 lines of code (exceeds 25 allowed). Consider refactoring.
Open

function diffString2( o, n ) {
  o = o.replace(/\s+$/, '');
  n = n.replace(/\s+$/, '');

  var out = diff(o == "" ? [] : o.split(/\s+/), n == "" ? [] : n.split(/\s+/) );
Severity: Minor
Found in app/assets/javascripts/jsdiff.js - About 1 hr to fix

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

  def publish_comment
    if logged_in_as(['admin', 'moderator'])
      @comment = Comment.find params[:id]
      if @comment.status == 1
        flash[:notice] = 'Comment already published.'
Severity: Minor
Found in app/controllers/admin_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

Method create has a Cognitive Complexity of 12 (exceeds 5 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

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

  def alert_and_redirect_moderated
    if @node.author.status == User::Status::BANNED && !(logged_in_as(['admin', 'moderator']))
      flash[:error] = I18n.t('application_controller.author_has_been_banned')
      redirect_to '/'
    elsif @node.status == 4 && (logged_in_as(['admin', 'moderator']))
Severity: Minor
Found in app/controllers/application_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

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

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

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

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

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

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

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
Severity
Category
Status
Source
Language