Noosfero/noosfero

View on GitHub
app/controllers/my_profile/cms_controller.rb

Summary

Maintainability
F
6 days
Test Coverage

File cms_controller.rb has 568 lines of code (exceeds 250 allowed). Consider refactoring.
Open

class CmsController < MyProfileController
  protect "edit_profile", :profile, only: [:set_home_page]

  include ArticleHelper
  include CategoriesHelper
Severity: Major
Found in app/controllers/my_profile/cms_controller.rb - About 1 day to fix

    Class CmsController has 40 methods (exceeds 20 allowed). Consider refactoring.
    Open

    class CmsController < MyProfileController
      protect "edit_profile", :profile, only: [:set_home_page]
    
      include ArticleHelper
      include CategoriesHelper
    Severity: Minor
    Found in app/controllers/my_profile/cms_controller.rb - About 5 hrs to fix

      Method edit has a Cognitive Complexity of 27 (exceeds 5 allowed). Consider refactoring.
      Open

        def edit
          params[:article] ||= {}
          @success_back_to = params[:success_back_to]
          @article = profile.articles.find(params[:id])
          version = params[:version]
      Severity: Minor
      Found in app/controllers/my_profile/cms_controller.rb - About 3 hrs 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 new has a Cognitive Complexity of 25 (exceeds 5 allowed). Consider refactoring.
      Open

        def new
          # FIXME this method should share some logic with edit !!!
          @success_back_to = params[:success_back_to]
          # user must choose an article type first
      
      
      Severity: Minor
      Found in app/controllers/my_profile/cms_controller.rb - About 3 hrs 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 publish_on_communities has a Cognitive Complexity of 23 (exceeds 5 allowed). Consider refactoring.
      Open

        def publish_on_communities
          if request.post?
            @back_to = params[:back_to]
            @article = profile.articles.find(params[:id])
            @failed = {}
      Severity: Minor
      Found in app/controllers/my_profile/cms_controller.rb - About 3 hrs 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 upload_files has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
      Open

        def upload_files
          upload_single_file?
          @uploaded_files = []
          @parent = check_parent(params[:parent_id])
          @target = @parent ? ("/%s/%s" % [profile.identifier, @parent.full_name]) : "/%s" % profile.identifier
      Severity: Minor
      Found in app/controllers/my_profile/cms_controller.rb - About 2 hrs 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 new has 63 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

        def new
          # FIXME this method should share some logic with edit !!!
          @success_back_to = params[:success_back_to]
          # user must choose an article type first
      
      
      Severity: Major
      Found in app/controllers/my_profile/cms_controller.rb - About 2 hrs to fix

        Method invite_to_event has a Cognitive Complexity of 18 (exceeds 5 allowed). Consider refactoring.
        Open

          def invite_to_event
            @article = profile.articles.find(params[:id])
            @profiles = invite_event_to @article
            record_coming
            if request.post?
        Severity: Minor
        Found in app/controllers/my_profile/cms_controller.rb - About 2 hrs 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 publish_on_portal_community has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
        Open

          def publish_on_portal_community
            if request.post?
              @article = profile.articles.find(params[:id])
              if environment.portal_enabled
                task = ApproveArticle.create!(article: @article, name: params[:name], target: environment.portal_community, requestor: user)
        Severity: Minor
        Found in app/controllers/my_profile/cms_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 publish has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
        Open

          def publish
            @article = profile.articles.find(params[:id])
            record_coming
            @failed = {}
            if request.post?
        Severity: Minor
        Found in app/controllers/my_profile/cms_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 edit has 39 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

          def edit
            params[:article] ||= {}
            @success_back_to = params[:success_back_to]
            @article = profile.articles.find(params[:id])
            version = params[:version]
        Severity: Minor
        Found in app/controllers/my_profile/cms_controller.rb - About 1 hr to fix

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

            def invite_to_event
              @article = profile.articles.find(params[:id])
              @profiles = invite_event_to @article
              record_coming
              if request.post?
          Severity: Minor
          Found in app/controllers/my_profile/cms_controller.rb - About 1 hr to fix

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

              def upload_files
                upload_single_file?
                @uploaded_files = []
                @parent = check_parent(params[:parent_id])
                @target = @parent ? ("/%s/%s" % [profile.identifier, @parent.full_name]) : "/%s" % profile.identifier
            Severity: Minor
            Found in app/controllers/my_profile/cms_controller.rb - About 1 hr to fix

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

                def publish_on_communities
                  if request.post?
                    @back_to = params[:back_to]
                    @article = profile.articles.find(params[:id])
                    @failed = {}
              Severity: Minor
              Found in app/controllers/my_profile/cms_controller.rb - About 1 hr to fix

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

                  def media_upload
                    parent = check_parent(params[:parent_id])
                    if request.post?
                      begin
                        file = params[:file].present? ? params[:file] : params[:crop][:file]
                Severity: Minor
                Found in app/controllers/my_profile/cms_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 destroy has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                Open

                  def destroy
                    @article = profile.articles.find(params[:id])
                    if request.post?
                      @article.destroy
                      session[:notice] = _("\"%s\" was removed." % @article.title)
                Severity: Minor
                Found in app/controllers/my_profile/cms_controller.rb - About 45 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

                Avoid deeply nested control flow statements.
                Open

                            redirect_to action: (@article.parent ? "view" : "index"), id: @article.parent
                Severity: Major
                Found in app/controllers/my_profile/cms_controller.rb - About 45 mins to fix

                  Method select_profile has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def select_profile
                      current_page = params[:page] ? Article.find(params[:page]) : nil
                  
                      @sensitive_back = params[:back] ? params[:back] : false
                  
                  
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 45 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 set_home_page has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def set_home_page
                      return render_access_denied unless user.can_change_homepage?
                  
                      article = (params[:id].nil? || params[:id].blank?) ? nil : profile.articles.find(params[:id])
                      profile.update_attribute(:home_page, article)
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 35 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 suggest_an_article has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def suggest_an_article
                      @back_to = params[:back_to] || request.referer || url_for(profile.public_profile_url)
                      @task = SuggestArticle.new(params[:task])
                      if request.post?
                        @task.target = profile
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 35 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 article_list_to_json has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def article_list_to_json(list)
                        list.map do |item|
                          {
                            "title" => item.title,
                            "url" => item.image? ? item.public_filename(:uploaded) : url_for(item.url),
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 25 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 invite_event_to has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def invite_event_to(article)
                        profiles = profile.kind_of?(Organization) ? profile.members : profile.friends
                        inviteds = article.invitations if article.event?
                        result = []
                        profiles.each do |profile|
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 25 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 load_recent_files has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                      def load_recent_files(parent_id = nil, q = nil, paginate_options = { page: 1, per_page: 6 })
                        # TODO Since we only have special support for images, I'm limiting myself to
                        #     consider generic files as non-images. In the future, with more supported
                        #     file types we'll need to have a smart way to fetch from the database
                        #     scopes of each supported type as well as the non-supported types as a
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 25 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 sensitive_content has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                  Open

                    def sensitive_content
                      current_page = params[:page] ? Article.find(params[:page]) : nil
                      select_subdirectory = !params[:select_subdirectory].nil?
                  
                      @sensitive_back = params[:not_back] ? (params[:not_back] == "true") : false
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb - About 25 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

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

                        if @failed.blank?
                          session[:notice] = _("Your publish request was sent successfully")
                          if @back_to
                            redirect_to @back_to
                          else
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb and 1 other location - About 15 mins to fix
                  app/controllers/my_profile/cms_controller.rb on lines 456..466

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

                  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 @failed.blank?
                          session[:notice] = _("Your friends were invited successfully.")
                          if @back_to
                            redirect_to @back_to
                          else
                  Severity: Minor
                  Found in app/controllers/my_profile/cms_controller.rb and 1 other location - About 15 mins to fix
                  app/controllers/my_profile/cms_controller.rb on lines 318..328

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

                  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

                  There are no issues that match your filters.

                  Category
                  Status