AlchemyCMS/alchemy_cms

View on GitHub

Showing 31 of 57 total issues

Class Page has 43 methods (exceeds 20 allowed). Consider refactoring.
Open

  class Page < BaseRecord
    include Alchemy::Hints
    include Alchemy::Logger
    include Alchemy::Taggable

Severity: Minor
Found in app/models/alchemy/page.rb - About 5 hrs to fix

    ElementEditor has 41 functions (exceeds 20 allowed). Consider refactoring.
    Open

    export class ElementEditor extends HTMLElement {
      constructor() {
        super()
    
        // Add event listeners
    Severity: Minor
    Found in app/javascript/alchemy_admin/components/element_editor.js - About 5 hrs to fix

      Class PagesController has 37 methods (exceeds 20 allowed). Consider refactoring.
      Open

          class PagesController < ResourcesController
            include OnPageLayout::CallbacksRunner
      
            helper "alchemy/pages"
      
      
      Severity: Minor
      Found in app/controllers/alchemy/admin/pages_controller.rb - About 4 hrs to fix

        Class Resource has 33 methods (exceeds 20 allowed). Consider refactoring.
        Open

          class Resource
            attr_accessor :resource_relations, :model_associations
            attr_reader :model
        
            DEFAULT_SKIPPED_ATTRIBUTES = %w[id created_at creator_id]
        Severity: Minor
        Found in lib/alchemy/resource.rb - About 4 hrs to fix

          File element_editor.js has 331 lines of code (exceeds 250 allowed). Consider refactoring.
          Open

          import ImageLoader from "alchemy_admin/image_loader"
          import fileEditors from "alchemy_admin/file_editors"
          import pictureEditors from "alchemy_admin/picture_editors"
          import SortableElements from "alchemy_admin/sortable_elements"
          import IngredientAnchorLink from "alchemy_admin/ingredient_anchor_link"
          Severity: Minor
          Found in app/javascript/alchemy_admin/components/element_editor.js - About 3 hrs to fix

            File page.rb has 305 lines of code (exceeds 250 allowed). Consider refactoring.
            Open

            require_dependency "alchemy/page/fixed_attributes"
            require_dependency "alchemy/page/page_layouts"
            require_dependency "alchemy/page/page_scopes"
            require_dependency "alchemy/page/page_natures"
            require_dependency "alchemy/page/page_naming"
            Severity: Minor
            Found in app/models/alchemy/page.rb - About 3 hrs to fix

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

                  def pages
                    tree = []
                    path = [{id: object.parent_id, children: tree}]
                    page_list = object.self_and_descendants.includes(:public_version, {language: :site})
                    base_level = object.level - 1
              Severity: Minor
              Found in app/serializers/alchemy/page_tree_serializer.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 try_seed_pages has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                    def try_seed_pages
                      return unless page_seeds_file.file?
              
                      if Alchemy::Page.exists?
                        desc "Seeding Alchemy pages"
              Severity: Minor
              Found in lib/alchemy/seeder.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 render_attribute has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                  def render_attribute(resource, attribute, options = {})
                    attribute_value = resource.send(attribute[:name])
                    if attribute[:relation]
                      record = resource.send(attribute[:relation][:name])
                      value = record.present? ? record.send(attribute[:relation][:attr_method]) : Alchemy.t(:not_found)
              Severity: Minor
              Found in lib/alchemy/resources_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 delete_multiple has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
              Open

                    def delete_multiple
                      if request.delete? && params[:picture_ids].present?
                        pictures = Picture.find(params[:picture_ids])
                        names = []
                        not_deletable = []
              Severity: Minor
              Found in app/controllers/alchemy/admin/pictures_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 expand has 37 lines of code (exceeds 25 allowed). Consider refactoring.
              Open

                expand() {
                  if (this.expanded && !this.compact) {
                    return Promise.resolve("Element is already expanded.")
                  }
              
              
              Severity: Minor
              Found in app/javascript/alchemy_admin/components/element_editor.js - About 1 hr to fix

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

                      def elements_count_by_name
                        res = Alchemy::Element.all
                          .select("name, COUNT(*) AS count")
                          .group(:name)
                          .order("count DESC, name ASC")
                Severity: Major
                Found in lib/alchemy/tasks/usage.rb and 1 other location - About 1 hr to fix
                lib/alchemy/tasks/usage.rb on lines 20..29

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

                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

                      def pages_count_by_type
                        res = Alchemy::Page.all
                          .select("page_layout, COUNT(*) AS count")
                          .group(:page_layout)
                          .order("count DESC, page_layout ASC")
                Severity: Major
                Found in lib/alchemy/tasks/usage.rb and 1 other location - About 1 hr to fix
                lib/alchemy/tasks/usage.rb on lines 8..17

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

                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 filter has 33 lines of code (exceeds 25 allowed). Consider refactoring.
                Open

                  filter(term) {
                    const results = []
                
                    this.items.forEach(function (item) {
                      if (
                Severity: Minor
                Found in app/javascript/alchemy_admin/sitemap.js - About 1 hr to fix

                  Function checkPageDirtyness has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                  function checkPageDirtyness(element) {
                    let callback = () => {}
                  
                    if ($(element).is("form")) {
                      callback = function () {
                  Severity: Minor
                  Found in app/javascript/alchemy_admin/dirty.js - About 1 hr to fix

                    Method page_hash has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                    Open

                        def page_hash(page, level, folded)
                          p_hash = {
                            id: page.id,
                            name: page.name,
                            public: page.public?,
                    Severity: Minor
                    Found in app/serializers/alchemy/page_tree_serializer.rb - About 1 hr to fix

                      Function collapse has 29 lines of code (exceeds 25 allowed). Consider refactoring.
                      Open

                        collapse() {
                          if (this.collapsed || this.compact || this.fixed) {
                            return Promise.resolve("Element is already collapsed.")
                          }
                      
                      
                      Severity: Minor
                      Found in app/javascript/alchemy_admin/components/element_editor.js - About 1 hr to fix

                        Function handleEvent has 28 lines of code (exceeds 25 allowed). Consider refactoring.
                        Open

                          handleEvent(event) {
                            switch (event.type) {
                              case "click":
                                const elementEditor = event.target.closest("alchemy-element-editor")
                                if (elementEditor === this) {
                        Severity: Minor
                        Found in app/javascript/alchemy_admin/components/element_editor.js - About 1 hr to fix

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

                              def pages
                                tree = []
                                path = [{id: object.parent_id, children: tree}]
                                page_list = object.self_and_descendants.includes(:public_version, {language: :site})
                                base_level = object.level - 1
                          Severity: Minor
                          Found in app/serializers/alchemy/page_tree_serializer.rb - About 1 hr to fix

                            Function handleEvent has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
                            Open

                              handleEvent(event) {
                                switch (event.type) {
                                  case "click":
                                    const elementEditor = event.target.closest("alchemy-element-editor")
                                    if (elementEditor === this) {
                            Severity: Minor
                            Found in app/javascript/alchemy_admin/components/element_editor.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

                            Severity
                            Category
                            Status
                            Source
                            Language