ArtOfCode-/qpixel

View on GitHub

Showing 99 of 164 total issues

Method update has 57 lines of code (exceeds 25 allowed). Consider refactoring.
Open

  def update
    before = { body: @post.body_markdown, title: @post.title, tags: @post.tags }
    after_tags = if @post_type.has_category?
                   Tag.where(tag_set_id: @post.category.tag_set_id, name: params[:post][:tags_cache])
                 end
Severity: Major
Found in app/controllers/posts_controller.rb - About 2 hrs to fix

    Class User has 21 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class User < ApplicationRecord
      # Include default devise modules. Others available are:
      # :confirmable, :lockable, :timeoutable and :omniauthable
      devise :database_authenticatable, :registerable, :confirmable,
             :recoverable, :rememberable, :trackable, :validatable,
    Severity: Minor
    Found in app/models/user.rb - About 2 hrs to fix

      Class ApplicationController has 21 methods (exceeds 20 allowed). Consider refactoring.
      Open

      class ApplicationController < ActionController::Base
        # Prevent CSRF attacks by raising an exception.
        # For APIs, you may want to use :null_session instead.
        protect_from_forgery with: :exception
        before_action :configure_permitted_parameters, if: :devise_controller?
      Severity: Minor
      Found in app/controllers/application_controller.rb - About 2 hrs to fix

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

          def create
            @post_type = PostType.find(params[:post][:post_type_id])
            @parent = Post.where(id: params[:parent]).first
            @category = if @post_type.has_category
                          if params[:post][:category_id].present?
        Severity: Major
        Found in app/controllers/posts_controller.rb - About 2 hrs to fix

          Method recalc_privilege has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

            def recalc_privilege(internal_id, sandbox: false)
              # Do not recalculate privileges already granted
              return true if privilege?(internal_id, ignore_suspension: true, ignore_mod: true)
          
              priv = Ability.where(internal_id: internal_id).first
          Severity: Minor
          Found in app/models/community_user.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 codidact has 46 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

            def codidact
              ad = Rails.cache.fetch 'codidact_ad', expires_in: 60.minutes do
                ad = Image.new(600, 500)
                ad.background_color = 'white'
          
          
          Severity: Minor
          Found in app/controllers/advertisement_controller.rb - About 1 hr to fix

            Method posts has 46 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

              def posts(ids)
                groups = ids.in_groups_of(100).map(&:compact)
                posts = []
                groups.each do |group|
                  posts = posts.concat request("https://api.stackexchange.com/2.2/posts/#{group.join(';')}",
            Severity: Minor
            Found in scripts/import/api_import.rb - About 1 hr to fix

              Function gotoMenu has 46 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                  function gotoMenu(e) {
                      if (e.key === 'm') {
                          window.location.href = '/';
                      }
                      else if (e.key === 'u') {
              Severity: Minor
              Found in app/assets/javascripts/keyboard_tools.js - About 1 hr to fix

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

                  def create
                    @post = Post.find(params[:comment][:post_id])
                    if @post.comments_disabled && !current_user.is_moderator && !current_user.is_admin
                      render json: { status: 'failed', message: 'Comments have been disabled on this post.' }, status: :forbidden
                      return
                Severity: Minor
                Found in app/controllers/comments_controller.rb - About 1 hr to fix

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

                    def qualifiers_to_sql(qualifiers)
                      valid_value = {
                        date: /^[<>=]{0,2}\d+(?:s|m|h|d|w|mo|y)?$/,
                        numeric: /^[<>=]{0,2}\d+$/
                      }
                  Severity: Minor
                  Found in app/helpers/search_helper.rb - About 1 hr to fix

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

                        function toolsMenu(e) {
                            if (e.key === 'e') {
                                window.location.href = $(_CodidactKeyboard.selectedItem).find('.tools--item i.fa.fa-pencil-alt').parent().attr("href");
                            }
                            else if (e.key === 'h') {
                    Severity: Minor
                    Found in app/assets/javascripts/keyboard_tools.js - About 1 hr to fix

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

                        def self.do_xml_transform(site_domain, data_type, options)
                          dump_path = options.path
                          community_id = options.community
                          category_id = options.category
                      
                      
                      Severity: Minor
                      Found in scripts/import/dump_import.rb - About 1 hr to fix

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

                          def run
                            # We only want questions and answers; nuke anything that isn't
                            query "DELETE FROM #{table 'posts'} WHERE #{column 'post_type_id'} NOT IN (1, 2)"
                        
                            # Change post user IDs to SE account IDs so we can re-associate them with users later
                        Severity: Minor
                        Found in scripts/import/database_import.rb - About 1 hr to fix

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

                            def mod_privilege_action
                              ability = Ability.find_by internal_id: params[:ability]
                              return not_found if ability.internal_id == 'mod'
                          
                              ua = @user.community_user.privilege(ability.internal_id)
                          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 mod_privilege_action has 35 lines of code (exceeds 25 allowed). Consider refactoring.
                          Open

                            def mod_privilege_action
                              ability = Ability.find_by internal_id: params[:ability]
                              return not_found if ability.internal_id == 'mod'
                          
                              ua = @user.community_user.privilege(ability.internal_id)
                          Severity: Minor
                          Found in app/controllers/users_controller.rb - About 1 hr to fix

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

                              def full_log
                                @posts = Post.where(user: @user).count
                                @comments = Comment.where(user: @user).count
                                @flags = Flag.where(user: @user).count
                                @suggested_edits = SuggestedEdit.where(user: @user).count
                            Severity: Minor
                            Found in app/controllers/users_controller.rb - About 1 hr to fix

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

                                createNotification: function(type, message) {
                                  // Some messages include a date stamp, `append_date` governs that.
                                  let append_date = false;
                                  let message_with_date = message;
                                  if (type === 'danger') {
                              Severity: Minor
                              Found in app/assets/javascripts/qpixel_api.js - About 1 hr to fix

                                Method close has 32 lines of code (exceeds 25 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

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

                                    def tab(text, link_url, **opts, &block)
                                      active = opts[:is_active] || false
                                      opts.delete :is_active
                                      opts[:class] = if opts[:class]
                                                       "#{opts[:class]} tabs--tab#{active ? ' tab__active' : ''}"
                                  Severity: Minor
                                  Found in app/helpers/tabs_helper.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

                                  Severity
                                  Category
                                  Status
                                  Source
                                  Language