ivanzotov/constructor

View on GitHub
pages/app/models/constructor_pages/page.rb

Summary

Maintainability
C
1 day
Test Coverage

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

  class Page < ActiveRecord::Base
    include ActiveSupport::Inflector
    include TheSortableTree::Scopes

    # Adding has_many for all field types
Severity: Minor
Found in pages/app/models/constructor_pages/page.rb - About 3 hrs to fix

    Method ids_by_params has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
    Open

          def ids_by_params(params)
            _hash = {}
    
            params.each_pair do |key, value|
              next if key == 'utf8'
    Severity: Minor
    Found in pages/app/models/constructor_pages/page.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 find_page_in_branch has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
    Open

        def find_page_in_branch(cname)
          Template.find_by(code_name: cname.singularize).tap {|t| t || return
            (descendants.where(template_id: t.id) if cname == cname.pluralize).tap {|r| r ||= []
              return r.empty? ? ancestors.find_by(template_id: t.id) : r}}
        end
    Severity: Minor
    Found in pages/app/models/constructor_pages/page.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 search has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
    Open

          def search(what = nil)
            _hash, _array = {}, []
            @where = Page.find_by(full_url: @where) if @where.is_a?(String)
            _array = ['lft > ? and rgt < ?', @where.lft, @where.rgt] if @where
            if what
    Severity: Minor
    Found in pages/app/models/constructor_pages/page.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

    There are no issues that match your filters.

    Category
    Status