SpontaneousCMS/spontaneous

View on GitHub

Showing 342 of 342 total issues

Avoid too many return statements within this method.
Open

        return template
Severity: Major
Found in lib/spontaneous/output/template/renderer.rb - About 30 mins to fix

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

                var set_info = function(href, filename, filesize) {
                    filename_info.text(filename);
                    if (filesize) {
                        filesize_info.text(parseFloat(filesize, 10).to_filesize());
                    }
    Severity: Minor
    Found in application/js/field/file.js and 1 other location - About 30 mins to fix
    application/js/field/file.js on lines 174..179

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

    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

    Method save has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def save
              id = nil
              saved = false
              trigger_hook(:before_save) do
                if new?
    Severity: Minor
    Found in lib/spontaneous/data_mapper/content_model.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

    Function StatusBar has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    Spontaneous.StatusBar = (function($, S) {
        var dom = S.Dom;
    
        var StatusBar = {
            showing: false,
    Severity: Minor
    Found in application/js/status_bar.js - 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

    Function FieldPreview has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

    Spontaneous.FieldPreview = (function($, S) {
        var dom = S.Dom;
    
        var FieldPreview = new JS.Class({
            initialize: function(view, wrap_id, listView) {
    Severity: Minor
    Found in application/js/field_preview.js - 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 layout has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def layout(name = nil, options = {}, &block)
            name = name.to_sym unless name.blank?
            if block_given?
              layout_procs[name] = block
            else
    Severity: Minor
    Found in lib/spontaneous/model/page/layouts.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 initialize has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize(options={})
          @buffer            = []
          @auto_flush        = options.has_key?(:auto_flush) ? options[:auto_flush] : true
          @level             = options[:log_level] ? Levels[options[:log_level]] : Levels[:debug]
          @log               = options[:stream]  || $stdout
    Severity: Minor
    Found in lib/spontaneous/logger.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 extract_content_length has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

            def extract_content_length(headers)
              headers.each do |key, value|
                if key.downcase == 'content-length'
                  return value.to_s == '0' ? '-' : value
                end
    Severity: Minor
    Found in lib/spontaneous/logger.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 copy_file has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def copy_file(existing_file, dest_path)
          if existing_file.respond_to?(:read)
            # Re-open the file because it's been modified on disk by the optimisation process
            # and if we don't re-open it the copy will take the unmodified version
            File.open(existing_file.path, "rb") do |src|
    Severity: Minor
    Found in lib/spontaneous/media/store/local.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 expanded has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def expanded(category)
          self[category].map do |path, glob|
            abs_path = expand_path(path)
            if abs_path.exist?
              abs_path += glob if glob
    Severity: Minor
    Found in lib/spontaneous/paths.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 box has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def box(name, options = {}, &block)
            name = name.to_sym
            prototype = nil
            options[:group] = @box_group if @box_group
    
    
    Severity: Minor
    Found in lib/spontaneous/model/core/boxes.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 check_styles has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def check_styles
            @options[:styles] = [@options[:style]] if @options.key?(:style)
            if @options.key?(:styles) and styles = @options[:styles]
              styles.each do |s|
                if instance_class.find_named_style(s).nil?
    Severity: Minor
    Found in lib/spontaneous/model/box/allowed_types.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 script_list has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def script_list(scripts)
          scripts.map do |script|
            script = "#{script}.js" unless script =~ /\.js$/
            src = script_url(script)
            size = 0
    Severity: Minor
    Found in lib/spontaneous/rack/back/helpers.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 authenticate has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def self.authenticate(login, clear_password, ip_address = nil)
          if (user = self[login: login, disabled: false])
            authenticator = Spontaneous::Crypt.new(clear_password, user.crypted_password)
            if authenticator.valid?
              user.upgrade_authentication(authenticator) if authenticator.outdated?
    Severity: Minor
    Found in lib/spontaneous/permissions/user.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 host_url_mapper has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def host_url_mapper(host)
          uri = URI.parse(host)
          lambda { |path|
            return path if path.blank?
            begin
    Severity: Minor
    Found in lib/spontaneous/media/store/cloud.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 user_table has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def user_table(users, hide_headers = false)
            columns = [:login, :name, :email, :level]
            users = ::Spontaneous::Permissions::User.all.map { |user|
              columns.map { |column| user.send(column) }
            }
    Severity: Minor
    Found in lib/spontaneous/cli/user.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 method_missing has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def method_missing(method, *args)
            if target && respond_to_missing?(method)
              if block_given?
                target.__send__(method, *args, &Proc.new)
              else
    Severity: Minor
    Found in lib/spontaneous/model/core/aliases.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 full_const_get has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

          def full_const_get(name)
            list = name.split("::")
            list.shift if list.first.blank?
            obj = self
            list.each do |x|
    Severity: Minor
    Found in lib/spontaneous/extensions/object.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 place_in_page_tree has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def place_in_page_tree
          if parent_id.nil?
            if __create_private_root? || content_model.has_root?
              make_private_root
            else
    Severity: Minor
    Found in lib/spontaneous/model/page/paths.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 initialize_site has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
    Open

        def initialize_site
          prepare :init
    
          @site = ::Spontaneous::Site.instantiate(Dir.pwd, options.environment, :console)
          Sequel.extension :migration
    Severity: Minor
    Found in lib/spontaneous/cli/init.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

    Severity
    Category
    Status
    Source
    Language