publiclab/plots2

View on GitHub

Showing 686 of 688 total issues

Method add has 43 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def add
    if current_user && params[:type] == "tag"

      tag = Tag.find_by(name: params[:name])

Severity: Minor
Found in app/controllers/subscription_controller.rb - About 1 hr to fix

Method list has 41 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def list
    sort_param = params[:sort]
    @tagname_param = params[:tagname]

    order_string = if params[:id]
Severity: Minor
Found in app/controllers/users_controller.rb - About 1 hr to fix

Method save_settings has 40 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def save_settings
    user_settings = [
      'notify-comment-direct:false',
      'notify-likes-direct:false',
      'notify-comment-indirect:false',
Severity: Minor
Found in app/controllers/users_controller.rb - About 1 hr to fix

Function promptTag has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

function promptTag(val) {
  var input;
  switch(val) {

    case "series:":
Severity: Minor
Found in app/assets/javascripts/tagging.js - 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 update has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def update
    @password_verification = user_verification_params
    @user = current_user
    @user = User.find_by(username: params[:id]) if params[:id] && logged_in_as(['admin'])
    if @user.valid_password?(user_verification_params["current_password"]) || user_verification_params["ui_update"].nil? || (user_verification_params["current_password"].blank? && user_verification_params["password"].blank? && user_verification_params["password_confirmation"].blank?)
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

Method delete has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def delete
    output = {
      status: false,
      tid: 0,
      errors: []
Severity: Minor
Found in app/controllers/user_tags_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 graph_data has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def self.graph_data(limit = 250, type = 'nodes', weight = 0)
    Rails.cache.fetch("graph-data/#{limit}/#{type}/#{weight}", expires_in: 1.weeks) do
      data = {}
      data["tags"] = []
      if type == 'nodes' # notes
Severity: Minor
Found in app/models/tag.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 delete has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
Open

  def delete
    @node = Node.find(params[:id])
    if current_user && (current_user.uid == @node.uid || current_user.can_moderate?)
      if @node.authors.uniq.length == 1
        @node.destroy
Severity: Minor
Found in app/controllers/notes_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 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

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

  $('#answer-0-comment-form').bind('ajax:success', function(e, data, status, response) {
    $('#answer-0-comment-form #loading-spinner').addClass('hidden');
    $('#answer-0-comment-form #reply-comment').removeClass('hidden');
    $('#answer-0-comment-form #submit-comment').text('Submit');
    $('#answer-0-comment-form #submit-comment-button').removeClass('disabled');
Severity: Major
Found in app/assets/javascripts/question.js and 1 other location - About 1 hr to fix
app/assets/javascripts/question.js on lines 25..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 64.

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

  $('#answer-0-comment-form').bind('ajax:send', function(e) {
    $('#answer-0-comment-form #loading-spinner').removeClass('hidden');
    $('#answer-0-comment-form #reply-comment').addClass('hidden');
    $('#answer-0-comment-form #submit-comment-button').addClass('disabled');
    $('#answer-0-comment-form #submit-comment').text('Submitting');
Severity: Major
Found in app/assets/javascripts/question.js and 1 other location - About 1 hr to fix
app/assets/javascripts/question.js on lines 32..37

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

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

Severity
Category
Status
Source
Language