ArtOfCode-/qpixel

View on GitHub

Showing 99 of 164 total issues

Method lock has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def lock
    return not_found unless current_user.privilege? 'flag_curate'
    return not_found if @post.locked?

    length = params[:length].present? ? params[:length].to_i : nil
Severity: Minor
Found in app/controllers/posts_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 qualifier_presence has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def qualifier_presence
    return unless ['tag', 'user', 'category'].include? type

    if type == 'tag' && (qualifier.blank? || Tag.find_by(name: qualifier).nil?)
      errors.add(:qualifier, 'must provide a valid tag name for tag subscriptions')
Severity: Minor
Found in app/models/subscription.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 flag_verify has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def flag_verify
    @flag = Flag.find params[:id]
    return false if current_user.nil?

    type = @flag.post_flag_type
Severity: Minor
Found in app/controllers/flags_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 close has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

  def close
    unless check_your_privilege('flag_close', nil, false)
      render json: { status: 'failed', message: helpers.ability_err_msg(:flag_close, 'close this post') },
             status: :forbidden
      return
Severity: Minor
Found in app/controllers/posts_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 do_rtl_witchcraft has 31 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def do_rtl_witchcraft(str)
    chars = str.chars
    output_buffer = ''
    scan_buffer = []
    current_mode = rtl?(chars[0]) ? :rtl : :ltr
Severity: Minor
Found in app/helpers/advertisement_helper.rb - About 1 hr to fix

    Method role_toggle has 31 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

      def role_toggle
        role_map = { mod: :is_moderator, admin: :is_admin, mod_global: :is_global_moderator, admin_global: :is_global_admin,
                     staff: :staff }
        permission_map = { mod: :is_admin, admin: :is_global_admin, mod_global: :is_global_admin,
        admin_global: :is_global_admin, staff: :staff }
    Severity: Minor
    Found in app/controllers/users_controller.rb - About 1 hr to fix

      Method restore has 31 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def restore
          unless check_your_privilege('flag_curate', @post, false)
            flash[:danger] = helpers.ability_err_msg(:flag_curate, 'restore this post')
            redirect_to post_path(@post)
            return
      Severity: Minor
      Found in app/controllers/posts_controller.rb - About 1 hr to fix

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

          def delete
            unless check_your_privilege('flag_curate', @post, false)
              flash[:danger] = helpers.ability_err_msg(:flag_curate, 'delete this post')
              redirect_to post_path(@post)
              return
        Severity: Minor
        Found in app/controllers/posts_controller.rb - About 1 hr to fix

          Method method_missing has 28 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def self.method_missing(name, *args, **opts)
              unless args.length >= 2
                raise NoMethodError
              end
          
          
          Severity: Minor
          Found in app/models/post_history.rb - About 1 hr to fix

            Method soft_delete has 28 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def soft_delete
                if @user.is_admin || @user.is_moderator
                  render json: { status: 'failed', message: 'Admins and moderators cannot be deleted.' },
                         status: :unprocessable_entity
                  return
            Severity: Minor
            Found in app/controllers/users_controller.rb - About 1 hr to fix

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

                def soft_delete
                  if @user.is_admin || @user.is_moderator
                    render json: { status: 'failed', message: 'Admins and moderators cannot be deleted.' },
                           status: :unprocessable_entity
                    return
              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 update_profile has 27 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                def update_profile
                  profile_params = params.require(:user).permit(:username, :profile_markdown, :website, :twitter)
                  profile_params[:twitter] = profile_params[:twitter].delete('@')
              
                  if profile_params[:website].present? && URI.parse(profile_params[:website]).instance_of?(URI::Generic)
              Severity: Minor
              Found in app/controllers/users_controller.rb - About 1 hr to fix

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

                  def create
                    post = Post.find(params[:post_id])
                
                    if post.user == current_user && !SiteSetting['AllowSelfVotes']
                      render(json: { status: 'failed', message: 'You may not vote on your own posts.' }, status: :forbidden) && return
                Severity: Minor
                Found in app/controllers/votes_controller.rb - About 1 hr to fix

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

                    def read
                      @notification = Notification.unscoped.find params[:id]
                  
                      unless @notification.user == current_user
                        respond_to do |format|
                  Severity: Minor
                  Found in app/controllers/notifications_controller.rb - About 1 hr to fix

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

                      def self.useful_err_msg
                        [
                          'The inverted database guide has found an insurmountable problem. Please poke it with a ' \
                            'paperclip before anyone finds out.',
                          'The modular cable meter has found a problem. You need to kick your IT technician in the ' \
                    Severity: Minor
                    Found in app/models/application_record.rb - About 1 hr to fix

                      Method user_sort has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def user_sort(term_opts, **field_mappings)
                          default = term_opts[:default] || :created_at
                          requested = term_opts[:term]
                          direction = term_opts[:direction] || :desc
                          if requested.nil? || field_mappings.exclude?(requested.to_sym)
                      Severity: Minor
                      Found in app/models/application_record.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 category_sort_tags has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def category_sort_tags(tags, required_ids, topic_ids, moderator_ids)
                          tags
                            .to_a
                            .sort_by do |t|
                              [required_ids.include?(t.id) ? 0 : 1, moderator_ids.include?(t.id) ? 0 : 1,
                      Severity: Minor
                      Found in app/helpers/tags_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

                      Method method_missing has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def self.method_missing(name, *args, **opts)
                          unless args.length >= 2
                            raise NoMethodError
                          end
                      
                      
                      Severity: Minor
                      Found in app/models/post_history.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 create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def create
                          if !current_user.is_global_admin && params[:global] == '1'
                            not_found
                            return
                          end
                      Severity: Minor
                      Found in app/controllers/close_reasons_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

                      Method create has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
                      Open

                        def create
                          post = Post.find(params[:post_id])
                      
                          if post.user == current_user && !SiteSetting['AllowSelfVotes']
                            render(json: { status: 'failed', message: 'You may not vote on your own posts.' }, status: :forbidden) && return
                      Severity: Minor
                      Found in app/controllers/votes_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