amahi/platform

View on GitHub

Showing 112 of 112 total issues

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

    def new_alias_check
        n = params[:alias]
        if n.nil? or n.blank?
            render :partial => 'aliases/name_bad'
            return
Severity: Major
Found in app/controllers/aliases_controller.rb and 1 other location - About 1 hr to fix
app/controllers/hosts_controller.rb on lines 164..182

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

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 new_host_check
        n = params[:host]
        if n.nil? or n.blank?
            render :partial => 'hosts/name_bad'
            return
Severity: Major
Found in app/controllers/hosts_controller.rb and 1 other location - About 1 hr to fix
app/controllers/aliases_controller.rb on lines 152..170

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

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 dir2theme has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def self.dir2theme(dir)
        theme = nil
        Dir.chdir(File.join(Rails.root, THEME_ROOT)) do
            theme_init_file = File.join(dir, "init.rb")
            if File.exist? theme_init_file
Severity: Minor
Found in app/models/theme.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 before_save_hook has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def before_save_hook
        if guest_writeable_changed?
            guest_writeable ? make_guest_writeable : make_guest_non_writeable
        end
        self.tags = self.tags.split(/\s*,\s*|\s+/).reject {|s| s.empty? }.join(', ').downcase if self.tags_changed?
Severity: Minor
Found in app/models/share.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 set_locale has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def set_locale

        preferred_locales = request.headers['HTTP_ACCEPT_LANGUAGE'].split(',').map { |locale| locale.split(';').first } rescue nil
        available_locales = I18n.available_locales
        default_locale = I18n.default_locale
Severity: Minor
Found in app/controllers/application_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 update_workgroup has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def update_workgroup
        sleep 2 if development?
        @workgroup = Setting.find(params[:id]) if params[:id]
        if @workgroup && @workgroup.name.eql?("workgroup")
            params[:share][:value].strip!
Severity: Minor
Found in plugins/020-shares/app/controllers/shares_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 simple_remote_select has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
Open

    def simple_remote_select options
        parsed_options = {}
        parsed_options[:disabled] = 'disabled' if options[:disabled]

        options[:id] = SecureRandom.hex(2) unless options[:id]
Severity: Minor
Found in app/helpers/application_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

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

    def toggle_write
        begin
            share = Share.find params[:id]
            if share.everyone
                render :partial => 'share/access', :locals => { :share => share }
Severity: Major
Found in app/controllers/share_controller.rb and 1 other location - About 1 hr to fix
app/controllers/share_controller.rb on lines 175..192

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

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 toggle_access
        begin
            share = Share.find params[:id]
            if share.everyone
                render :partial => 'share/access', :locals => { :share => share }
Severity: Major
Found in app/controllers/share_controller.rb and 1 other location - About 1 hr to fix
app/controllers/share_controller.rb on lines 194..211

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

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

        tmpl: function( tmpl, data, options, parentItem ) {
            var ret, topLevel = !parentItem;
            if ( topLevel ) {
                // This is a top-level tmpl call (not from a nested template using {{tmpl}})
                parentItem = topTmplItem;
Severity: Minor
Found in app/assets/javascripts/lib/jquery.ui.templates.js - About 1 hr to fix

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

        initialize: function(options){
    
            var _this = this;
            var options = options || {};
    
    
    Severity: Minor
    Found in app/assets/javascripts/lib/smart-links.js - About 1 hr to fix

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

              def set_platform
                  if File.exist?('/etc/amahi-release')
                      line = nil
                      File.open("/etc/amahi-release", "r") do |issue|
                          line = issue.gets
      Severity: Minor
      Found in lib/platform.rb - About 1 hr to fix

        Method install_theme has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def install_theme(installer, source)
        
                return if (installer.source_url.nil? or installer.source_url.blank?)
        
                dir = nil
        Severity: Minor
        Found in app/models/app.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 system_all_new_users has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

                def system_all_new_users
                    res = []
                    Dir.chdir("/home") do
                        Dir.glob("*").sort.reverse.each do |login|
                            unless User.where(:login=> login).first
        Severity: Minor
        Found in app/models/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 hda has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def hda
                @page_title = 'Search Results'
                @search_value = 'HDA'
        
                if params[:button] && params[:button] == "Web"
        Severity: Minor
        Found in app/controllers/search_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 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def destroy
                sleep 2 if development?
                @user = User.find(params[:id])
                id = nil
                if @user && @user != current_user && !@user.admin?
        Severity: Minor
        Found in plugins/010-users/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 simple_remote_radio has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
        Open

            def simple_remote_radio options
                parsed_options = {}
                parsed_options[:checked] = 'checked' if options[:checked]
                parsed_options[:disabled] = 'disabled' if options[:disabled]
        
        
        Severity: Minor
        Found in app/helpers/application_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 read_lease has 26 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

                def self.read_lease(file)
                    res = {}
                    return res unless File.exists?(file)
                    current = {}
                    File.foreach(file) do |l|
        Severity: Minor
        Found in lib/leases.rb - About 1 hr to fix

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

              def update_address
                  a = Host.find(params[:id])
                  addr = params[:value].strip
                  # FIXME - report errors to the user!
                  unless valid_short_address?(addr)
          Severity: Minor
          Found in app/controllers/hosts_controller.rb and 1 other location - About 55 mins to fix
          app/controllers/hosts_controller.rb on lines 135..151

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

          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 update_mac
                  a = Host.find(params[:id])
                  mac = params[:value].strip
                  # FIXME - report errors to the user!
                  unless valid_mac?(mac)
          Severity: Minor
          Found in app/controllers/hosts_controller.rb and 1 other location - About 55 mins to fix
          app/controllers/hosts_controller.rb on lines 117..133

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

          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

          Severity
          Category
          Status
          Source
          Language